diff --git a/src/test/tokens-test.js b/src/test/tokens-test.js index f8fd2976c..dab470a2f 100644 --- a/src/test/tokens-test.js +++ b/src/test/tokens-test.js @@ -42,6 +42,27 @@ describe('Tokens', function () { expect(error.reason).to.be(BoxError.BAD_FIELD); }); + it('add fails with unknown scope', async function () { + const badToken = Object.assign({}, TOKEN_0); + badToken.scope = { 'foobar': 'rw', '*': 'r' }; + const [error] = await safe(tokens.add(badToken)); + expect(error.reason).to.be(BoxError.BAD_FIELD); + }); + + it('add fails with invalid scope rule', async function () { + const badToken = Object.assign({}, TOKEN_0); + badToken.scope = { '*': 'rw ' }; + const [error] = await safe(tokens.add(badToken)); + expect(error.reason).to.be(BoxError.BAD_FIELD); + }); + + it('add fails with bad name', async function () { + const badToken = Object.assign({}, TOKEN_0); + badToken.name = new Array(100).fill('x').join(''); + const [error] = await safe(tokens.add(badToken)); + expect(error.reason).to.be(BoxError.BAD_FIELD); + }); + it('get succeeds', async function () { const result = await tokens.get(TOKEN_0.id); expect(result).to.be.eql(TOKEN_0);