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.
- remove uneccesary iffes - remove use of var and replace with const and let
- Loading branch information
Thomas Nyambati
committed
Nov 1, 2016
1 parent
f4cf179
commit ea7ef60
Showing
13 changed files
with
1,134 additions
and
1,176 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
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
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 |
---|---|---|
@@ -1,158 +1,155 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
var acl = require('../../'); | ||
var httpMocks = require('node-mocks-http'); | ||
|
||
describe('Acl middleware for express', function() { | ||
var req, res, next, data; | ||
var response = { | ||
success: { | ||
status: 200, | ||
success: true, | ||
message: 'ACCESS GRANTED' | ||
}, | ||
restricted: { | ||
status: 'Access denied', | ||
success: false, | ||
message: 'Unauthorized access' | ||
} | ||
}; | ||
|
||
describe('When the methods and resource is a glob', function() { | ||
'use strict'; | ||
const assert = require('assert'); | ||
const acl = require('../../'); | ||
const httpMocks = require('node-mocks-http'); | ||
|
||
describe('Acl middleware for express', function() { | ||
let req, res, next, data; | ||
let response = { | ||
success: { | ||
status: 200, | ||
success: true, | ||
message: 'ACCESS GRANTED' | ||
}, | ||
restricted: { | ||
status: 'Access denied', | ||
success: false, | ||
message: 'Unauthorized access' | ||
} | ||
}; | ||
|
||
describe('When the methods and resource is a glob', function() { | ||
beforeEach(function(done) { | ||
res = httpMocks.createResponse(); | ||
next = function() { | ||
res.send(response.success); | ||
}; | ||
done(); | ||
}); | ||
|
||
context('When action deny', function() { | ||
beforeEach(function(done) { | ||
res = httpMocks.createResponse(); | ||
next = function() { | ||
res.send(response.success); | ||
}; | ||
acl.config({ | ||
baseUrl: 'api', | ||
filename: 'all-glob-deny.json', | ||
path: './tests/config' | ||
}); | ||
done(); | ||
}); | ||
|
||
context('When action deny', function() { | ||
beforeEach(function(done) { | ||
acl.config({ | ||
baseUrl: 'api', | ||
filename: 'all-glob-deny.json', | ||
path: './tests/config' | ||
}); | ||
done(); | ||
it('Should deny access to resource /api/user/42', function(done) { | ||
req = httpMocks.createRequest({ | ||
method: 'POST', | ||
url: '/api/users/42' | ||
}); | ||
|
||
it('Should deny access to resource /api/user/42', function(done) { | ||
req = httpMocks.createRequest({ | ||
method: 'POST', | ||
url: '/api/users/42' | ||
}); | ||
|
||
req.decoded = {}; | ||
req.session = {}; | ||
req.decoded.role = 'user'; | ||
acl.authorize(req, res, next); | ||
data = res._getData(); | ||
assert(data, true); | ||
assert(typeof data, 'object'); | ||
assert.deepEqual(data, response.restricted); | ||
done(); | ||
}); | ||
req.decoded = {}; | ||
req.session = {}; | ||
req.decoded.role = 'user'; | ||
acl.authorize(req, res, next); | ||
data = res._getData(); | ||
assert(data, true); | ||
assert(typeof data, 'object'); | ||
assert.deepEqual(data, response.restricted); | ||
done(); | ||
}); | ||
|
||
|
||
it('Should deny access to resource /api/user/42', function(done) { | ||
req = httpMocks.createRequest({ | ||
method: 'PUT', | ||
url: '/api/users/42' | ||
}); | ||
it('Should deny access to resource /api/user/42', function(done) { | ||
req = httpMocks.createRequest({ | ||
method: 'PUT', | ||
url: '/api/users/42' | ||
}); | ||
|
||
req.decoded = {}; | ||
req.session = {}; | ||
req.decoded.role = 'user'; | ||
acl.authorize(req, res, next); | ||
data = res._getData(); | ||
assert(data, true); | ||
assert(typeof data, 'object'); | ||
assert.deepEqual(data, response.restricted); | ||
done(); | ||
req.decoded = {}; | ||
req.session = {}; | ||
req.decoded.role = 'user'; | ||
acl.authorize(req, res, next); | ||
data = res._getData(); | ||
assert(data, true); | ||
assert(typeof data, 'object'); | ||
assert.deepEqual(data, response.restricted); | ||
done(); | ||
|
||
}); | ||
}); | ||
|
||
it('Should deny access to resource on /api/user/42', function(done) { | ||
req = httpMocks.createRequest({ | ||
method: 'DElETE', | ||
url: '/api/users/42' | ||
}); | ||
|
||
req.decoded = {}; | ||
req.session = {}; | ||
req.decoded.role = 'user'; | ||
acl.authorize(req, res, next); | ||
data = res._getData(); | ||
assert(data, true); | ||
assert(typeof data, 'object'); | ||
assert.deepEqual(data, response.restricted); | ||
done(); | ||
it('Should deny access to resource on /api/user/42', function(done) { | ||
req = httpMocks.createRequest({ | ||
method: 'DElETE', | ||
url: '/api/users/42' | ||
}); | ||
|
||
req.decoded = {}; | ||
req.session = {}; | ||
req.decoded.role = 'user'; | ||
acl.authorize(req, res, next); | ||
data = res._getData(); | ||
assert(data, true); | ||
assert(typeof data, 'object'); | ||
assert.deepEqual(data, response.restricted); | ||
done(); | ||
}); | ||
}); | ||
|
||
context('When action allow', function() { | ||
beforeEach(function(done) { | ||
acl.config({ | ||
baseUrl: 'api', | ||
filename: 'all-glob-allow.json', | ||
path: './tests/config' | ||
}); | ||
done(); | ||
context('When action allow', function() { | ||
beforeEach(function(done) { | ||
acl.config({ | ||
baseUrl: 'api', | ||
filename: 'all-glob-allow.json', | ||
path: './tests/config' | ||
}); | ||
done(); | ||
}); | ||
|
||
it('Should Deny Access to resource /api/user/42', function(done) { | ||
req = httpMocks.createRequest({ | ||
method: 'POST', | ||
url: '/api/users/42' | ||
}); | ||
|
||
req.decoded = {}; | ||
req.session = {}; | ||
req.decoded.role = 'user'; | ||
acl.authorize(req, res, next); | ||
data = res._getData(); | ||
assert(data, true); | ||
assert.deepEqual(data, response.success); | ||
done(); | ||
it('Should Deny Access to resource /api/user/42', function(done) { | ||
req = httpMocks.createRequest({ | ||
method: 'POST', | ||
url: '/api/users/42' | ||
}); | ||
|
||
req.decoded = {}; | ||
req.session = {}; | ||
req.decoded.role = 'user'; | ||
acl.authorize(req, res, next); | ||
data = res._getData(); | ||
assert(data, true); | ||
assert.deepEqual(data, response.success); | ||
done(); | ||
}); | ||
|
||
|
||
it('Should deny access to resource /api/user/42', function(done) { | ||
req = httpMocks.createRequest({ | ||
method: 'PUT', | ||
url: '/api/users/42' | ||
}); | ||
|
||
req.decoded = {}; | ||
req.session = {}; | ||
req.decoded.role = 'user'; | ||
acl.authorize(req, res, next); | ||
data = res._getData(); | ||
assert(data, true); | ||
assert.deepEqual(data, response.success); | ||
done(); | ||
it('Should deny access to resource /api/user/42', function(done) { | ||
req = httpMocks.createRequest({ | ||
method: 'PUT', | ||
url: '/api/users/42' | ||
}); | ||
|
||
it('should deny DElETE operation on /api/user/42', function(done) { | ||
req = httpMocks.createRequest({ | ||
method: 'DElETE', | ||
url: '/api/users/42' | ||
}); | ||
|
||
req.decoded = {}; | ||
req.session = {}; | ||
req.decoded.role = 'user'; | ||
acl.authorize(req, res, next); | ||
data = res._getData(); | ||
assert(data, true); | ||
assert(data, true); | ||
assert.deepEqual(data, response.success); | ||
done(); | ||
req.decoded = {}; | ||
req.session = {}; | ||
req.decoded.role = 'user'; | ||
acl.authorize(req, res, next); | ||
data = res._getData(); | ||
assert(data, true); | ||
assert.deepEqual(data, response.success); | ||
done(); | ||
}); | ||
|
||
it('should deny DElETE operation on /api/user/42', function(done) { | ||
req = httpMocks.createRequest({ | ||
method: 'DElETE', | ||
url: '/api/users/42' | ||
}); | ||
|
||
req.decoded = {}; | ||
req.session = {}; | ||
req.decoded.role = 'user'; | ||
acl.authorize(req, res, next); | ||
data = res._getData(); | ||
assert(data, true); | ||
assert(data, true); | ||
assert.deepEqual(data, response.success); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
})(); | ||
}); |
Oops, something went wrong.