Skip to content

Commit

Permalink
8.0 Release (#2117)
Browse files Browse the repository at this point in the history
* Drop support for EOL versions of node (#2062)

* Drop support for EOL versions of node

* Re-add testing for node@8.x

* Revert changes to .travis.yml

* Update packages/pg-pool/package.json

Co-Authored-By: Charmander <~@charmander.me>

Co-authored-by: Charmander <~@charmander.me>

* Remove password from stringified outputs (#2066)

* Remove password from stringified outputs

Theres a security concern where if you're not careful and you include your client or pool instance in console.log or stack traces it might include the database password.  To widen the pit of success I'm making that field non-enumerable.  You can still get at it...it just wont show up "by accident" when you're logging things now.

The backwards compatiblity impact of this is very small, but it is still technically somewhat an API change so...8.0.

* Implement feedback

* Fix more whitespace the autoformatter changed

* Simplify code a bit

* Remove password from stringified outputs (#2070)

* Keep ConnectionParameters’s password property writable

`Client` writes to it when `password` is a function.

* Avoid creating password property on pool options

when it didn’t exist previously.

* Allow password option to be non-enumerable

to avoid breaking uses like `new Pool(existingPool.options)`.

* Make password property definitions consistent

in formatting and configurability.

Co-authored-by: Charmander <~@charmander.me>

* Make `native` non-enumerable (#2065)

* Make `native` non-enumerable

Making it non-enumerable means less spurious "Cannot find module"
errors in your logs when iterating over `pg` objects.

`Object.defineProperty` has been available since Node 0.12.

See #1894 (comment)

* Add test for `native` enumeration

Co-authored-by: Gabe Gorelick <gabegorelick@gmail.com>

* Use class-extends to wrap Pool (#1541)

* Use class-extends to wrap Pool

* Minimize diff

* Test `BoundPool` inheritance

Co-authored-by: Charmander <~@charmander.me>
Co-authored-by: Brian C <brian.m.carlson@gmail.com>

* Continue support for creating a pg.Pool from another instance’s options (#2076)

* Add failing test for creating a `BoundPool` from another instance’s settings

* Continue support for creating a pg.Pool from another instance’s options

by dropping the requirement for the `password` property to be enumerable.

* Use user name as default database when user is non-default (#1679)

Not entirely backwards-compatible.

* Make native client password property consistent with others

i.e. configurable.

* Make notice messages not an instance of Error (#2090)

* Make notice messages not an instance of Error

Slight API cleanup to make a notice instance the same shape as it was, but not be an instance of error.  This is a backwards incompatible change though I expect the impact to be minimal.

Closes #1982

* skip notice test in travis

* Pin node@13.6 for regression in async iterators

* Check and see if node 13.8 is still borked on async iterator

* Yeah, node still has changed edge case behavior on stream

* Emit notice messages on travis

* Revert "Revert "Support additional tls.connect() options (#1996)" (#2010)" (#2113)

This reverts commit 510a273.

* Fix ssl tests (#2116)

* Convert Query to an ES6 class (#2126)

The last missing `new` deprecation warning for pg 8.

Co-authored-by: Charmander <~@charmander.me>
Co-authored-by: Gabe Gorelick <gabegorelick@gmail.com>
Co-authored-by: Natalie Wolfe <natalie@lifewanted.com>
  • Loading branch information
4 people committed Mar 30, 2020
1 parent c036779 commit aafd8ac
Show file tree
Hide file tree
Showing 22 changed files with 416 additions and 317 deletions.
12 changes: 12 additions & 0 deletions packages/pg-pool/index.js
Expand Up @@ -64,6 +64,18 @@ class Pool extends EventEmitter {
constructor (options, Client) {
super()
this.options = Object.assign({}, options)

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,
writable: true,
value: options.password
})
}

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
Expand Down
2 changes: 1 addition & 1 deletion packages/pg-pool/package.json
Expand Up @@ -34,6 +34,6 @@
"pg-cursor": "^1.3.0"
},
"peerDependencies": {
"pg": ">5.0"
"pg": ">=8.0"
}
}
4 changes: 1 addition & 3 deletions packages/pg/Makefile
Expand Up @@ -62,6 +62,4 @@ test-pool:

lint:
@echo "***Starting lint***"
node -e "process.exit(Number(process.versions.node.split('.')[0]) < 8 ? 0 : 1)" \
&& echo "***Skipping lint (node version too old)***" \
|| node_modules/.bin/eslint lib
node_modules/.bin/eslint lib
11 changes: 10 additions & 1 deletion packages/pg/lib/client.js
Expand Up @@ -30,7 +30,16 @@ var Client = function (config) {
this.database = this.connectionParameters.database
this.port = this.connectionParameters.port
this.host = this.connectionParameters.host
this.password = this.connectionParameters.password

// "hiding" the password so it doesn't show up in stack traces
// or if the client is console.logged
Object.defineProperty(this, 'password', {
configurable: true,
enumerable: false,
writable: true,
value: this.connectionParameters.password
})

this.replication = this.connectionParameters.replication

var c = config || {}
Expand Down
22 changes: 0 additions & 22 deletions packages/pg/lib/compat/check-constructor.js

This file was deleted.

19 changes: 0 additions & 19 deletions packages/pg/lib/compat/warn-deprecation.js

This file was deleted.

20 changes: 3 additions & 17 deletions packages/pg/lib/connection-fast.js
Expand Up @@ -15,8 +15,6 @@ var Writer = require('buffer-writer')
// eslint-disable-next-line
var PacketStream = require('pg-packet-stream')

var warnDeprecation = require('./compat/warn-deprecation')

var TEXT_MODE = 0

// TODO(bmc) support binary mode here
Expand Down Expand Up @@ -95,21 +93,9 @@ Connection.prototype.connect = function (port, host) {
return self.emit('error', new Error('There was an error establishing an SSL connection'))
}
var tls = require('tls')
const options = {
socket: self.stream,
checkServerIdentity: self.ssl.checkServerIdentity || tls.checkServerIdentity,
rejectUnauthorized: self.ssl.rejectUnauthorized,
ca: self.ssl.ca,
pfx: self.ssl.pfx,
key: self.ssl.key,
passphrase: self.ssl.passphrase,
cert: self.ssl.cert,
secureOptions: self.ssl.secureOptions,
NPNProtocols: self.ssl.NPNProtocols
}
if (typeof self.ssl.rejectUnauthorized !== 'boolean') {
warnDeprecation('Implicit disabling of certificate verification is deprecated and will be removed in pg 8. Specify `rejectUnauthorized: true` to require a valid CA or `rejectUnauthorized: false` to explicitly opt out of MITM protection.', 'PG-SSL-VERIFY')
}
const options = Object.assign({
socket: self.stream
}, self.ssl)
if (net.isIP(host) === 0) {
options.servername = host
}
Expand Down
16 changes: 15 additions & 1 deletion packages/pg/lib/connection-parameters.js
Expand Up @@ -52,9 +52,23 @@ var ConnectionParameters = function (config) {

this.user = val('user', config)
this.database = val('database', config)

if (this.database === undefined) {
this.database = this.user
}

this.port = parseInt(val('port', config), 10)
this.host = val('host', config)
this.password = val('password', config)

// "hiding" the password so it doesn't show up in stack traces
// or if the client is console.logged
Object.defineProperty(this, 'password', {
configurable: true,
enumerable: false,
writable: true,
value: val('password', config)
})

this.binary = val('binary', config)
this.ssl = typeof config.ssl === 'undefined' ? useSsl() : config.ssl
this.client_encoding = val('client_encoding', config)
Expand Down
28 changes: 7 additions & 21 deletions packages/pg/lib/connection.js
Expand Up @@ -14,8 +14,6 @@ var util = require('util')
var Writer = require('buffer-writer')
var Reader = require('packet-reader')

var warnDeprecation = require('./compat/warn-deprecation')

var TEXT_MODE = 0
var BINARY_MODE = 1
var Connection = function (config) {
Expand Down Expand Up @@ -95,21 +93,9 @@ Connection.prototype.connect = function (port, host) {
return self.emit('error', new Error('There was an error establishing an SSL connection'))
}
var tls = require('tls')
const options = {
socket: self.stream,
checkServerIdentity: self.ssl.checkServerIdentity || tls.checkServerIdentity,
rejectUnauthorized: self.ssl.rejectUnauthorized,
ca: self.ssl.ca,
pfx: self.ssl.pfx,
key: self.ssl.key,
passphrase: self.ssl.passphrase,
cert: self.ssl.cert,
secureOptions: self.ssl.secureOptions,
NPNProtocols: self.ssl.NPNProtocols
}
if (typeof self.ssl.rejectUnauthorized !== 'boolean') {
warnDeprecation('Implicit disabling of certificate verification is deprecated and will be removed in pg 8. Specify `rejectUnauthorized: true` to require a valid CA or `rejectUnauthorized: false` to explicitly opt out of MITM protection.', 'PG-SSL-VERIFY')
}
const options = Object.assign({
socket: self.stream
}, self.ssl)
if (net.isIP(host) === 0) {
options.servername = host
}
Expand Down Expand Up @@ -602,7 +588,7 @@ Connection.prototype._readValue = function (buffer) {
}

// parses error
Connection.prototype.parseE = function (buffer, length) {
Connection.prototype.parseE = function (buffer, length, isNotice) {
var fields = {}
var fieldType = this.readString(buffer, 1)
while (fieldType !== '\0') {
Expand All @@ -611,10 +597,10 @@ Connection.prototype.parseE = function (buffer, length) {
}

// the msg is an Error instance
var msg = new Error(fields.M)
var msg = isNotice ? { message: fields.M } : new Error(fields.M)

// for compatibility with Message
msg.name = 'error'
msg.name = isNotice ? 'notice' : 'error'
msg.length = length

msg.severity = fields.S
Expand All @@ -638,7 +624,7 @@ Connection.prototype.parseE = function (buffer, length) {

// same thing, different name
Connection.prototype.parseN = function (buffer, length) {
var msg = this.parseE(buffer, length)
var msg = this.parseE(buffer, length, true)
msg.name = 'notice'
return msg
}
Expand Down
2 changes: 1 addition & 1 deletion packages/pg/lib/defaults.js
Expand Up @@ -15,7 +15,7 @@ module.exports = {
user: process.platform === 'win32' ? process.env.USERNAME : process.env.USER,

// name of database to connect
database: process.platform === 'win32' ? process.env.USERNAME : process.env.USER,
database: undefined,

// database user's password
password: null,
Expand Down
50 changes: 25 additions & 25 deletions packages/pg/lib/index.js
Expand Up @@ -7,25 +7,17 @@
* README.md file in the root directory of this source tree.
*/

var util = require('util')
var Client = require('./client')
var defaults = require('./defaults')
var Connection = require('./connection')
var Pool = require('pg-pool')
const checkConstructor = require('./compat/check-constructor')

const poolFactory = (Client) => {
var BoundPool = function (options) {
// eslint-disable-next-line no-eval
checkConstructor('pg.Pool', 'PG-POOL-NEW', () => eval('new.target'))

var config = Object.assign({ Client: Client }, options)
return new Pool(config)
return class BoundPool extends Pool {
constructor (options) {
super(options, Client)
}
}

util.inherits(BoundPool, Pool)

return BoundPool
}

var PG = function (clientConstructor) {
Expand All @@ -44,20 +36,28 @@ if (typeof process.env.NODE_PG_FORCE_NATIVE !== 'undefined') {
module.exports = new PG(Client)

// lazy require native module...the native module may not have installed
module.exports.__defineGetter__('native', function () {
delete module.exports.native
var native = null
try {
native = new PG(require('./native'))
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
throw err
Object.defineProperty(module.exports, 'native', {
configurable: true,
enumerable: false,
get() {
var native = null
try {
native = new PG(require('./native'))
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
throw err
}
/* eslint-disable no-console */
console.error(err.message)
/* eslint-enable no-console */
}
/* eslint-disable no-console */
console.error(err.message)
/* eslint-enable no-console */

// overwrite module.exports.native so that getter is never called again
Object.defineProperty(module.exports, 'native', {
value: native
})

return native
}
module.exports.native = native
return native
})
}
10 changes: 9 additions & 1 deletion packages/pg/lib/native/client.js
Expand Up @@ -43,7 +43,15 @@ var Client = module.exports = function (config) {
// for the time being. TODO: deprecate all this jazz
var cp = this.connectionParameters = new ConnectionParameters(config)
this.user = cp.user
this.password = cp.password

// "hiding" the password so it doesn't show up in stack traces
// or if the client is console.logged
Object.defineProperty(this, 'password', {
configurable: true,
enumerable: false,
writable: true,
value: cp.password
})
this.database = cp.database
this.host = cp.host
this.port = cp.port
Expand Down

0 comments on commit aafd8ac

Please sign in to comment.