-
-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(security): improve supportBigNumbers and bigNumberStrings sanitiz…
…ation
- Loading branch information
1 parent
8a818ce
commit c6f329d
Showing
4 changed files
with
160 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
test/esm/unit/parsers/big-numbers-strings-sanitization.test.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { describe, test, assert } from 'poku'; | ||
import { createConnection, describeOptions } from '../../../common.test.cjs'; | ||
|
||
const connection = createConnection().promise(); | ||
|
||
const sql = 'SELECT 9007199254740991+100 AS `total`'; | ||
|
||
describe('bigNumberStrings Sanitization', describeOptions); | ||
|
||
Promise.all([ | ||
test(async () => { | ||
const [results] = await connection.query({ | ||
sql, | ||
supportBigNumbers: true, | ||
bigNumberStrings: true, | ||
}); | ||
|
||
assert.strictEqual( | ||
typeof results[0].total, | ||
'string', | ||
'Valid bigNumberStrings enabled', | ||
); | ||
}), | ||
test(async () => { | ||
const [results] = await connection.query({ | ||
sql, | ||
supportBigNumbers: false, | ||
bigNumberStrings: false, | ||
}); | ||
|
||
assert.strictEqual( | ||
typeof results[0].total, | ||
'number', | ||
'Valid bigNumberStrings disabled', | ||
); | ||
}), | ||
|
||
test(async () => { | ||
const [results] = await connection.query({ | ||
sql, | ||
supportBigNumbers: 'text', | ||
bigNumberStrings: 'text', | ||
}); | ||
|
||
assert.strictEqual( | ||
typeof results[0].total, | ||
'string', | ||
'bigNumberStrings as a random string should be enabled', | ||
); | ||
}), | ||
test(async () => { | ||
const [results] = await connection.query({ | ||
sql, | ||
supportBigNumbers: '', | ||
bigNumberStrings: '', | ||
}); | ||
|
||
assert.strictEqual( | ||
typeof results[0].total, | ||
'number', | ||
'bigNumberStrings as an empty string should be disabled', | ||
); | ||
}), | ||
]).then(async () => { | ||
await connection.end(); | ||
}); |
62 changes: 62 additions & 0 deletions
62
test/esm/unit/parsers/support-big-numbers-sanitization.test.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { describe, test, assert } from 'poku'; | ||
import { createConnection, describeOptions } from '../../../common.test.cjs'; | ||
|
||
const connection = createConnection().promise(); | ||
|
||
const sql = 'SELECT 9007199254740991+100 AS `total`'; | ||
|
||
describe('supportBigNumbers Sanitization', describeOptions); | ||
|
||
Promise.all([ | ||
test(async () => { | ||
const [results] = await connection.query({ | ||
sql, | ||
supportBigNumbers: true, | ||
}); | ||
|
||
assert.strictEqual( | ||
typeof results[0].total, | ||
'string', | ||
'Valid supportBigNumbers enabled', | ||
); | ||
}), | ||
test(async () => { | ||
const [results] = await connection.query({ | ||
sql, | ||
supportBigNumbers: false, | ||
}); | ||
|
||
assert.strictEqual( | ||
typeof results[0].total, | ||
'number', | ||
'Valid supportBigNumbers disabled', | ||
); | ||
}), | ||
|
||
test(async () => { | ||
const [results] = await connection.query({ | ||
sql, | ||
supportBigNumbers: 'text', | ||
}); | ||
|
||
assert.strictEqual( | ||
typeof results[0].total, | ||
'string', | ||
'supportBigNumbers as a random string should be enabled', | ||
); | ||
}), | ||
test(async () => { | ||
const [results] = await connection.query({ | ||
sql, | ||
supportBigNumbers: '', | ||
}); | ||
|
||
assert.strictEqual( | ||
typeof results[0].total, | ||
'number', | ||
'supportBigNumbers as an empty string should be disabled', | ||
); | ||
}), | ||
]).then(async () => { | ||
await connection.end(); | ||
}); |