Skip to content

Commit fe153ec

Browse files
committed
Support empty username
1 parent 5de8cdc commit fe153ec

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.DS_Store*
3+
*.log

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ module.exports = function(req){
2121

2222
// credentials
2323
auth = new Buffer(auth, 'base64').toString();
24-
auth = auth.match(/^([^:]+):(.*)$/);
24+
auth = auth.match(/^([^:]*):(.*)$/);
2525
if (!auth) return;
2626

2727
return { name: auth[1], pass: auth[2] };
28-
};
28+
};

test/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,18 @@ describe('auth(req)', function(){
4444
auth(req).should.eql({ name: 'foo', pass: ''});
4545
})
4646
})
47+
48+
describe('with empty userid', function(){
49+
it('should return .user and .pass', function(){
50+
var req = request('basic ' + new Buffer(':pass').toString('base64'));
51+
auth(req).should.eql({ name: '', pass: 'pass'});
52+
})
53+
})
54+
55+
describe('with empty userid and pass', function(){
56+
it('should return .user and .pass', function(){
57+
var req = request('basic ' + new Buffer(':').toString('base64'));
58+
auth(req).should.eql({ name: '', pass: ''});
59+
})
60+
})
4761
})

0 commit comments

Comments
 (0)