Skip to content

Commit

Permalink
fix(address-parsing): don't truncate ':' passwords
Browse files Browse the repository at this point in the history
Fix a bug which truncated passwords containing a ':' character because
the parseAddress function relied upon node's url.parse().auth which
returns the user:pass pair already URI-decoded.

Fixes #318
  • Loading branch information
prestona authored and mbroadst committed May 20, 2017
1 parent 6767767 commit fc84946
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/policies/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,13 @@ Policy.prototype.parseAddress = function(address) {

result.rootUri = result.protocol + '://';
if (!!parsedAddress.auth) {
result.rootUri += parsedAddress.auth + '@';

var userPass = parsedAddress.auth.split(':', 2);
result.user = userPass[0];
result.pass = userPass[1] || null;
// capture the part of the encoded URI between '//' and '@'
var matchAuth = /amqps?:\/\/([^@]+).+/g;
var auth = matchAuth.exec(address)[1];
result.rootUri += auth + '@';
var authSplit = auth.split(':', 2);
result.user = decodeURIComponent(authSplit[0]);
result.pass = (authSplit[1]) ? decodeURIComponent(authSplit[1]) : null;
}

result.rootUri += result.host + ':' + result.port;
Expand Down
10 changes: 10 additions & 0 deletions test/unit/address.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ describe('Address Parsing', function() {
rootUri: 'amqps://username:[email protected]:1234',
href: 'amqps://username:[email protected]:1234/myroute'
}
},
{
description: 'should match credentials if passwd contains colons',
address: 'amqp://username:ii%7DS%[email protected]',
expected: {
protocol: 'amqp', host: 'my.amqp.server', port: 5672, path: '/',
user: 'username', pass: 'ii}S:ae3',
rootUri: 'amqp://username:ii%7DS%[email protected]:5672',
href: 'amqp://username:ii%7DS:[email protected]'
}
}
].forEach(function(testCase) {
it('should match ' + testCase.description, function() {
Expand Down

0 comments on commit fc84946

Please sign in to comment.