Fix SSL configuration error and add tests. #848 (#1055)

This commit is contained in:
Jos Kuijpers 2016-06-21 16:42:30 +02:00 committed by Brian C
parent d1c5fc694b
commit 1596a933eb
2 changed files with 27 additions and 2 deletions

View File

@ -47,7 +47,7 @@ var ConnectionParameters = function(config) {
this.host = val('host', config); this.host = val('host', config);
this.password = val('password', config); this.password = val('password', config);
this.binary = val('binary', 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); this.client_encoding = val("client_encoding", config);
//a domain socket begins with '/' //a domain socket begins with '/'
this.isDomainSocket = (!(this.host||'').indexOf('/')); this.isDomainSocket = (!(this.host||'').indexOf('/'));

View File

@ -11,6 +11,7 @@ test('client settings', function() {
assert.equal(client.user, pguser); assert.equal(client.user, pguser);
assert.equal(client.database, pgdatabase); assert.equal(client.database, pgdatabase);
assert.equal(client.port, pgport); assert.equal(client.port, pgport);
assert.equal(client.ssl, false);
}); });
test('custom', function() { test('custom', function() {
@ -21,13 +22,37 @@ test('client settings', function() {
user: user, user: user,
database: database, database: database,
port: 321, port: 321,
password: password password: password,
ssl: true
}); });
assert.equal(client.user, user); assert.equal(client.user, user);
assert.equal(client.database, database); assert.equal(client.database, database);
assert.equal(client.port, 321); assert.equal(client.port, 321);
assert.equal(client.password, password); 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);
}); });
}); });