express-reaccess
Advanced tools
Comparing version 0.0.7 to 0.0.8
{ | ||
"name": "express-reaccess", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Express/Connect middleware to manage API access on a RegExp basis", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -131,2 +131,12 @@ # express-reaccess | ||
## Static methods | ||
`express-reaccess` comes with some convenience static methods to deal with `methods` | ||
properties. | ||
### [strings] : reaccess.methodsAsString(methods) | ||
Return an array of strings from the methods property of a right. | ||
### methods : reaccess.stringsToMethods(strings) | ||
Return the methods value of a right from an array of strings. | ||
## Static properties | ||
@@ -133,0 +143,0 @@ Reaccess use bitwise operators to match methods. The reaccess function provides |
@@ -100,2 +100,35 @@ var escRegExp = require('escape-regexp-component'); | ||
// Static methods | ||
reaccess.methodsAsStrings = function reaccessMethodsAsStrings(methods) { | ||
var strings = []; | ||
if(methods&reaccess.OPTIONS) { | ||
strings.push('OPTIONS'); | ||
} | ||
if(methods&reaccess.HEAD) { | ||
strings.push('HEAD'); | ||
} | ||
if(methods&reaccess.GET) { | ||
strings.push('GET'); | ||
} | ||
if(methods&reaccess.POST) { | ||
strings.push('POST'); | ||
} | ||
if(methods&reaccess.PUT) { | ||
strings.push('PUT'); | ||
} | ||
if(methods&reaccess.PATCH) { | ||
strings.push('PATCH'); | ||
} | ||
if(methods&reaccess.DELETE) { | ||
strings.push('DELETE'); | ||
} | ||
return strings; | ||
}; | ||
reaccess.stringsToMethods = function reaccessStringsToMethods(strings) { | ||
return strings.reduce(function(methods, str) { | ||
return methods | ('number' === typeof reaccess[str.toUpperCase()] ? | ||
reaccess[str.toUpperCase()] : 0); | ||
}, 0); | ||
}; | ||
// Helpers | ||
@@ -102,0 +135,0 @@ function getValues(values, path) { |
@@ -40,3 +40,3 @@ var assert = require('assert'); | ||
}) | ||
.expect(500, /Unauthorized access!/) | ||
.expect(500, 'Unauthorized access!') | ||
.end(function(err, res){ | ||
@@ -58,3 +58,3 @@ if(err) throw err; | ||
}) | ||
.expect(500, /Unauthorized access!/) | ||
.expect(500, 'Unauthorized access!') | ||
.end(function(err, res){ | ||
@@ -76,3 +76,3 @@ if(err) throw err; | ||
}) | ||
.expect(500, /Unauthorized access!/) | ||
.expect(500, 'Unauthorized access!') | ||
.end(function(err, res){ | ||
@@ -95,3 +95,3 @@ if(err) throw err; | ||
}, '/foo/') | ||
.expect(500, /Unauthorized access!/) | ||
.expect(500, 'Unauthorized access!') | ||
.end(function(err, res){ | ||
@@ -114,3 +114,3 @@ if(err) throw err; | ||
}, '/foo//') | ||
.expect(500, /Unauthorized access!/) | ||
.expect(500, 'Unauthorized access!') | ||
.end(function(err, res){ | ||
@@ -337,2 +337,66 @@ if(err) throw err; | ||
describe('reacesss.stringsToMethods', function() { | ||
it('should work with no strings', function() { | ||
assert.deepEqual( | ||
reaccess.stringsToMethods([]), | ||
0 | ||
); | ||
}); | ||
it('should work with one strings', function() { | ||
assert.deepEqual( | ||
reaccess.stringsToMethods(['PUT']), | ||
16 | ||
); | ||
}); | ||
it('should work with some strings', function() { | ||
assert.deepEqual( | ||
reaccess.stringsToMethods(['OPTIONS', 'PATCH']), | ||
33 | ||
); | ||
}); | ||
it('should work with every strings', function() { | ||
assert.deepEqual( | ||
reaccess.stringsToMethods(['OPTIONS', 'HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE']), | ||
127 | ||
); | ||
}); | ||
}); | ||
describe('reacesss.methodsAsStrings', function() { | ||
it('should work with no strings', function() { | ||
assert.deepEqual( | ||
reaccess.methodsAsStrings(0), | ||
[] | ||
); | ||
}); | ||
it('should work with one strings', function() { | ||
assert.deepEqual( | ||
reaccess.methodsAsStrings(16), | ||
['PUT'] | ||
); | ||
}); | ||
it('should work with some strings', function() { | ||
assert.deepEqual( | ||
reaccess.methodsAsStrings(33), | ||
['OPTIONS', 'PATCH'] | ||
); | ||
}); | ||
it('should work with every strings', function() { | ||
assert.deepEqual( | ||
reaccess.methodsAsStrings(127), | ||
['OPTIONS', 'HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'] | ||
); | ||
}); | ||
}); | ||
describe('reacesss for SimpliField should work', function() { | ||
@@ -339,0 +403,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
24140
587
228