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

Commit

Permalink
Adds tests for the unprotected paths added
Browse files Browse the repository at this point in the history
  • Loading branch information
andela-thomas committed Apr 22, 2016
1 parent 28957c9 commit 65a35a0
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/nacl.unprotected.path.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
var assert = require('assert');
var acl = require('../');
var httpMocks = require('node-mocks-http');

describe('Acl middleware for express', function() {
var req, res, next;

describe('Policy based on action: "deny and methods glob "*"', function() {
beforeEach(function(done) {
acl.config({
baseUrl: 'api'
});
done();
});

it('should deny POST operation on /api/mangoes/42', function(done) {
req = httpMocks.createRequest({
method: 'POST',
url: '/api/oranges'
});

res = httpMocks.createResponse({
eventEmitter: require('events').EventEmitter
});

req.decoded = {};
req.session = {};

req.decoded.role = 'user';

next = function() {
res.send({
status: 200,
success: true,
message: 'ACCESS GRANTED'
});
};

acl
.authorize
.unless({
path: [
'/api/oranges'
]
})(req, res, next);

var data = res._getData();

assert(data, true);
assert(typeof data, 'object');
assert.deepEqual(data.status, 200);
assert.deepEqual(data.success, true);
assert.deepEqual(data.message, 'ACCESS GRANTED');

done();
});

});

});

0 comments on commit 65a35a0

Please sign in to comment.