@vonage/acl-express
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -120,3 +120,3 @@ const fs = require('fs'); | ||
*/ | ||
function findRule(rules, url, prefix) { | ||
function findRule(rules, url, method, prefix) { | ||
for (let rule of rules) { | ||
@@ -131,3 +131,3 @@ let route = rule.route; | ||
if (rule.subroutes && rule.route !== '*') { | ||
let res = findRule(rule.subroutes, url, route); | ||
let res = findRule(rule.subroutes, url, method, route); | ||
@@ -138,3 +138,3 @@ if (res) { | ||
} | ||
if (matchURL(url, route)) { | ||
if (matchURL(url, route) && checkRule(method, rule)) { | ||
return rule; | ||
@@ -151,4 +151,4 @@ } | ||
*/ | ||
function checkRule(req, rule) { | ||
if (rule.methods === '*' || rule.methods.indexOf(req.method) > -1) { | ||
function checkRule(method, rule) { | ||
if (rule.methods === '*' || rule.methods.indexOf(method) > -1) { | ||
if (rule.action === 'allow') { | ||
@@ -187,3 +187,3 @@ return true; | ||
if (rules) { | ||
rule = findRule(rules, url); | ||
rule = findRule(rules, url, req.method); | ||
debug(rule); | ||
@@ -199,7 +199,2 @@ } | ||
if (!checkRule(req, rule)) { | ||
next(new UnauthorizedError()); | ||
return; | ||
} | ||
next(); | ||
@@ -206,0 +201,0 @@ } |
{ | ||
"name": "@vonage/acl-express", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "An access control middleware for Express", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -77,8 +77,5 @@ const fs = require('fs'); | ||
next = sinon.spy(); | ||
}); | ||
beforeEach(function() { | ||
acl = require('../../lib'); | ||
acl.config({ | ||
path: 'test/resources/rules.json', | ||
path: 'test/resources/rules.json' | ||
}); | ||
@@ -85,0 +82,0 @@ }); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16007
402