mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 10:15:07 +08:00
sqlite: validate backup() source is a Database
backup() only checked that the source argument was a BaseObject before casting it to Database, so passing a Statement or Session caused a type confusion. Check against the Database constructor template instead. Signed-off-by: Guilherme Araújo <arauujogui@gmail.com> PR-URL: https://github.com/nodejs/node/pull/66797 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
1 parent
c7ae7ab5b9
commit
e20da720c8
3 files changed
+73
-45
No files matched your search
@@ -48,10 +48,26 @@ describe('backup()', () => {
|
||||
backup();
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
message: 'The "sourceDb" argument must be an object.'
|
||||
message: 'The "sourceDb" argument must be an instance of Database.'
|
||||
});
|
||||
});
|
||||
|
||||
test('throws if the source is not an instance of Database', (t) => {
|
||||
const database = makeSourceDb();
|
||||
for (const source of [
|
||||
{},
|
||||
database.prepare('SELECT 1'),
|
||||
database.createSession(),
|
||||
]) {
|
||||
t.assert.throws(() => {
|
||||
backup(source, 'out.db');
|
||||
}, {
|
||||
code: 'ERR_INVALID_ARG_TYPE',
|
||||
message: 'The "sourceDb" argument must be an instance of Database.'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test('throws if path is not a string, URL, or Buffer', (t) => {
|
||||
const database = makeSourceDb();
|
||||
|
||||
|
||||
Reference in new issue
Block a user