Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/check_profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function checkProfiles (profiles, args, cb) {
var permissions = require('../config/permissions.js')();
var httpErr = {};
var extendedUserTypes = [];
var maxUserTypeDepth = 5; // TODO: this should be calculated
var maxUserTypeDepth = 6; // TODO: this should be calculated
var maxUserRoleDepth = 4; // TODO: this should be calculated
var user = args.user ? args.user : {roles: ['none']};

Expand Down
19 changes: 18 additions & 1 deletion test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var expect = require('code').expect;
var actForSimpleMinded = {role: 'cp-test', cmd: 'acting_as_normal'};
var actForAnybody = {role: 'cp-test', cmd: 'acting_as_free'};
var actForAdult = {role: 'cp-test', cmd: 'acting_as_adult'};
var actForChildren = {role: 'cp-test', cmd: 'acting_as_children'};
var actForPro = {role: 'cp-test', cmd: 'acting_as_pro'};
var actForSchyzo = {role: 'cp-test', cmd: 'acting_as_schyzo'};
var actForCrazy = {role: 'cp-test', cmd: 'acting_as_crazy'};
Expand Down Expand Up @@ -64,6 +65,14 @@ describe('cp-perms', function () {
done();
});
});

it('should allow the lowest user-type', function (done) {
seneca.act({role: 'cp-test', cmd: 'check_permissions', act: actForChildren.cmd, user: {roles: ['basic-user'], initUserType: ['attendee-o13'] }}, function (err, allowance) {
expect(allowance).to.be.deep.equal({allowed: true}).and.to.satisfy(isValidFormat);
done();
});
});


it('should allow basic-user', function (done) {
seneca.act({role: 'cp-test', cmd: 'check_permissions', act: actForSimpleMinded.cmd, user: {roles: ['basic-user']}}, function (err, allowance) {
Expand Down Expand Up @@ -184,13 +193,21 @@ describe('cp-perms', function () {

// TODO : test for missing conf
// Apart from seneca errors, like act not found, or config errors (missing conf)
it('should be not returning errors when userType does not exist', function (done) {
it('should be not returning errors when role does not exist', function (done) {
seneca.act({role: 'cp-test', cmd: 'check_permissions', act: actForSimpleMinded.cmd, user: {roles: ['basic-userqsd']}}, function (err, allowance) {
expect(allowance).to.satisfy(isValidFormat);
expect(allowance).to.be.deep.equal({allowed: {status: 403}});
done();
});
});

it('should be not returning errors when userType does not exist', function (done) {
seneca.act({role: 'cp-test', cmd: 'check_permissions', act: actForAdult.cmd, user: {initUserType: ['monster-munch']}}, function (err, allowance) {
expect(allowance).to.satisfy(isValidFormat);
expect(allowance).to.be.deep.equal({allowed: {status: 403}});
done();
});
});

it('should not be returning errors when passed params are in the wrong format', function (done) {
seneca.act({role: 'cp-test', cmd: 'check_permissions', act: actForSimpleMinded.cmd, user: {roles: 'basic-user'}}, function (err, allowance) {
Expand Down
5 changes: 5 additions & 0 deletions test/permissions-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ module.exports = function () {
userType: 'parent-guardian'
}
],
'acting_as_children': [
{
userType: 'attendee-o13'
},
],
'acting_as_pro': [
{
role: 'basic-user',
Expand Down
Loading