Skip to content

Commit

Permalink
More invalidate tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
wbyoung committed Jun 30, 2014
1 parent e24d20c commit 9995993
Showing 1 changed file with 57 additions and 3 deletions.
60 changes: 57 additions & 3 deletions test/invalidate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('admit-one', function() {
this.req.auth = {
user: {},
db: { user: {} },
token: ''
token: 'AB83212'
};
this.res.setHeader = sinon.spy();
this.results = {};
Expand All @@ -50,7 +50,61 @@ describe('admit-one', function() {
this.admit.invalidate(this.req, this.res, null);
});

it('invalidates sessions');
it('fails if token removal fails');
it('fails if authorization is missing user', function(done) {
this.req.auth.user = undefined;
this.res.json = function(code, json) {
expect(code).to.eql(401);
expect(json).to.eql({ error: 'not authorized (auth[user])' });
expect(this.admit._adapter.users.removeToken).to.not.been.called;
done();
}.bind(this);
this.admit.invalidate(this.req, this.res, null);
});

it('fails if authorization is missing db user', function(done) {
this.req.auth.db.user = undefined;
this.res.json = function(code, json) {
expect(code).to.eql(401);
expect(json).to.eql({ error: 'not authorized (auth[db][user])' });
expect(this.admit._adapter.users.removeToken).to.not.been.called;
done();
}.bind(this);
this.admit.invalidate(this.req, this.res, null);
});

it('fails if authorization is missing token', function(done) {
this.req.auth.token = undefined;
this.res.json = function(code, json) {
expect(code).to.eql(401);
expect(json).to.eql({ error: 'not authorized (auth[token])' });
expect(this.admit._adapter.users.removeToken).to.not.been.called;
done();
}.bind(this);
this.admit.invalidate(this.req, this.res, null);
});

it('fails if token removal fails', function(done) {
this.results.removeToken = false;
this.res.json = function(code, json) {
expect(code).to.eql(500);
expect(json).to.eql({ error: 'server error (failed to remove token)' });
expect(this.admit._adapter.users.removeToken).to.have.been.called;
done();
}.bind(this);
this.admit.invalidate(this.req, this.res, null);
});

it('invalidates sessions', function(done) {
this.admit.invalidate(this.req, this.res, function() {
expect(this.res.setHeader).to.have.been.calledOnce;
expect(this.res.setHeader).to.have.been.calledWith('Authorization', 'Invalidated');
expect(this.req.auth.user).to.not.exist;
expect(this.req.auth.db.user).to.not.exist;;
expect(this.req.auth.token).to.not.exist;
expect(this.admit._adapter.users.removeToken).to.have.been.called;
done();
}.bind(this));

});
});
});

0 comments on commit 9995993

Please sign in to comment.