Instead of opting these storage/toolkit tests out of SQLite encryption, assert the correct behavior in BOTH the encrypted and plaintext configurations (detected via the security.storage.encryption.sqlite.enabled pref): - test_storage_service: a directory-as-database open surfaces NS_ERROR_FAILURE through obfsvfs (and records no open telemetry) vs NS_ERROR_FILE_ACCESS_DENIED / Glean "access" on the plain VFS. - test_vacuum: obfsvfs forces a fixed page size, so a VACUUM cannot change it (expect unchanged vs 1024); and an encrypted database keeps full auto_vacuum (1) rather than switching to incremental (2). - test_sqlite_autoVacuum: a fresh encrypted database reports full auto_vacuum (1), which reclaims freed pages at commit, so there is no freelist for an idle VACUUM to reclaim; assert that auto-reclaim behavior instead. - test_cache_size: the requested page size is ignored under encryption (cache size is KiB-based and unchanged). - test_sqlite_secure_delete: an encrypted database never stores the plaintext on disk, so the pre-delete "string is present" check only applies unencrypted; the post-delete absence check holds in both modes. Add test_encryption_rejects_plaintext, asserting the fail-closed contract directly: with encryption on, an in-profile database that is not encrypted (a foreign plaintext database) is refused rather than opened as plaintext; with encryption off it opens normally. Finally, the places, IndexedDB and dom/cache migration/upgrade tests ship pre-built PLAINTEXT profile/database fixtures and migrate them to the current schema. An encrypting build cannot read those plaintext databases (obfsvfs requires its own page format and there is no plaintext->encrypted migration by design), and never legitimately encounters a foreign plaintext profile. Their schema-migration logic is VFS-agnostic and is covered with encryption off, so run those fixture tests with encryption disabled, each manifest entry carrying a short comment. Verified passing both with and without SQLite encryption. Differential Revision: https://phabricator.services.mozilla.com/D305033
89 lines
2.5 KiB
JavaScript
89 lines
2.5 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
/**
|
|
* This file tests to make sure that SQLite was compiled with
|
|
* SQLITE_SECURE_DELETE=1.
|
|
*/
|
|
|
|
// Helper Methods
|
|
|
|
/**
|
|
* Reads the contents of a file and returns it as a string.
|
|
*
|
|
* @param aFile
|
|
* The file to return from.
|
|
* @return the contents of the file in the form of a string.
|
|
*/
|
|
function getFileContents(aFile) {
|
|
let fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
|
|
Ci.nsIFileInputStream
|
|
);
|
|
fstream.init(aFile, -1, 0, 0);
|
|
|
|
let bstream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(
|
|
Ci.nsIBinaryInputStream
|
|
);
|
|
bstream.setInputStream(fstream);
|
|
return bstream.readBytes(bstream.available());
|
|
}
|
|
|
|
// Tests
|
|
|
|
add_test(function test_delete_removes_data() {
|
|
const TEST_STRING = "SomeRandomStringToFind";
|
|
|
|
let file = getTestDB();
|
|
let db = Services.storage.openDatabase(file);
|
|
|
|
// Create the table and insert the data.
|
|
db.createTable("test", "data TEXT");
|
|
let stmt = db.createStatement("INSERT INTO test VALUES(:data)");
|
|
stmt.params.data = TEST_STRING;
|
|
try {
|
|
stmt.execute();
|
|
} finally {
|
|
stmt.finalize();
|
|
}
|
|
|
|
// Make sure this test is actually testing what it thinks by making sure the
|
|
// string shows up in the database. Because the previous statement was
|
|
// automatically wrapped in a transaction, the contents are already on disk.
|
|
// When at-rest encryption is enabled, obfsvfs encrypts the page contents, so
|
|
// the plaintext never appears on disk in the first place (a stronger
|
|
// guarantee than SECURE_DELETE); the post-delete check below then holds
|
|
// trivially.
|
|
let encrypted = Services.prefs.getBoolPref(
|
|
"security.storage.encryption.sqlite.enabled",
|
|
false
|
|
);
|
|
let contents = getFileContents(file);
|
|
if (encrypted) {
|
|
Assert.equal(-1, contents.indexOf(TEST_STRING));
|
|
} else {
|
|
Assert.notEqual(-1, contents.indexOf(TEST_STRING));
|
|
}
|
|
|
|
// Delete the data, and then close the database.
|
|
stmt = db.createStatement("DELETE FROM test WHERE data = :data");
|
|
stmt.params.data = TEST_STRING;
|
|
try {
|
|
stmt.execute();
|
|
} finally {
|
|
stmt.finalize();
|
|
}
|
|
db.close();
|
|
|
|
// Check the file to see if the string can be found.
|
|
contents = getFileContents(file);
|
|
Assert.equal(-1, contents.indexOf(TEST_STRING));
|
|
|
|
run_next_test();
|
|
});
|
|
|
|
function run_test() {
|
|
cleanup();
|
|
run_next_test();
|
|
}
|