Skip to content

Commit

Permalink
Add test for pgpass check function scope
Browse files Browse the repository at this point in the history
  • Loading branch information
brianc committed Aug 26, 2020
1 parent 0758b76 commit 1f0d3d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
27 changes: 18 additions & 9 deletions packages/pg/test/unit/client/cleartext-password-tests.js
@@ -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')
})
})
1 change: 1 addition & 0 deletions packages/pg/test/unit/client/pgpass.file
@@ -0,0 +1 @@
foo:5432:bar:baz:quz

0 comments on commit 1f0d3d5

Please sign in to comment.