|
| 1 | +import { test, describe, assert } from 'poku'; |
| 2 | +import { createConnection, describeOptions } from '../../../common.test.cjs'; |
| 3 | + |
| 4 | +const connection = createConnection().promise(); |
| 5 | + |
| 6 | +describe('Binary Parser: Prototype Sanitization', describeOptions); |
| 7 | + |
| 8 | +Promise.all([ |
| 9 | + test(async () => { |
| 10 | + const expected = [{}]; |
| 11 | + expected[0].test = 2; |
| 12 | + |
| 13 | + const [results] = await connection.query('SELECT 1+1 AS `test`'); |
| 14 | + |
| 15 | + assert.notDeepStrictEqual( |
| 16 | + results, |
| 17 | + expected, |
| 18 | + `Ensure "results" doesn't contain a standard object ({})`, |
| 19 | + ); |
| 20 | + }), |
| 21 | + test(async () => { |
| 22 | + const expected = [Object.create(null)]; |
| 23 | + expected[0].test = 2; |
| 24 | + |
| 25 | + const [results] = await connection.execute('SELECT 1+1 AS `test`'); |
| 26 | + |
| 27 | + assert.deepStrictEqual(results, expected, 'Ensure clean object "results"'); |
| 28 | + assert.strictEqual( |
| 29 | + Object.getPrototypeOf(results[0]), |
| 30 | + null, |
| 31 | + 'Ensure clean properties in results items', |
| 32 | + ); |
| 33 | + assert.strictEqual( |
| 34 | + typeof results[0].toString, |
| 35 | + 'undefined', |
| 36 | + 'Re-check prototypes (manually) in results columns', |
| 37 | + ); |
| 38 | + assert.strictEqual( |
| 39 | + typeof results[0].test.toString, |
| 40 | + 'function', |
| 41 | + 'Ensure that the end-user is able to use prototypes', |
| 42 | + ); |
| 43 | + assert.strictEqual( |
| 44 | + results[0].test.toString(), |
| 45 | + '2', |
| 46 | + 'Ensure that the end-user is able to use prototypes (manually): toString', |
| 47 | + ); |
| 48 | + assert.strictEqual( |
| 49 | + results[0].test.toFixed(2), |
| 50 | + '2.00', |
| 51 | + 'Ensure that the end-user is able to use prototypes (manually): toFixed', |
| 52 | + ); |
| 53 | + |
| 54 | + results[0].customProp = true; |
| 55 | + assert.strictEqual( |
| 56 | + results[0].customProp, |
| 57 | + true, |
| 58 | + 'Ensure that the end-user is able to use custom props', |
| 59 | + ); |
| 60 | + }), |
| 61 | + test(async () => { |
| 62 | + const [result] = await connection.execute('SET @1 = 1;'); |
| 63 | + |
| 64 | + assert.strictEqual( |
| 65 | + result.constructor.name, |
| 66 | + 'ResultSetHeader', |
| 67 | + 'Ensure constructor name in result object', |
| 68 | + ); |
| 69 | + }), |
| 70 | +]).then(async () => { |
| 71 | + await connection.end(); |
| 72 | +}); |
0 commit comments