Skip to content
This repository has been archived by the owner on Dec 21, 2020. It is now read-only.

Commit

Permalink
Merge 053346f into 8e957c0
Browse files Browse the repository at this point in the history
  • Loading branch information
nexdrew committed Dec 12, 2016
2 parents 8e957c0 + 053346f commit 0fd6ca4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/authorizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ AuthorizerOAuth2.prototype.authorize = AuthorizerOAuth2.prototype.whoami = funct
if (err) return cb(err)
else if (!user.accessToken) return _this.session.oauthURL(cb, token)
else {
// since this plugin manages its own caching, let the upstream service
// know that it should not cache results itself
user.cacheAllowed = false
// we hold a lock in redis for a few minutes, to prevent
// a thundering herd of auth requests.
_this.session.checkLock(token, function (locked) {
Expand Down
51 changes: 51 additions & 0 deletions test/authorizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,57 @@ tap.test('it returns error with login url if SSO dance is not complete', functio
})
})

tap.test('it indicates that upstream caching is not allowed with OAuth-verified response', t => {
var authorizer = new Authorizer()
var profile = nock('https://api.github.com')
.get('/user')
.reply(200)

session.unlock('ben@example.com-abc123')

session.set('ben@example.com-abc123', userComplete, function (err) {
t.equal(err, null)
authorizer.authorize({
headers: {
authorization: 'Bearer ben@example.com-abc123'
}
}, function (err, user) {
authorizer.end()
session.unlock('ben@example.com-abc123')
session.delete('ben@example.com-abc123')

profile.done()
t.equal(err, null)
t.equal(user.email, 'ben@example.com')
t.equal(user.cacheAllowed, false)
t.end()
})
})
})

tap.test('it indicates that upstream caching is not allowed with cached response', t => {
var authorizer = new Authorizer()

session.lock('ben@example.com-abc123')
session.set('ben@example.com-abc123', userComplete, function (err) {
t.equal(err, null)
authorizer.authorize({
headers: {
authorization: 'Bearer ben@example.com-abc123'
}
}, function (err, user) {
authorizer.end()
session.delete('ben@example.com-abc123')
session.unlock('ben@example.com-abc123')

t.equal(err, null)
t.equal(user.email, 'ben@example.com')
t.equal(user.cacheAllowed, false)
t.end()
})
})
})

tap.test('after', function (t) {
session.end(true)
t.end()
Expand Down

0 comments on commit 0fd6ca4

Please sign in to comment.