mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-25 16:03:13 +00:00
Merge pull request #2309 from chris--young/ssl-err
Prevents bad ssl credentials from causing a crash
This commit is contained in:
commit
61e4b7f03b
@ -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