From 1596a933eb5e856b96193e5e25b908cdc25ceda6 Mon Sep 17 00:00:00 2001 From: Jos Kuijpers Date: Tue, 21 Jun 2016 16:42:30 +0200 Subject: [PATCH] Fix SSL configuration error and add tests. #848 (#1055) --- lib/connection-parameters.js | 2 +- test/unit/client/configuration-tests.js | 27 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/connection-parameters.js b/lib/connection-parameters.js index bd42758..2904f0c 100644 --- a/lib/connection-parameters.js +++ b/lib/connection-parameters.js @@ -47,7 +47,7 @@ var ConnectionParameters = function(config) { this.host = val('host', config); this.password = val('password', config); this.binary = val('binary', config); - this.ssl = config.ssl || useSsl(); + this.ssl = typeof config.ssl === 'boolean' ? config.ssl : useSsl(); this.client_encoding = val("client_encoding", config); //a domain socket begins with '/' this.isDomainSocket = (!(this.host||'').indexOf('/')); diff --git a/test/unit/client/configuration-tests.js b/test/unit/client/configuration-tests.js index d42ee0e..0204af2 100644 --- a/test/unit/client/configuration-tests.js +++ b/test/unit/client/configuration-tests.js @@ -11,6 +11,7 @@ test('client settings', function() { assert.equal(client.user, pguser); assert.equal(client.database, pgdatabase); assert.equal(client.port, pgport); + assert.equal(client.ssl, false); }); test('custom', function() { @@ -21,13 +22,37 @@ test('client settings', function() { user: user, database: database, port: 321, - password: password + password: password, + ssl: true }); assert.equal(client.user, user); assert.equal(client.database, database); assert.equal(client.port, 321); assert.equal(client.password, password); + assert.equal(client.ssl, true); + }); + + test('custom ssl default on', function() { + var old = process.env.PGSSLMODE; + process.env.PGSSLMODE = "prefer"; + + var client = new Client(); + process.env.PGSSLMODE = old; + + assert.equal(client.ssl, true); + }); + + test('custom ssl force off', function() { + var old = process.env.PGSSLMODE; + process.env.PGSSLMODE = "prefer"; + + var client = new Client({ + ssl: false + }); + process.env.PGSSLMODE = old; + + assert.equal(client.ssl, false); }); });