Make intersectScopes take an array

This commit is contained in:
Girish Ramakrishnan
2018-06-17 22:38:14 -07:00
parent 1015b0ad9c
commit 6a2dacb08a
3 changed files with 13 additions and 30 deletions

View File

@@ -20,7 +20,7 @@ exports = module.exports = {
validateScopeString: validateScopeString,
hasScopes: hasScopes,
intersectScope: intersectScope,
intersectScopes: intersectScopes,
canonicalScope: canonicalScope
};
@@ -34,17 +34,11 @@ function canonicalScope(scope) {
return scopes.join(',');
}
function intersectScope(allowedScope, wantedScope) {
assert.strictEqual(typeof allowedScope, 'string');
assert.strictEqual(typeof wantedScope, 'string');
function intersectScopes(allowedScopes, wantedScopes) {
assert(Array.isArray(allowedScopes), 'Expecting array');
assert(Array.isArray(wantedScopes), 'Expecting array');
const allowedScopes = allowedScope.split(',');
const wantedScopes = wantedScope.split(',');
if (allowedScopes.indexOf(exports.SCOPE_ANY) !== -1) return canonicalScope(wantedScope);
if (wantedScopes.indexOf(exports.SCOPE_ANY) !== -1) return canonicalScope(allowedScope);
return _.intersection(allowedScopes, wantedScopes).join(',');
return _.intersection(allowedScopes, wantedScopes);
}
function validateRoles(roles) {