1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-12-21 13:38:01 +03:00

Add a test which uses SEE via the "opfs" VFS. "opfs-sahpool" is pending.

FossilOrigin-Name: 1eb5a7ea394aa5b7e8594d73ce31f4b9bef55f2fa977dc26810c0bfba1cc39f7
This commit is contained in:
stephan
2025-10-26 21:30:29 +00:00
parent 4f177f1d3e
commit 89a9efe840
3 changed files with 80 additions and 7 deletions

View File

@@ -3311,6 +3311,79 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
"entryExists(",testDir,") should have failed");
}
}/*OPFS util sanity checks*/)
//#if enable-see
.t({
name: 'OPFS with SEE encryption',
test: function(sqlite3){
const dbFile = 'file:///sqlite3-see.edb';
const dbCtor = sqlite3.oo1.OpfsDb;
//const tryKey = T.see.tryKey(dbCtor, dbFile);
const hexFoo = new Uint8Array([0x66,0x6f,0x6f]/*=="foo"*/);
let initDb = true;
const tryKey = function(keyKey, key, expectCount){
let db;
//console.debug('tryKey()',arguments);
const ctoropt = {
filename: dbFile,
flags: 'ct'
};
try {
if (initDb) {
initDb = false;
const opt = {
...ctoropt,
[keyKey]: key
};
opt.filename += '?delete-before-open=1';
db = new dbCtor(opt);
db.exec([
"drop table if exists t;",
"create table t(a);"
]);
db.close();
// Ensure that it's actually encrypted...
let err;
try {
db = new dbCtor(ctoropt);
T.assert(db, 'db opened') /* opening is fine, but... */;
const rv = db.exec({
sql:"select count(*) from sqlite_schema",
returnValue: 'resultRows'
});
console.warn("(should not be reached) rv =",rv);
} catch (e) {
err = e;
} finally {
db.close()
}
T.assert(err, "Expecting an exception")
.assert(sqlite3.capi.SQLITE_NOTADB == err.resultCode,
"Expecting NOTADB");
}/*initDb*/
db = new dbCtor({
...ctoropt,
[keyKey]: key
});
db.exec("insert into t(a) values (1),(2)");
T.assert(expectCount === db.selectValue('select sum(a) from t'));
} finally {
if (db) db.close();
}
};
tryKey('textkey', 'foo', 3);
T.assert( !initDb );
tryKey('textkey', 'foo', 6);
initDb = true;
tryKey('key', 'foo', 3);
T.assert( !initDb );
tryKey('key', hexFoo, 6);
initDb = true;
tryKey('hexkey', hexFoo, 3);
T.assert( !initDb );
tryKey('hexkey', hexFoo, 6);
}
})/*OPFS with SEE*/
//#endif enable-see
;/* end OPFS tests */
////////////////////////////////////////////////////////////////////////