1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Add sqlite3_set_authorizer() support and related tests to JS.

FossilOrigin-Name: 551b848894c249cb3c9d237643d2ed53ffcb3b003d0cf3f797a535df1731ce39
This commit is contained in:
stephan
2022-12-16 11:13:32 +00:00
parent 00d6b2755f
commit d83ab0cf85
8 changed files with 155 additions and 18 deletions

View File

@@ -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){