Add test for pgpass check function scope

This commit is contained in:
Brian M. Carlson 2020-08-26 15:40:33 -05:00 committed by Brian C
parent 0758b766aa
commit 1f0d3d567f
2 changed files with 19 additions and 9 deletions

View File

@ -1,21 +1,30 @@
'use strict'
const helper = require('./test-helper')
const createClient = require('./test-helper').createClient
/*
* TODO: Add _some_ comments to explain what it is we're testing, and how the
* code-being-tested works behind the scenes.
*/
test('cleartext password authentication', function () {
var client = createClient()
client.password = '!'
client.connection.stream.packets = []
client.connection.emit('authenticationCleartextPassword')
test('responds with password', function () {
var client = createClient()
client.password = '!'
client.connection.stream.packets = []
client.connection.emit('authenticationCleartextPassword')
var packets = client.connection.stream.packets
assert.lengthIs(packets, 1)
var packet = packets[0]
assert.equalBuffers(packet, [0x70, 0, 0, 0, 6, 33, 0])
})
test('does not crash with null password using pg-pass', function () {
process.env.PGPASSFILE = `${__dirname}/pgpass.file`
var client = new helper.Client({
host: 'foo',
port: 5432,
database: 'bar',
user: 'baz',
stream: new MemoryStream(),
})
client.connect()
client.connection.emit('authenticationCleartextPassword')
})
})

View File

@ -0,0 +1 @@
foo:5432:bar:baz:quz