Skip to content

Commit 279fdea

Browse files
committed
Add supporting username and password for socket connections
This fix adds the ability to use username and password even when using a socket.
1 parent eafb7ac commit 279fdea

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ function parse(str) {
2323
}
2424
}
2525

26+
var auth = (result.auth || ':').split(':');
27+
config.user = auth[0];
28+
config.password = auth.splice(1).join(':');
29+
2630
config.port = result.port;
2731
if(result.protocol == 'socket:') {
2832
config.host = decodeURI(result.pathname);
@@ -40,10 +44,6 @@ function parse(str) {
4044
}
4145
config.database = pathname && decodeURI(pathname);
4246

43-
var auth = (result.auth || ':').split(':');
44-
config.user = auth[0];
45-
config.password = auth.splice(1).join(':');
46-
4747
if (config.ssl === 'true' || config.ssl === '1') {
4848
config.ssl = true;
4949
}

test/parse.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ describe('parse', function(){
5252
subject.client_encoding.should.equal('utf8');
5353
});
5454

55+
it('initializing with unix domain socket, username and password', function(){
56+
var subject = parse('socket://brian:pw@/var/run/?db=mydb');
57+
subject.user.should.equal('brian');
58+
subject.password.should.equal('pw');
59+
subject.host.should.equal('/var/run/');
60+
subject.database.should.equal('mydb');
61+
});
62+
5563
it('password contains < and/or > characters', function(){
5664
var sourceConfig = {
5765
user:'brian',

0 commit comments

Comments
 (0)