From c7647ca4e66788c1a6680e76a6e005e501638521 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Thu, 2 Jul 2015 00:40:03 -0400 Subject: [PATCH] Fix regression accepting a Koa context fixes #18 closes #19 --- HISTORY.md | 5 +++++ index.js | 1 - test/basic-auth.js | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 75f1341..85e0fe7 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +========== + + * Fix regression accepting a Koa context + 1.0.2 / 2015-06-12 ================== diff --git a/index.js b/index.js index 4ead190..79801c1 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/test/basic-auth.js b/test/basic-auth.js index 4375388..08d9822 100644 --- a/test/basic-auth.js +++ b/test/basic-auth.js @@ -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') + }) }) })