Skip to content

Commit 43114f4

Browse files
authored
Merge pull request #17 from ywkim/master
Add supporting username and password for socket connections
2 parents b53c2bd + 279fdea commit 43114f4

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
@@ -24,6 +24,10 @@ function parse(str) {
2424
}
2525
}
2626

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

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

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)