Skip to content

Commit c7647ca

Browse files
committed
Fix regression accepting a Koa context
fixes #18 closes #19
1 parent d479495 commit c7647ca

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
unreleased
2+
==========
3+
4+
* Fix regression accepting a Koa context
5+
16
1.0.2 / 2015-06-12
27
==================
38

index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ function auth(req) {
5454
var header = (req.req || req).headers.authorization
5555

5656
// parse header
57-
var header = req.headers.authorization
5857
var match = credentialsRegExp.exec(header || '')
5958

6059
if (!match) {

test/basic-auth.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ describe('auth(req)', function () {
1515
it('should be required', function () {
1616
assert.throws(auth, /argument req is required/)
1717
})
18+
19+
it('should accept a request', function () {
20+
var req = request('basic Zm9vOmJhcg==')
21+
var creds = auth(req)
22+
assert.equal(creds.name, 'foo')
23+
assert.equal(creds.pass, 'bar')
24+
})
25+
26+
it('should accept a koa context', function () {
27+
var ctx = { req: request('basic Zm9vOmJhcg==') }
28+
var creds = auth(ctx)
29+
assert.equal(creds.name, 'foo')
30+
assert.equal(creds.pass, 'bar')
31+
})
1832
})
1933
})
2034

0 commit comments

Comments
 (0)