Attachment #412450: test v1.0 with requested review changes for bug #445164

Looking for saved searches? click on "Search Bugs" above.
View | Details | Raw Unified | Return to bug 445164 | Differences between
and this patch

Collapse All | Expand All

(-)a/storage/test/unit/test_sqlite_secure_delete.js (+138 lines)
Line     Link Here 
Line 0    Link Here 
1
/*-*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
 *vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
3
 * ***** BEGIN LICENSE BLOCK *****
4
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version
7
 * 1.1 (the "License"); you may not use this file except in compliance with
8
 * the License. You may obtain a copy of the License at
9
 * http://www.mozilla.org/MPL/
10
 *
11
 * Software distributed under the License is distributed on an "AS IS" basis,
12
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
 * for the specific language governing rights and limitations under the
14
 * License.
15
 *
16
 * The Original Code is Storage Test Code.
17
 *
18
 * The Initial Developer of the Original Code is
19
 * Mozilla Foundation.
20
 * Portions created by the Initial Developer are Copyright (C) 2009
21
 * the Initial Developer. All Rights Reserved.
22
 *
23
 * Contributor(s):
24
 *   Shawn Wilsher <me@shawnwilsher.com> (Original Author)
25
 *
26
 * Alternatively, the contents of this file may be used under the terms of
27
 * either the GNU General Public License Version 2 or later (the "GPL"), or
28
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
 * in which case the provisions of the GPL or the LGPL are applicable instead
30
 * of those above. If you wish to allow use of your version of this file only
31
 * under the terms of either the GPL or the LGPL, and not to allow others to
32
 * use your version of this file under the terms of the MPL, indicate your
33
 * decision by deleting the provisions above and replace them with the notice
34
 * and other provisions required by the GPL or the LGPL. If you do not delete
35
 * the provisions above, a recipient may use your version of this file under
36
 * the terms of any one of the MPL, the GPL or the LGPL.
37
 *
38
 * ***** END LICENSE BLOCK ***** */
39
40
/**
41
 * This file tests to make sure that SQLite was compiled with
42
 * SQLITE_SECURE_DELETE=1.
43
 */
44
45
////////////////////////////////////////////////////////////////////////////////
46
//// Helper Methods
47
48
/**
49
 * Reads the contents of a file and returns it as a string.
50
 *
51
 * @param aFile
52
 *        The file to return from.
53
 * @return the contents of the file in the form of a string.
54
 */
55
function getFileContents(aFile)
56
{
57
  let fstream = Cc["@mozilla.org/network/file-input-stream;1"].
58
                createInstance(Ci.nsIFileInputStream);
59
  fstream.init(aFile, -1, 0, 0);
60
61
  let bstream = Cc["@mozilla.org/binaryinputstream;1"].
62
                createInstance(Ci.nsIBinaryInputStream);
63
  bstream.setInputStream(fstream);
64
  return bstream.readBytes(bstream.available());
65
}
66
67
////////////////////////////////////////////////////////////////////////////////
68
//// Tests
69
70
function test_delete_removes_data()
71
{
72
  const TEST_STRING = "SomeRandomStringToFind";
73
74
  let file = getTestDB();
75
  let db = getService().openDatabase(file);
76
77
  // Create the table and insert the data.
78
  db.createTable("test", "data TEXT");
79
  let stmt = db.createStatement("INSERT INTO test VALUES(:data)");
80
  stmt.params.data = TEST_STRING;
81
  try {
82
    stmt.execute();
83
  }
84
  finally {
85
    stmt.finalize();
86
  }
87
88
  // Make sure this test is actually testing what it thinks by making sure the
89
  // string shows up in the database.  Because the previous statement was
90
  // automatically wrapped in a transaction, the contents are already on disk.
91
  let contents = getFileContents(file);
92
  do_check_neq(-1, contents.indexOf(TEST_STRING));
93
94
  // Delete the data, and then close the database.
95
  stmt = db.createStatement("DELETE FROM test WHERE data = :data");
96
  stmt.params.data = TEST_STRING;
97
  try {
98
    stmt.execute();
99
  }
100
  finally {
101
    stmt.finalize();
102
  }
103
  db.close();
104
105
  // Check the file to see if the string can be found.
106
  contents = getFileContents(file);
107
  do_check_eq(-1, contents.indexOf(TEST_STRING));
108
109
  run_next_test();
110
}
111
112
////////////////////////////////////////////////////////////////////////////////
113
//// Test Runner
114
115
var tests =
116
[
117
  test_delete_removes_data,
118
];
119
let index = 0;
120
121
function run_next_test()
122
{
123
  if (index < tests.length) {
124
    do_test_pending();
125
    print("Running the next test: " + tests[index].name);
126
    tests[index++]();
127
  }
128
129
  do_test_finished();
130
}
131
132
function run_test()
133
{
134
  cleanup();
135
136
  do_test_pending();
137
  run_next_test();
138
}

Return to bug 445164