|
| 1 | +'use strict' |
| 2 | +const helper = require('./../test-helper') |
| 3 | +const assert = require('assert') |
| 4 | +const util = require('util') |
| 5 | + |
| 6 | +const suite = new helper.Suite() |
| 7 | + |
| 8 | +const secret_value = 'FAIL THIS TEST' |
| 9 | + |
| 10 | +suite.test('SSL Key should not exist in toString() output', () => { |
| 11 | + const pool = new helper.pg.Pool({ ssl: { key: secret_value } }) |
| 12 | + const client = new helper.pg.Client({ ssl: { key: secret_value } }) |
| 13 | + assert(pool.toString().indexOf(secret_value) === -1) |
| 14 | + assert(client.toString().indexOf(secret_value) === -1) |
| 15 | +}) |
| 16 | + |
| 17 | +suite.test('SSL Key should not exist in util.inspect output', () => { |
| 18 | + const pool = new helper.pg.Pool({ ssl: { key: secret_value } }) |
| 19 | + const client = new helper.pg.Client({ ssl: { key: secret_value } }) |
| 20 | + const depth = 20 |
| 21 | + assert(util.inspect(pool, { depth }).indexOf(secret_value) === -1) |
| 22 | + assert(util.inspect(client, { depth }).indexOf(secret_value) === -1) |
| 23 | +}) |
| 24 | + |
| 25 | +suite.test('SSL Key should not exist in json.stringfy output', () => { |
| 26 | + const pool = new helper.pg.Pool({ ssl: { key: secret_value } }) |
| 27 | + const client = new helper.pg.Client({ ssl: { key: secret_value } }) |
| 28 | + const depth = 20 |
| 29 | + assert(JSON.stringify(pool).indexOf(secret_value) === -1) |
| 30 | + assert(JSON.stringify(client).indexOf(secret_value) === -1) |
| 31 | +}) |
| 32 | + |
| 33 | +suite.test('SSL Key should exist for direct access', () => { |
| 34 | + const pool = new helper.pg.Pool({ ssl: { key: secret_value } }) |
| 35 | + const client = new helper.pg.Client({ ssl: { key: secret_value } }) |
| 36 | + assert(pool.options.ssl.key === secret_value) |
| 37 | + assert(client.connectionParameters.ssl.key === secret_value) |
| 38 | +}) |
| 39 | + |
| 40 | +suite.test('SSL Key should exist for direct access even when non-enumerable custom config', () => { |
| 41 | + const config = { ssl: { key: secret_value } } |
| 42 | + Object.defineProperty(config.ssl, 'key', { enumerable: false }) |
| 43 | + const pool = new helper.pg.Pool(config) |
| 44 | + const client = new helper.pg.Client(config) |
| 45 | + assert(pool.options.ssl.key === secret_value) |
| 46 | + assert(client.connectionParameters.ssl.key === secret_value) |
| 47 | +}) |
0 commit comments