This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds tests for the unprotected paths added
- Loading branch information
andela-thomas
committed
Apr 22, 2016
1 parent
28957c9
commit 65a35a0
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
|
||
}); | ||
|
||
}); |