mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Prevents bad ssl credentials from causing a crash
Fixes: https://github.com/brianc/node-postgres/issues/2307 Fixes: https://github.com/brianc/node-postgres/issues/2004
This commit is contained in:
parent
316bec3b43
commit
f4d123b09e
@ -85,7 +85,11 @@ class Connection extends EventEmitter {
|
||||
if (net.isIP(host) === 0) {
|
||||
options.servername = host
|
||||
}
|
||||
self.stream = tls.connect(options)
|
||||
try {
|
||||
self.stream = tls.connect(options)
|
||||
} catch (err) {
|
||||
return self.emit('error', err)
|
||||
}
|
||||
self.attachListeners(self.stream)
|
||||
self.stream.on('error', reportStreamError)
|
||||
|
||||
|
||||
24
packages/pg/test/integration/gh-issues/2307-tests.js
Normal file
24
packages/pg/test/integration/gh-issues/2307-tests.js
Normal file
@ -0,0 +1,24 @@
|
||||
'use strict'
|
||||
|
||||
const pg = require('../../../lib')
|
||||
const helper = require('../test-helper')
|
||||
|
||||
const suite = new helper.Suite()
|
||||
|
||||
suite.test('bad ssl credentials do not cause crash', (done) => {
|
||||
const config = {
|
||||
ssl: {
|
||||
ca: 'invalid_value',
|
||||
key: 'invalid_value',
|
||||
cert: 'invalid_value',
|
||||
},
|
||||
}
|
||||
|
||||
const client = new pg.Client(config)
|
||||
|
||||
client.connect((err) => {
|
||||
assert(err)
|
||||
client.end()
|
||||
done()
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user