]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add importDb() tests of SEE databases for the opfs/opfs-wl VFSes, analog to the opfs...
authorstephan <stephan@noemail.net>
Tue, 5 May 2026 15:26:24 +0000 (15:26 +0000)
committerstephan <stephan@noemail.net>
Tue, 5 May 2026 15:26:24 +0000 (15:26 +0000)
FossilOrigin-Name: 534d388031dfacf83cb40c712150a376db10393c98936a33ea80da0166b3dbeb

ext/wasm/tester1.c-pp.js
manifest
manifest.uuid

index 511e7108448784ac2241d3064adc6ab953d49ac7..abf8e710a64db8dd9e6fc2405464594d901a0629 100644 (file)
@@ -380,14 +380,14 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
      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).
+     VFS-dependent).  dbUnlink is a _synchronous_ function which is
+     expected to unlink() the db file if the ctorOpfFunc does not do
+     so when passed true (namely for kvvfs).
 
-     This function initializes the db described by ctorOptFunc(...),
-     writes some secret info into it, and re-opens it twice to
-     confirm that it can be read with an SEE key and cannot be read
-     without one.
+     This function initializes the db described by the result of
+     ctorOptFunc(bool), writes some secret info into it, and re-opens
+     it twice to confirm that it can be read with an SEE key and
+     cannot be read without one.
 
      If unlinkDbAtEnd is truthy then dbUnlink() is (on success)
      called before returning.
@@ -3599,7 +3599,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
       name: 'kvvfs SEE encryption in sessionStorage',
       predicate: ()=>(!!globalThis.sessionStorage
                       || "sessionStorage is not available"),
-      test: function(sqlite3){
+      test: async function(sqlite3){
         const JDb = sqlite3.oo1.JsStorageDb;
         T.seeBaseCheck(JDb,
                        (isInit)=>{
@@ -3926,17 +3926,38 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
     .t({
       name: '@vfsName@ with SEE encryption',
       predicate: (sqlite3)=>!!sqlite3.oo1.@oo1Ctor@,
-      test: function(sqlite3){
+      test: async function(sqlite3){
         const ctor = sqlite3.oo1.@oo1Ctor@;
-        T.seeBaseCheck(
-          ctor,
-          function(isInit){
-            const opt = {filename: 'file:///sqlite3-see.edb'};
-            if( isInit ) opt.filename += '?delete-before-open=1';
-            return opt;
-          },
-          ()=>{}
-        );
+        const filename = 'sqlite3-see.edb';
+        const ctorOpt = {filename: 'file:///'+filename};
+        const opfs = sqlite3.opfs;
+        const initer = function(isInit){
+          const opt = {...ctorOpt};
+          if( isInit ) opt.filename += '?delete-before-open=1';
+          return opt;
+        };
+
+        T.seeBaseCheck(ctor, initer, ()=>{}, false);
+        /*
+          Ensure that ctor.importDb() correctly handles SEE-encrypted
+          dbs. For more details search below for forumpost/f84bef3552.
+        */
+        let exp = await opfs.getRootDir()
+            .then(d=>d.getFileHandle(filename))
+            .then(fh=>fh.getFile())
+            .then(f=>f.bytes());
+        await opfs.unlink(filename);
+        T.assert( exp.byteLength > 100 && 0===(exp.byteLength % 512) );
+        const got = await ctor.importDb(filename, exp);
+        T.assert(exp.byteLength === got);
+        exp = null;
+        const db = new ctor({...initer(false), key: 'foo'});
+        try{
+          T.assert( 4 === db.selectValue("select count(*) from t") )
+            .assert( 6 === db.selectValue("select sum(a) from t") );
+        }finally{
+          db.close();
+        }
       }
     })
 //#/if enable-see
@@ -4149,8 +4170,7 @@ globalThis.sqlite3InitModule = sqlite3InitModule;
           false
         );
         /* Ensure that importDb() does the right thing for an
-           SEE-encrypted DB:
-           https://sqlite.org/see/forumpost/f84bef3552 */
+           SEE-encrypted DB: https://sqlite.org/see/forumpost/f84bef3552 */
         let exp = poolUtil.exportFile(dbFile);
         T.assert( exp.byteLength > 100 && 0===(exp.byteLength % 512) );
         poolUtil.unlink(dbFile);
index 1015fdaa2d0541f376f244bf087fb922dda076ff..59e2c37b9bcc6db5bed444e99c86f607b864c783 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C For\sthe\svarious\sOPFS\sVFS\sdb-import\sroutines,\sin\sSEE\sbuilds\s(only)\srelax\sthe\sis-this-a-db\scheck\sto\sallow\sfor\sSEE\sdbs\snot\shaving\sthe\susual\sheader\sstring\sin\scleartext.\sAddresses\s[https://sqlite.org/see/forumpost/f84bef3552|SEE\sforum\spost\sf84bef3552].
-D 2026-05-05T08:51:10.859
+C Add\simportDb()\stests\sof\sSEE\sdatabases\sfor\sthe\sopfs/opfs-wl\sVFSes,\sanalog\sto\sthe\sopfs-sahpool\stest\sin\s[a5a9ac7ad6622b].
+D 2026-05-05T15:26:24.464
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -647,7 +647,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555
 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c
 F ext/wasm/tester1-worker.c-pp.html 7171022e7f4da8f46e5f50ea81dd6ce840b9235c47653a5deeb3764ccc2fe472
 F ext/wasm/tester1.c-pp.html bd927ccf51ddd65e924660a0487add99e1b044afe03950e49d87ccf44efdddb6
-F ext/wasm/tester1.c-pp.js bb6ea310ff3daf2aaef99cffd0e0db2603736b49df8fbd1cf5b05fb165b63d62
+F ext/wasm/tester1.c-pp.js 803af078fe11b06482b5aa85d38478d2f37e9cdc3f85eacbeaea40c1b61359f1
 F ext/wasm/tests/opfs/concurrency/index.html 706eab6308343c04ac2360aba6001af4ffaf46d8f33a0ccd02c64d93e3216a43
 F ext/wasm/tests/opfs/concurrency/test.js 6919778fceaac1b7cc78caf41d796f545d2c4433b31188aa9689f05b5ad28828
 F ext/wasm/tests/opfs/concurrency/worker.js 704d82c5e287e47f612349e027765943a58ad967dcf178fb5a1c3a8eaafb09af
@@ -2203,8 +2203,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee
 F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
 F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c
-P 97ab0a2fd56501d08bc2ab2adbe70a4130f6c5b5db343941fa16c7b34c550bd3
-R 7ba13c65bbee516d32510c18094784db
+P a5a9ac7ad6622b5b07193aa279deefde7d59ca17f81aba9dd78ee90718446993
+R 25cccb4d818ffb318cddd785d9828f48
 U stephan
-Z 9cde2ed6511053725206d4ec3b114f5d
+Z 70c153abce31c38c75f7b3a78b65123e
 # Remove this line to create a well-formed Fossil manifest.
index 2c6fd12472eb21c0712124032200accf9ffc1600..5f710131780da182953604ba6ea80b9a9d2d89e3 100644 (file)
@@ -1 +1 @@
-a5a9ac7ad6622b5b07193aa279deefde7d59ca17f81aba9dd78ee90718446993
+534d388031dfacf83cb40c712150a376db10393c98936a33ea80da0166b3dbeb