Permalink
Browse files

add "Basic" check to req.auth

  • Loading branch information...
1 parent 7bf4ad3 commit d6cb4490111302077f8b02531907dc3fc5cc4fe2 @tj tj committed Oct 19, 2012
Showing with 19 additions and 2 deletions.
  1. +4 −2 lib/request.js
  2. +15 −0 test/req.auth.js
View
@@ -387,8 +387,10 @@ req.__defineGetter__('auth', function(){
if (!auth) return;
// malformed
- auth = auth.split(' ')[1];
- if (!auth) return;
+ var parts = auth.split(' ');
+ if ('basic' != parts[0].toLowerCase()) return;
+ if (!parts[1]) return;
+ auth = parts[1];
// credentials
auth = new Buffer(auth, 'base64').toString().split(':');
View
@@ -33,6 +33,21 @@ describe('req', function(){
})
})
+ describe('when Authorization is not Basic', function(){
+ it('should return undefined', function(done){
+ var app = express();
+
+ app.get('/', function(req, res){
+ res.send(req.auth || 'none');
+ });
+
+ request(app)
+ .get('/')
+ .set('Authorization', 'Meow dG9iaTpmZXJyZXQ')
+ .expect('none', done)
+ })
+ })
+
it('should return .username and .password', function(done){
var app = express();

0 comments on commit d6cb449

Please sign in to comment.