mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Add supporting username and password for socket connections
This fix adds the ability to use username and password even when using a socket.
This commit is contained in:
parent
eafb7acd95
commit
279fdeae2f
8
index.js
8
index.js
@ -23,6 +23,10 @@ function parse(str) {
|
||||
}
|
||||
}
|
||||
|
||||
var auth = (result.auth || ':').split(':');
|
||||
config.user = auth[0];
|
||||
config.password = auth.splice(1).join(':');
|
||||
|
||||
config.port = result.port;
|
||||
if(result.protocol == 'socket:') {
|
||||
config.host = decodeURI(result.pathname);
|
||||
@ -40,10 +44,6 @@ function parse(str) {
|
||||
}
|
||||
config.database = pathname && decodeURI(pathname);
|
||||
|
||||
var auth = (result.auth || ':').split(':');
|
||||
config.user = auth[0];
|
||||
config.password = auth.splice(1).join(':');
|
||||
|
||||
if (config.ssl === 'true' || config.ssl === '1') {
|
||||
config.ssl = true;
|
||||
}
|
||||
|
||||
@ -52,6 +52,14 @@ describe('parse', function(){
|
||||
subject.client_encoding.should.equal('utf8');
|
||||
});
|
||||
|
||||
it('initializing with unix domain socket, username and password', function(){
|
||||
var subject = parse('socket://brian:pw@/var/run/?db=mydb');
|
||||
subject.user.should.equal('brian');
|
||||
subject.password.should.equal('pw');
|
||||
subject.host.should.equal('/var/run/');
|
||||
subject.database.should.equal('mydb');
|
||||
});
|
||||
|
||||
it('password contains < and/or > characters', function(){
|
||||
var sourceConfig = {
|
||||
user:'brian',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user