From 1f0d3d567f00a0fe18db7bf66f6b4295f4f7a564 Mon Sep 17 00:00:00 2001 From: "Brian M. Carlson" Date: Wed, 26 Aug 2020 15:40:33 -0500 Subject: [PATCH] Add test for pgpass check function scope --- .../unit/client/cleartext-password-tests.js | 27 ++++++++++++------- packages/pg/test/unit/client/pgpass.file | 1 + 2 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 packages/pg/test/unit/client/pgpass.file diff --git a/packages/pg/test/unit/client/cleartext-password-tests.js b/packages/pg/test/unit/client/cleartext-password-tests.js index cd8dbb00..49db22d0 100644 --- a/packages/pg/test/unit/client/cleartext-password-tests.js +++ b/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') + }) }) diff --git a/packages/pg/test/unit/client/pgpass.file b/packages/pg/test/unit/client/pgpass.file new file mode 100644 index 00000000..fa0cd41b --- /dev/null +++ b/packages/pg/test/unit/client/pgpass.file @@ -0,0 +1 @@ +foo:5432:bar:baz:quz