Skip to content

Commit

Permalink
Fix regression accepting a Koa context
Browse files Browse the repository at this point in the history
fixes #18
closes #19
  • Loading branch information
dougwilson committed Jul 2, 2015
1 parent d479495 commit c7647ca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unreleased
==========

* Fix regression accepting a Koa context

1.0.2 / 2015-06-12
==================

Expand Down
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function auth(req) {
var header = (req.req || req).headers.authorization

// parse header
var header = req.headers.authorization
var match = credentialsRegExp.exec(header || '')

if (!match) {
Expand Down
14 changes: 14 additions & 0 deletions test/basic-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ describe('auth(req)', function () {
it('should be required', function () {
assert.throws(auth, /argument req is required/)
})

it('should accept a request', function () {
var req = request('basic Zm9vOmJhcg==')
var creds = auth(req)
assert.equal(creds.name, 'foo')
assert.equal(creds.pass, 'bar')
})

it('should accept a koa context', function () {
var ctx = { req: request('basic Zm9vOmJhcg==') }
var creds = auth(ctx)
assert.equal(creds.name, 'foo')
assert.equal(creds.pass, 'bar')
})
})
})

Expand Down

0 comments on commit c7647ca

Please sign in to comment.