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
+3 -2
View File
@@ -23,14 +23,15 @@ describe('janitor', function () {
clientId: 'clientid-1',
expires: Number.MAX_SAFE_INTEGER,
lastUsedTime: null,
scope: 'unused'
scope: { '*': 'rw' }
};
const token2 = {
name: 'token2',
identifier: '2',
clientId: 'clientid-2',
expires: Date.now(),
lastUsedTime: null
lastUsedTime: null,
scope: null //{ '*': 'rw '}
};
it('can cleanupTokens', async function () {
+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;