Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /**
8 * This file tests to make sure that SQLite was compiled with
9 * SQLITE_SECURE_DELETE=1.
10 */
12 ////////////////////////////////////////////////////////////////////////////////
13 //// Helper Methods
15 /**
16 * Reads the contents of a file and returns it as a string.
17 *
18 * @param aFile
19 * The file to return from.
20 * @return the contents of the file in the form of a string.
21 */
22 function getFileContents(aFile)
23 {
24 let fstream = Cc["@mozilla.org/network/file-input-stream;1"].
25 createInstance(Ci.nsIFileInputStream);
26 fstream.init(aFile, -1, 0, 0);
28 let bstream = Cc["@mozilla.org/binaryinputstream;1"].
29 createInstance(Ci.nsIBinaryInputStream);
30 bstream.setInputStream(fstream);
31 return bstream.readBytes(bstream.available());
32 }
34 ////////////////////////////////////////////////////////////////////////////////
35 //// Tests
37 function test_delete_removes_data()
38 {
39 const TEST_STRING = "SomeRandomStringToFind";
41 let file = getTestDB();
42 let db = getService().openDatabase(file);
44 // Create the table and insert the data.
45 db.createTable("test", "data TEXT");
46 let stmt = db.createStatement("INSERT INTO test VALUES(:data)");
47 stmt.params.data = TEST_STRING;
48 try {
49 stmt.execute();
50 }
51 finally {
52 stmt.finalize();
53 }
55 // Make sure this test is actually testing what it thinks by making sure the
56 // string shows up in the database. Because the previous statement was
57 // automatically wrapped in a transaction, the contents are already on disk.
58 let contents = getFileContents(file);
59 do_check_neq(-1, contents.indexOf(TEST_STRING));
61 // Delete the data, and then close the database.
62 stmt = db.createStatement("DELETE FROM test WHERE data = :data");
63 stmt.params.data = TEST_STRING;
64 try {
65 stmt.execute();
66 }
67 finally {
68 stmt.finalize();
69 }
70 db.close();
72 // Check the file to see if the string can be found.
73 contents = getFileContents(file);
74 do_check_eq(-1, contents.indexOf(TEST_STRING));
76 run_next_test();
77 }
79 ////////////////////////////////////////////////////////////////////////////////
80 //// Test Runner
82 [
83 test_delete_removes_data,
84 ].forEach(add_test);
86 function run_test()
87 {
88 cleanup();
89 run_next_test();
90 }