aboutsummaryrefslogtreecommitdiff
path: root/ext/wasm/tester1.c-pp.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/wasm/tester1.c-pp.js')
-rw-r--r--ext/wasm/tester1.c-pp.js65
1 files changed, 64 insertions, 1 deletions
diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js
index 768d5cdf4..2e96daa2f 100644
--- a/ext/wasm/tester1.c-pp.js
+++ b/ext/wasm/tester1.c-pp.js
@@ -1331,7 +1331,70 @@ self.sqlite3InitModule = sqlite3InitModule;
T.assert(e instanceof sqlite3.SQLite3Error)
.assert(0==e.message.indexOf('Cannot prepare empty'));
}
- })
+ })/*setup table T*/
+
+ ////////////////////////////////////////////////////////////////////
+ .t({
+ name: "sqlite3_set_authorizer()",
+ test:function(sqlite3){
+ T.assert(capi.SQLITE_IGNORE>0)
+ .assert(capi.SQLITE_DENY>0);
+ const db = this.db;
+ const ssa = capi.sqlite3_set_authorizer;
+ const n = db.selectValue('select count(*) from t');
+ T.assert(n>0);
+ let authCount = 0;
+ let rc = ssa(db, function(pV, iCode, s0, s1, s2, s3){
+ ++authCount;
+ return capi.SQLITE_IGNORE;
+ }, 0);
+ T.assert(0===rc)
+ .assert(
+ undefined === db.selectValue('select count(*) from t')
+ /* Note that the count() never runs, so we get undefined
+ instead of 0. */
+ )
+ .assert(authCount>0);
+ authCount = 0;
+ db.exec("update t set a=-9999");
+ T.assert(authCount>0);
+ /* Reminder: we don't use DELETE because, from the C API docs:
+
+ "If the action code is [SQLITE_DELETE] and the callback
+ returns [SQLITE_IGNORE] then the [DELETE] operation proceeds
+ but the [truncate optimization] is disabled and all rows are
+ deleted individually."
+ */
+ rc = ssa(db, null, 0);
+ authCount = 0;
+ T.assert(-9999 != db.selectValue('select a from t'))
+ .assert(0===authCount);
+ rc = ssa(db, function(pV, iCode, s0, s1, s2, s3){
+ ++authCount;
+ return capi.SQLITE_DENY;
+ }, 0);
+ T.assert(0===rc);
+ let err;
+ try{ db.exec("select 1 from t") }
+ catch(e){ err = e }
+ T.assert(err instanceof sqlite3.SQLite3Error)
+ .assert(err.message.indexOf('not authorized'>0))
+ .assert(1===authCount);
+ authCount = 0;
+ rc = ssa(db, function(...args){
+ ++authCount;
+ return capi.SQLITE_OK;
+ }, 0);
+ T.assert(0===rc);
+ T.assert(n === db.selectValue('select count(*) from t'))
+ .assert(authCount>0);
+ authCount = 0;
+ rc = ssa(db, null, 0);
+ T.assert(0===rc);
+ T.assert(n === db.selectValue('select count(*) from t'))
+ .assert(0===authCount);
+ }
+ })/*sqlite3_set_authorizer()*/
////////////////////////////////////////////////////////////////////////
.t("sqlite3_table_column_metadata()", function(sqlite3){