Skip to content

Commit 1596a93

Browse files
joskuijpersbrianc
authored andcommitted
Fix SSL configuration error and add tests. brianc#848 (brianc#1055)
1 parent d1c5fc6 commit 1596a93

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/connection-parameters.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var ConnectionParameters = function(config) {
4747
this.host = val('host', config);
4848
this.password = val('password', config);
4949
this.binary = val('binary', config);
50-
this.ssl = config.ssl || useSsl();
50+
this.ssl = typeof config.ssl === 'boolean' ? config.ssl : useSsl();
5151
this.client_encoding = val("client_encoding", config);
5252
//a domain socket begins with '/'
5353
this.isDomainSocket = (!(this.host||'').indexOf('/'));

test/unit/client/configuration-tests.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ test('client settings', function() {
1111
assert.equal(client.user, pguser);
1212
assert.equal(client.database, pgdatabase);
1313
assert.equal(client.port, pgport);
14+
assert.equal(client.ssl, false);
1415
});
1516

1617
test('custom', function() {
@@ -21,13 +22,37 @@ test('client settings', function() {
2122
user: user,
2223
database: database,
2324
port: 321,
24-
password: password
25+
password: password,
26+
ssl: true
2527
});
2628

2729
assert.equal(client.user, user);
2830
assert.equal(client.database, database);
2931
assert.equal(client.port, 321);
3032
assert.equal(client.password, password);
33+
assert.equal(client.ssl, true);
34+
});
35+
36+
test('custom ssl default on', function() {
37+
var old = process.env.PGSSLMODE;
38+
process.env.PGSSLMODE = "prefer";
39+
40+
var client = new Client();
41+
process.env.PGSSLMODE = old;
42+
43+
assert.equal(client.ssl, true);
44+
});
45+
46+
test('custom ssl force off', function() {
47+
var old = process.env.PGSSLMODE;
48+
process.env.PGSSLMODE = "prefer";
49+
50+
var client = new Client({
51+
ssl: false
52+
});
53+
process.env.PGSSLMODE = old;
54+
55+
assert.equal(client.ssl, false);
3156
});
3257

3358
});

0 commit comments

Comments
 (0)