Skip to content

Commit 0c41b5c

Browse files
committed
test: add more SQLite limit enforcement and constructor Infinity tests
1 parent 122aa00 commit 0c41b5c

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

test/parallel/test-sqlite-limits.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,15 @@ suite('DatabaseSync limits', () => {
198198
});
199199
});
200200

201+
test('throws on Infinity limit value in constructor', (t) => {
202+
t.assert.throws(() => {
203+
new DatabaseSync(':memory:', { limits: { length: Infinity } });
204+
}, {
205+
name: 'TypeError',
206+
message: /options\.limits\.length.*must be an integer/,
207+
});
208+
});
209+
201210
test('partial limits in constructor', (t) => {
202211
const db = new DatabaseSync(':memory:', {
203212
limits: {
@@ -223,4 +232,73 @@ suite('DatabaseSync limits', () => {
223232
message: /too many columns/,
224233
});
225234
});
235+
236+
test('throws when exceeding attach limit', (t) => {
237+
const db = new DatabaseSync(':memory:', {
238+
limits: {
239+
attach: 0,
240+
}
241+
});
242+
243+
t.assert.throws(() => {
244+
db.exec("ATTACH DATABASE ':memory:' AS db1");
245+
}, {
246+
message: /too many attached databases/,
247+
});
248+
});
249+
250+
test('throws when exceeding variable number limit', (t) => {
251+
const db = new DatabaseSync(':memory:', {
252+
limits: {
253+
variableNumber: 2,
254+
}
255+
});
256+
257+
t.assert.throws(() => {
258+
const stmt = db.prepare('SELECT ?, ?, ?');
259+
stmt.all(1, 2, 3);
260+
}, {
261+
message: /too many SQL variables/,
262+
});
263+
});
264+
265+
test('throws when exceeding compound select limit', (t) => {
266+
const db = new DatabaseSync(':memory:', {
267+
limits: {
268+
compoundSelect: 1,
269+
}
270+
});
271+
272+
t.assert.throws(() => {
273+
db.exec('SELECT 1 UNION SELECT 2 UNION SELECT 3');
274+
}, {
275+
message: /too many terms in compound SELECT/,
276+
});
277+
});
278+
279+
test('throws when exceeding function arg limit', (t) => {
280+
const db = new DatabaseSync(':memory:', {
281+
limits: {
282+
functionArg: 2,
283+
}
284+
});
285+
286+
t.assert.throws(() => {
287+
db.exec('SELECT max(1, 2, 3)');
288+
}, {
289+
message: /too many arguments on function max/,
290+
});
291+
});
292+
293+
test('setter applies limit to SQLite immediately', (t) => {
294+
const db = new DatabaseSync(':memory:');
295+
296+
db.limits.attach = 0;
297+
298+
t.assert.throws(() => {
299+
db.exec("ATTACH DATABASE ':memory:' AS db1");
300+
}, {
301+
message: /too many attached databases/,
302+
});
303+
});
226304
});

0 commit comments

Comments
 (0)