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
80 lines
2.3 KiB
JavaScript
80 lines
2.3 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
// This file tests that dbs of various page sizes are using the right cache
|
|
// size (bug 703113).
|
|
|
|
/**
|
|
* In order to change the cache size, we must open a DB, change the page
|
|
* size, create a table, close the DB, then re-open the DB. We then check
|
|
* the cache size after reopening.
|
|
*
|
|
* @param dbOpener
|
|
* function that opens the DB specified in file
|
|
* @param file
|
|
* file holding the database
|
|
* @param pageSize
|
|
* the DB's page size
|
|
* @param expectedCacheSize
|
|
* the expected cache size for the given page size
|
|
*/
|
|
function check_size(dbOpener, file, pageSize, expectedCacheSize) {
|
|
// Open the DB, immediately change its page size.
|
|
let db = dbOpener(file);
|
|
db.executeSimpleSQL("PRAGMA page_size = " + pageSize);
|
|
|
|
// Check the page size change worked. obfsvfs (the default VFS under SQLite
|
|
// encryption) forces a fixed page size and ignores the change, so the
|
|
// requested page size only takes effect on a plaintext database.
|
|
let encrypted = Services.prefs.getBoolPref(
|
|
"security.storage.encryption.sqlite.enabled",
|
|
false
|
|
);
|
|
let stmt = db.createStatement("PRAGMA page_size");
|
|
Assert.ok(stmt.executeStep());
|
|
Assert.equal(stmt.row.page_size, encrypted ? db.defaultPageSize : pageSize);
|
|
stmt.finalize();
|
|
|
|
// Create a simple table.
|
|
db.executeSimpleSQL("CREATE TABLE test ( id INTEGER PRIMARY KEY )");
|
|
|
|
// Close and re-open the DB.
|
|
db.close();
|
|
db = dbOpener(file);
|
|
|
|
// Check cache size is as expected.
|
|
stmt = db.createStatement("PRAGMA cache_size");
|
|
Assert.ok(stmt.executeStep());
|
|
Assert.equal(stmt.row.cache_size, expectedCacheSize);
|
|
stmt.finalize();
|
|
}
|
|
|
|
function new_file(name) {
|
|
let file = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
|
file.append(name + ".sqlite");
|
|
Assert.ok(!file.exists());
|
|
return file;
|
|
}
|
|
|
|
function run_test() {
|
|
const kExpectedCacheSize = -2048; // 2MiB
|
|
|
|
let pageSizes = [1024, 4096, 32768];
|
|
|
|
for (let i = 0; i < pageSizes.length; i++) {
|
|
let pageSize = pageSizes[i];
|
|
check_size(
|
|
getDatabase,
|
|
new_file("shared" + pageSize),
|
|
pageSize,
|
|
kExpectedCacheSize
|
|
);
|
|
check_size(
|
|
Services.storage.openUnsharedDatabase,
|
|
new_file("unshared" + pageSize),
|
|
pageSize,
|
|
kExpectedCacheSize
|
|
);
|
|
}
|
|
}
|