mirror of
https://github.com/sqlite/sqlite.git
synced 2025-12-21 13:38:01 +03:00
Consolidate the three VFS-specific SEE tests into a shared routine.
FossilOrigin-Name: 8ac0bf125ddb6cc86a6825dcfe8895559835eca85ef14b5ad489f7c8159462e4
This commit is contained in:
@@ -369,6 +369,88 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
|
|||||||
clearOnInit: true,
|
clearOnInit: true,
|
||||||
initialCapacity: 6
|
initialCapacity: 6
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//#if enable-see
|
||||||
|
/**
|
||||||
|
Code consolidator for SEE sanity checks for various VFSes. ctor
|
||||||
|
is the VFS's oo1.DB-type constructor. ctorOptFunc(bool) is a
|
||||||
|
function which must return a constructor args object for ctor. It
|
||||||
|
is passed true if the db needs to be cleaned up/unlinked before
|
||||||
|
opening it (OPFS) and false if not (how that is done is
|
||||||
|
VFS-dependent). dbUnlink is a function which is expected to
|
||||||
|
unlink() the db file if the ctorOpfFunc does not do so when
|
||||||
|
passed true (kvvfs).
|
||||||
|
|
||||||
|
This function initializes the db described by ctorOptFunc(...),
|
||||||
|
writes some secret info into it, and re-opens it twice to
|
||||||
|
confirming that it can be read with an SEE key and cannot be read
|
||||||
|
without one.
|
||||||
|
*/
|
||||||
|
T.seeBaseCheck = function(ctor, ctorOptFunc, dbUnlink){
|
||||||
|
let initDb = true;
|
||||||
|
const tryKey = function(keyKey, key, expectCount){
|
||||||
|
let db;
|
||||||
|
//console.debug('tryKey()',arguments);
|
||||||
|
try {
|
||||||
|
if (initDb) {
|
||||||
|
const ctoropt = ctorOptFunc(initDb);
|
||||||
|
initDb = false;
|
||||||
|
db = new ctor({
|
||||||
|
...ctoropt,
|
||||||
|
[keyKey]: key
|
||||||
|
});
|
||||||
|
db.exec([
|
||||||
|
"drop table if exists t;",
|
||||||
|
"create table t(a);"
|
||||||
|
]);
|
||||||
|
db.close();
|
||||||
|
db = null;
|
||||||
|
// Ensure that it's actually encrypted...
|
||||||
|
let err;
|
||||||
|
try {
|
||||||
|
db = new ctor(ctorOptFunc(false));
|
||||||
|
T.assert(db, 'db opened') /* opening is fine, but... */;
|
||||||
|
db.exec("select 1 from sqlite_schema");
|
||||||
|
console.warn("(should not be reached) sessionStorage =", sessionStorage);
|
||||||
|
} catch (e) {
|
||||||
|
err = e;
|
||||||
|
} finally {
|
||||||
|
db.close()
|
||||||
|
db = null;
|
||||||
|
}
|
||||||
|
T.assert(err, "Expecting an exception")
|
||||||
|
.assert(capi.SQLITE_NOTADB == err.resultCode,
|
||||||
|
"Expecting NOTADB");
|
||||||
|
}/*initDb*/
|
||||||
|
db = new ctor({
|
||||||
|
...ctorOptFunc(false),
|
||||||
|
[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();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const hexFoo = new Uint8Array([0x66,0x6f,0x6f]/*=="foo"*/);
|
||||||
|
dbUnlink();
|
||||||
|
tryKey('textkey', 'foo', 3);
|
||||||
|
T.assert( !initDb );
|
||||||
|
tryKey('textkey', 'foo', 6);
|
||||||
|
dbUnlink();
|
||||||
|
initDb = true;
|
||||||
|
tryKey('key', 'foo', 3);
|
||||||
|
T.assert( !initDb );
|
||||||
|
tryKey('key', hexFoo, 6);
|
||||||
|
dbUnlink();
|
||||||
|
initDb = true;
|
||||||
|
tryKey('hexkey', hexFoo, 3);
|
||||||
|
T.assert( !initDb );
|
||||||
|
tryKey('hexkey', hexFoo, 6);
|
||||||
|
dbUnlink();
|
||||||
|
},
|
||||||
|
//#endif enable-see
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// End of infrastructure setup. Now define the tests...
|
// End of infrastructure setup. Now define the tests...
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
@@ -2839,71 +2921,9 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
|
|||||||
predicate: ()=>(isUIThread()
|
predicate: ()=>(isUIThread()
|
||||||
|| "Only available in main thread."),
|
|| "Only available in main thread."),
|
||||||
test: function(sqlite3){
|
test: function(sqlite3){
|
||||||
this.kvvfsUnlink();
|
T.seeBaseCheck(sqlite3.oo1.JsStorageDb, (isInit)=>{
|
||||||
let initDb = true;
|
return {filename: "session"};
|
||||||
const tryKey = function(keyKey, key, expectCount){
|
}, ()=>this.kvvfsUnlink());
|
||||||
let db;
|
|
||||||
//console.debug('tryKey()',arguments);
|
|
||||||
const ctoropt = {
|
|
||||||
filename: this.kvvfsDbFile
|
|
||||||
//vfs: 'kvvfs'
|
|
||||||
//,flags: 'ct'
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
if (initDb) {
|
|
||||||
initDb = false;
|
|
||||||
db = new this.JDb({
|
|
||||||
...ctoropt,
|
|
||||||
[keyKey]: key
|
|
||||||
});
|
|
||||||
db.exec([
|
|
||||||
"drop table if exists t;",
|
|
||||||
"create table t(a);"
|
|
||||||
]);
|
|
||||||
db.close();
|
|
||||||
// Ensure that it's actually encrypted...
|
|
||||||
let err;
|
|
||||||
try {
|
|
||||||
db = new this.JDb(ctoropt);
|
|
||||||
T.assert(db, 'db opened') /* opening is fine, but... */;
|
|
||||||
db.exec("select 1 from sqlite_schema");
|
|
||||||
console.warn("(should not be reached) sessionStorage =", sessionStorage);
|
|
||||||
} catch (e) {
|
|
||||||
err = e;
|
|
||||||
} finally {
|
|
||||||
db.close()
|
|
||||||
}
|
|
||||||
T.assert(err, "Expecting an exception")
|
|
||||||
.assert(sqlite3.capi.SQLITE_NOTADB == err.resultCode,
|
|
||||||
"Expecting NOTADB");
|
|
||||||
}/*initDb*/
|
|
||||||
//console.debug('tryKey()',arguments);
|
|
||||||
db = new sqlite3.oo1.DB({
|
|
||||||
...ctoropt,
|
|
||||||
vfs: 'kvvfs',
|
|
||||||
[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();
|
|
||||||
}
|
|
||||||
}.bind(this);
|
|
||||||
const hexFoo = new Uint8Array([0x66,0x6f,0x6f]/*=="foo"*/);
|
|
||||||
tryKey('textkey', 'foo', 3);
|
|
||||||
T.assert( !initDb );
|
|
||||||
tryKey('textkey', 'foo', 6);
|
|
||||||
this.kvvfsUnlink();
|
|
||||||
initDb = true;
|
|
||||||
tryKey('key', 'foo', 3);
|
|
||||||
T.assert( !initDb );
|
|
||||||
tryKey('key', hexFoo, 6);
|
|
||||||
this.kvvfsUnlink();
|
|
||||||
initDb = true;
|
|
||||||
tryKey('hexkey', hexFoo, 3);
|
|
||||||
T.assert( !initDb );
|
|
||||||
tryKey('hexkey', hexFoo, 6);
|
|
||||||
this.kvvfsUnlink();
|
|
||||||
}
|
}
|
||||||
})/*kvvfs with SEE*/
|
})/*kvvfs with SEE*/
|
||||||
//#endif enable-see
|
//#endif enable-see
|
||||||
@@ -3318,71 +3338,14 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
|
|||||||
.t({
|
.t({
|
||||||
name: 'OPFS with SEE encryption',
|
name: 'OPFS with SEE encryption',
|
||||||
test: function(sqlite3){
|
test: function(sqlite3){
|
||||||
const dbFile = 'file:///sqlite3-see.edb';
|
T.seeBaseCheck(
|
||||||
const dbCtor = sqlite3.oo1.OpfsDb;
|
sqlite3.oo1.OpfsDb,
|
||||||
const hexFoo = new Uint8Array([0x66,0x6f,0x6f]/*=="foo"*/);
|
function(isInit){
|
||||||
let initDb = true;
|
const opt = {filename: 'file:///sqlite3-see.edb'};
|
||||||
const tryKey = function(keyKey, key, expectCount){
|
if( isInit ) opt.filename += '?delete-before-open=1';
|
||||||
let db;
|
return opt;
|
||||||
//console.debug('tryKey()',arguments);
|
},
|
||||||
const ctoropt = {
|
()=>{});
|
||||||
filename: dbFile,
|
|
||||||
flags: 'c'
|
|
||||||
};
|
|
||||||
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*/
|
})/*OPFS with SEE*/
|
||||||
//#endif enable-see
|
//#endif enable-see
|
||||||
@@ -3587,69 +3550,11 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
|
|||||||
let poolUtil;
|
let poolUtil;
|
||||||
const P1 = await inst(poolConfig).then(u=>poolUtil = u).catch(catcher);
|
const P1 = await inst(poolConfig).then(u=>poolUtil = u).catch(catcher);
|
||||||
const dbFile = '/sqlite3-see.edb';
|
const dbFile = '/sqlite3-see.edb';
|
||||||
const dbCtor = poolUtil.OpfsSAHPoolDb;
|
T.seeBaseCheck(
|
||||||
const hexFoo = new Uint8Array([0x66,0x6f,0x6f]/*=="foo"*/);
|
poolUtil.OpfsSAHPoolDb,
|
||||||
let initDb = true;
|
(isInit)=>{return {filename: dbFile}},
|
||||||
const tryKey = function(keyKey, key, expectCount){
|
()=>poolUtil.unlink(dbFile)
|
||||||
let db;
|
);
|
||||||
//console.debug('tryKey()',arguments);
|
|
||||||
const ctoropt = {
|
|
||||||
filename: dbFile,
|
|
||||||
flags: 'c'
|
|
||||||
};
|
|
||||||
try {
|
|
||||||
if (initDb) {
|
|
||||||
initDb = false;
|
|
||||||
poolUtil.unlink(dbFile);
|
|
||||||
db = new dbCtor({
|
|
||||||
...ctoropt,
|
|
||||||
[keyKey]: key
|
|
||||||
});
|
|
||||||
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);
|
|
||||||
poolUtil.removeVfs();
|
poolUtil.removeVfs();
|
||||||
}
|
}
|
||||||
})/*opfs-sahpool with SEE*/
|
})/*opfs-sahpool with SEE*/
|
||||||
|
|||||||
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Move\sthe\shard-coded\sSHELL_OPT\smakefile\svalues\sfrom\sthe\stwo\smain\smakefiles\sinto\stheir\sshared\sconfigure\sscript.
|
C Consolidate\sthe\sthree\sVFS-specific\sSEE\stests\sinto\sa\sshared\sroutine.
|
||||||
D 2025-11-04T00:15:51.888
|
D 2025-11-04T01:03:58.330
|
||||||
F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
|
F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
|
||||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||||
@@ -644,7 +644,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555
|
|||||||
F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c
|
F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c
|
||||||
F ext/wasm/tester1-worker.c-pp.html 0e432ec2c0d99cd470484337066e8d27e7aee4641d97115338f7d962bf7b081a
|
F ext/wasm/tester1-worker.c-pp.html 0e432ec2c0d99cd470484337066e8d27e7aee4641d97115338f7d962bf7b081a
|
||||||
F ext/wasm/tester1.c-pp.html 52d88fe2c6f21a046030a36410b4839b632f4424028197a45a3d5669ea724ddb
|
F ext/wasm/tester1.c-pp.html 52d88fe2c6f21a046030a36410b4839b632f4424028197a45a3d5669ea724ddb
|
||||||
F ext/wasm/tester1.c-pp.js 1eb1d603fc5f0aa92f503bc41a7586599c7cd2fdd562415dbf9ba00aadd071d3
|
F ext/wasm/tester1.c-pp.js 76ed6a87c673cf55b0bb786d7cb8cafe04eebe0fb3438a4ed0bb040843e305c1
|
||||||
F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e
|
F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e
|
||||||
F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88
|
F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88
|
||||||
F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2
|
F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2
|
||||||
@@ -2167,8 +2167,8 @@ F tool/version-info.c 33d0390ef484b3b1cb685d59362be891ea162123cea181cb8e6d2cf6dd
|
|||||||
F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
|
F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
|
||||||
F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98
|
F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98
|
||||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||||
P bf55a4220a74022e8be5f8a0cd7f4ca395a36e1666e14113e7e60c4a94cf0b3a
|
P 900885c4fb3071e461bf868e9e68d0d8f3d3e83a1bcbf5c9c68179c701c1fb92
|
||||||
R 13f21af781fee875bf882cdafc32741b
|
R cf212ac209e135421eafb888295b09f1
|
||||||
U stephan
|
U stephan
|
||||||
Z 05b6dbea240df8d044f64f1dacaeeeb7
|
Z 6ccf2b6311a3c5ee1b7f2de43939fd38
|
||||||
# Remove this line to create a well-formed Fossil manifest.
|
# Remove this line to create a well-formed Fossil manifest.
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
900885c4fb3071e461bf868e9e68d0d8f3d3e83a1bcbf5c9c68179c701c1fb92
|
8ac0bf125ddb6cc86a6825dcfe8895559835eca85ef14b5ad489f7c8159462e4
|
||||||
|
|||||||
Reference in New Issue
Block a user