From faa0f38813723207ea0327a6b9838ccd30daf2b2 Mon Sep 17 00:00:00 2001 From: Charmander <~@charmander.me> Date: Mon, 13 Jan 2020 11:07:15 -0800 Subject: [PATCH 1/4] =?UTF-8?q?Keep=20ConnectionParameters=E2=80=99s=20pas?= =?UTF-8?q?sword=20property=20writable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `Client` writes to it when `password` is a function. --- packages/pg/lib/connection-parameters.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pg/lib/connection-parameters.js b/packages/pg/lib/connection-parameters.js index b00d3f1a3..55569e070 100644 --- a/packages/pg/lib/connection-parameters.js +++ b/packages/pg/lib/connection-parameters.js @@ -61,7 +61,7 @@ var ConnectionParameters = function (config) { Object.defineProperty(this, 'password', { enumerable: false, configurable: false, - writable: false, + writable: true, value: password }) From fa1d44accbb5c8201232d67899ab8819340428d2 Mon Sep 17 00:00:00 2001 From: Charmander <~@charmander.me> Date: Mon, 13 Jan 2020 08:30:21 -0800 Subject: [PATCH 2/4] Avoid creating password property on pool options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit when it didn’t exist previously. --- packages/pg-pool/index.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/pg-pool/index.js b/packages/pg-pool/index.js index 42731d3c6..64dc5fa91 100644 --- a/packages/pg-pool/index.js +++ b/packages/pg-pool/index.js @@ -60,15 +60,19 @@ class Pool extends EventEmitter { constructor (options, Client) { super() this.options = Object.assign({}, options) - const password = this.options.password - // "hiding" the password so it doesn't show up in stack traces - // or if the client is console.logged - Object.defineProperty(this.options, 'password', { - configurable: true, - enumerable: false, - value: password, - writable: true - }) + + if ('password' in this.options) { + const password = this.options.password + // "hiding" the password so it doesn't show up in stack traces + // or if the client is console.logged + Object.defineProperty(this.options, 'password', { + configurable: true, + enumerable: false, + value: password, + writable: true + }) + } + this.options.max = this.options.max || this.options.poolSize || 10 this.log = this.options.log || function () { } this.Client = this.options.Client || Client || require('pg').Client From 410b89b22bd72cbdb71db5de8c990d16a2cf6c04 Mon Sep 17 00:00:00 2001 From: Charmander <~@charmander.me> Date: Mon, 13 Jan 2020 08:33:40 -0800 Subject: [PATCH 3/4] Allow password option to be non-enumerable to avoid breaking uses like `new Pool(existingPool.options)`. --- packages/pg-pool/index.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/pg-pool/index.js b/packages/pg-pool/index.js index 64dc5fa91..79a3eca32 100644 --- a/packages/pg-pool/index.js +++ b/packages/pg-pool/index.js @@ -61,14 +61,13 @@ class Pool extends EventEmitter { super() this.options = Object.assign({}, options) - if ('password' in this.options) { - const password = this.options.password + if (options != null && 'password' in options) { // "hiding" the password so it doesn't show up in stack traces // or if the client is console.logged Object.defineProperty(this.options, 'password', { configurable: true, enumerable: false, - value: password, + value: options.password, writable: true }) } From 6df7511feda3917d26c89e7f1e1fd6e745f159bc Mon Sep 17 00:00:00 2001 From: Charmander <~@charmander.me> Date: Mon, 13 Jan 2020 11:11:08 -0800 Subject: [PATCH 4/4] Make password property definitions consistent in formatting and configurability. --- packages/pg-pool/index.js | 4 ++-- packages/pg/lib/client.js | 5 ++--- packages/pg/lib/connection-parameters.js | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/pg-pool/index.js b/packages/pg-pool/index.js index 79a3eca32..dd0d478d2 100644 --- a/packages/pg-pool/index.js +++ b/packages/pg-pool/index.js @@ -67,8 +67,8 @@ class Pool extends EventEmitter { Object.defineProperty(this.options, 'password', { configurable: true, enumerable: false, - value: options.password, - writable: true + writable: true, + value: options.password }) } diff --git a/packages/pg/lib/client.js b/packages/pg/lib/client.js index fe1ce8baf..c929d26f3 100644 --- a/packages/pg/lib/client.js +++ b/packages/pg/lib/client.js @@ -33,12 +33,11 @@ var Client = function (config) { // "hiding" the password so it doesn't show up in stack traces // or if the client is console.logged - const password = this.connectionParameters.password Object.defineProperty(this, 'password', { + configurable: true, enumerable: false, - configurable: false, writable: true, - value: password + value: this.connectionParameters.password }) this.replication = this.connectionParameters.replication diff --git a/packages/pg/lib/connection-parameters.js b/packages/pg/lib/connection-parameters.js index 55569e070..c0f8498eb 100644 --- a/packages/pg/lib/connection-parameters.js +++ b/packages/pg/lib/connection-parameters.js @@ -57,12 +57,11 @@ var ConnectionParameters = function (config) { // "hiding" the password so it doesn't show up in stack traces // or if the client is console.logged - const password = val('password', config) Object.defineProperty(this, 'password', { + configurable: true, enumerable: false, - configurable: false, writable: true, - value: password + value: val('password', config) }) this.binary = val('binary', config)