roles -> role, null -> COMMENTER for user roles

This commit is contained in:
Wyatt Johnson
2017-11-27 11:53:40 -07:00
parent 9386912b9b
commit 13865ff29e
38 changed files with 206 additions and 199 deletions
+6 -6
View File
@@ -6,13 +6,13 @@ const authz = require('../../../middleware/authorization');
describe('middleware.authorization', () => {
describe('#has', () => {
it('allows if no roles are specified', () => {
expect(authz.has({roles: []})).to.be.true;
expect(authz.has({role: 'COMMENTER'})).to.be.true;
});
it('allows if the correct roles are met', () => {
expect(authz.has({roles: ['ADMIN']}, 'ADMIN', 'MODERATOR')).to.be.true;
expect(authz.has({role: 'ADMIN'}, 'ADMIN', 'MODERATOR')).to.be.true;
});
it('disallows if the role required is missing', () => {
expect(authz.has({roles: []}, 'ADMIN', 'MODERATOR')).to.be.false;
expect(authz.has({role: 'COMMENTER'}, 'ADMIN', 'MODERATOR')).to.be.false;
});
});
@@ -24,17 +24,17 @@ describe('middleware.authorization', () => {
};
it('allows if no roles are specified', () => {
needed()({user: {roles: []}}, {}, (err) => {
needed()({user: {role: 'COMMENTER'}}, {}, (err) => {
expect(err).to.be.undefined;
});
});
it('allows if the correct roles are met', () => {
needed()({user: {roles: ['ADMIN']}}, {}, (err) => {
needed()({user: {role: 'ADMIN'}}, {}, (err) => {
expect(err).to.be.undefined;
});
});
it('disallows if the role required is missing', () => {
needed('ADMIN', 'MODERATOR')({user: {roles: []}}, {}, (err) => {
needed('ADMIN', 'MODERATOR')({user: {role: 'COMMENTER'}}, {}, (err) => {
expect(err).to.not.be.undefined;
});
});