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:
Youngwook Kim 2017-11-22 10:17:22 +09:00
parent eafb7acd95
commit 279fdeae2f
2 changed files with 12 additions and 4 deletions

View File

@ -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;
}

View File

@ -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',