Fixup some token tests and error handling

This commit is contained in:
Johannes Zellner
2022-09-24 17:29:42 +02:00
parent 70d3040135
commit 15d473d506
2 changed files with 7 additions and 5 deletions
+4 -3
View File
@@ -37,6 +37,7 @@ function postProcess(result) {
assert.strictEqual(typeof result, 'object');
result.scope = safe.JSON.parse(result.scopeJson) || {};
delete result.scopeJson;
return result;
}
@@ -53,7 +54,7 @@ function validateTokenType(type) {
assert.strictEqual(typeof type, 'string');
const types = [ exports.ID_WEBADMIN, exports.ID_SDK ];
if (types.indexOf(type) === -1) return BoxError(BoxError.BAD_FIELD, `type must be one of ${types.join(',')}`);
if (types.indexOf(type) === -1) return new BoxError(BoxError.BAD_FIELD, `type must be one of ${types.join(',')}`);
return null;
}
@@ -62,8 +63,8 @@ function validateScope(scope) {
assert.strictEqual(typeof scope, 'object');
for (const key in scope) {
if (exports.SCOPES.indexOf(key) === -1) return BoxError(BoxError.BAD_FIELD, `Unkown token scope ${key}. Valid scopes are ${exports.SCOPES.join(',')}`);
if (scope[key] !== 'rw' && scope[key] !== 'r') return BoxError(BoxError.BAD_FIELD, `Unkown token scope value ${scope[key]} for ${key}. Valid values are 'rw' or 'r'`);
if (exports.SCOPES.indexOf(key) === -1) return new BoxError(BoxError.BAD_FIELD, `Unkown token scope ${key}. Valid scopes are ${exports.SCOPES.join(',')}`);
if (scope[key] !== 'rw' && scope[key] !== 'r') return new BoxError(BoxError.BAD_FIELD, `Unkown token scope value ${scope[key]} for ${key}. Valid values are 'rw' or 'r'`);
}
return null;