Skip to content

Commit

Permalink
Handle blank password in basic auth.
Browse files Browse the repository at this point in the history
Fixes #681.
  • Loading branch information
diversario committed Oct 24, 2013
1 parent 034e84e commit 2afab5b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions request.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,9 @@ Request.prototype.init = function (options) {
if (options.auth) {
self.auth(
(options.auth.user==="") ? options.auth.user : (options.auth.user || options.auth.username ),
options.auth.pass || options.auth.password,
options.auth.sendImmediately)
(options.auth.pass != null) ? options.auth.pass : options.auth.password,
options.auth.sendImmediately
)
}

if (self.uri.auth && !self.hasHeader('authorization')) {
Expand Down
28 changes: 28 additions & 0 deletions tests/test-basic-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var basicServer = http.createServer(function (req, res) {
if (req.headers.authorization) {
if (req.headers.authorization == 'Basic ' + new Buffer('test:testing2').toString('base64')) {
ok = true;
} else if ( req.headers.authorization == 'Basic ' + new Buffer('test:').toString('base64')) {
ok = true;
} else if ( req.headers.authorization == 'Basic ' + new Buffer(':apassword').toString('base64')) {
ok = true;
} else if ( req.headers.authorization == 'Basic ' + new Buffer('justauser').toString('base64')) {
Expand Down Expand Up @@ -146,6 +148,32 @@ var tests = [
next();
});
})
},

function (next) {
request
.get('http://localhost:6767/test/')
.auth("test","",false)
.on('response', function (res) {
assert.equal(res.statusCode, 200);
assert.equal(numBasicRequests, 12);
next();
})
},

function (next) {
request.get('http://localhost:6767/test/',
{
auth: {
user: "test",
pass: "",
sendImmediately: false
}
}, function (err, res) {
assert.equal(res.statusCode, 200);
assert.equal(numBasicRequests, 14);
next();
})
}
];

Expand Down

0 comments on commit 2afab5b

Please sign in to comment.