Skip to content

Commit 50a8bee

Browse files
committed
Enable old commented out ssl test, add test for self-signed cert failuer
1 parent d5dc421 commit 50a8bee

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed
Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
'use strict'
2-
var pg = require(__dirname + '/../../../lib')
3-
var config = require(__dirname + '/test-helper').config
4-
test('can connect with ssl', function () {
5-
return false
6-
config.ssl = {
7-
rejectUnauthorized: false
2+
const { pg, Suite } = require('./test-helper')
3+
const assert = require('assert')
4+
5+
const suite = new Suite()
6+
7+
suite.testAsync('it can connect w/ ssl', async () => {
8+
const ssl = {
9+
rejectUnauthorized: false,
810
}
9-
pg.connect(config, assert.success(function (client) {
10-
return false
11-
client.query('SELECT NOW()', assert.success(function () {
12-
pg.end()
13-
}))
14-
}))
11+
12+
const client = new pg.Client({ ssl })
13+
await client.connect()
14+
assert.strictEqual(client.connection.stream.encrypted, true)
15+
await client.end()
16+
})
17+
18+
suite.testAsync('it rejects on self-signed cert', async () => {
19+
const ssl = true
20+
const client = new pg.Client({ ssl })
21+
try {
22+
await client.connect()
23+
} catch (e) {
24+
assert(e.message.includes('self signed'))
25+
return
26+
}
27+
throw new Error('connection should have failed with self-signed cert error')
1528
})

0 commit comments

Comments
 (0)