Skip to content

Commit

Permalink
add "Basic" check to req.auth
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Oct 19, 2012
1 parent 7bf4ad3 commit d6cb449
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/request.js
Expand Up @@ -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(':');
Expand Down
15 changes: 15 additions & 0 deletions test/req.auth.js
Expand Up @@ -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();

Expand Down

0 comments on commit d6cb449

Please sign in to comment.