Skip to content
This repository has been archived by the owner on Apr 24, 2019. It is now read-only.

Commit

Permalink
Add a requireCommittee option so that you can specify a specific comm…
Browse files Browse the repository at this point in the history
…ittee
  • Loading branch information
ekmartin committed Oct 1, 2014
1 parent 9b05785 commit 72ca34f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.bs
Expand Up @@ -16,7 +16,14 @@ export (options) ->
else
user = data.user
if user.auth
if options.requireAbakom
if options.requireCommittee
if user.committees.indexOf(options.requireCommittee) >= 0
user.username = username
done(null, user)
else
done(null, false, { message: 'Not in #{options.requireCommittee}' })

elif options.requireAbakom
if user.is_abakom
user.username = username
done(null, user)
Expand All @@ -25,6 +32,7 @@ export (options) ->
else
user.username = username
done(null, user)

else
done(null, false, { message: 'Bad credentials' })
)
Expand Down
47 changes: 47 additions & 0 deletions test/index.bs
Expand Up @@ -71,6 +71,53 @@ describe('passport-abakus', () ->
}
).authenticate()
)

describe('requireCommittee option', () ->
it('fail when an user is not in a provided committee', (done) ->
createApiMock({ user: {
username: 'test',
committees: ['Webkom'],
is_abakom: true,
auth: true
}})

chai.passport.use(abakusStrategy({ requireCommittee: 'LaBamba' }))
.fail((info) ->
expect(info.message).to.equal('Not in LaBamba')
done()
).req((req) ->
req.query = {
username: 'test',
password: 'test'
}
).authenticate()
)

it('success when user is a member of a provided committee', (done) ->
createApiMock({ user: {
username: 'test',
committees: ['Webkom'],
is_abakom: true,
auth: true
}})

chai.passport.use(abakusStrategy({ requireCommittee: 'Webkom' }))
.success((user, info) ->
expect(user.username).to.equal('test')
expect(user.committees.indexOf('Webkom')).to.be.above(-1)
expect(user.is_abakom).to.be.true
expect(user.auth).to.be.true
done()
).req((req) ->
req.query = {
username: 'test',
password: 'test'
}
).authenticate()

)
)

describe('requireAbakom option', () ->
it('fail when user is not a member of abakom', (done) ->
createApiMock({ user: {
Expand Down

0 comments on commit 72ca34f

Please sign in to comment.