tests: cleanup common variables

This commit is contained in:
Girish Ramakrishnan
2021-08-13 10:41:10 -07:00
parent aa981da43b
commit a8760f6c2c
20 changed files with 393 additions and 404 deletions
+9 -9
View File
@@ -14,19 +14,19 @@ const appPasswords = require('../apppasswords.js'),
users = require('../users.js');
describe('App passwords', function () {
const { setup, cleanup, ADMIN } = common;
const { setup, cleanup, admin } = common;
before(setup);
after(cleanup);
let id, password;
it('cannot add bad app password', async function () {
const [error] = await safe(appPasswords.add(ADMIN.id, 'appid', 'x'.repeat(201)));
const [error] = await safe(appPasswords.add(admin.id, 'appid', 'x'.repeat(201)));
expect(error.reason).to.be(BoxError.BAD_FIELD);
});
it('can add app password', async function () {
const result = await appPasswords.add(ADMIN.id, 'appid', 'spark');
const result = await appPasswords.add(admin.id, 'appid', 'spark');
expect(result.id).to.be.a('string');
expect(result.password).to.be.a('string');
id = result.id;
@@ -46,7 +46,7 @@ describe('App passwords', function () {
});
it('can get app passwords', async function () {
const results = await appPasswords.list(ADMIN.id);
const results = await appPasswords.list(admin.id);
expect(results.length).to.be(1);
expect(results[0].hashedPassword).to.be.a('string');
expect(results[0].name).to.be('spark');
@@ -54,25 +54,25 @@ describe('App passwords', function () {
});
it('can verify app password', async function () {
const result = await users.verify(ADMIN.id, password, 'appid');
const result = await users.verify(admin.id, password, 'appid');
expect(result).to.be.ok();
expect(result.appPassword).to.be(true);
});
it('can verify non-app password', async function () {
const result = await users.verify(ADMIN.id, ADMIN.password, 'appid');
const result = await users.verify(admin.id, admin.password, 'appid');
expect(result).to.be.ok();
expect(result.appPassword).to.be(undefined);
});
it('cannot verify bad password', async function () {
const [error, result] = await safe(users.verify(ADMIN.id, 'bad', 'appid'));
const [error, result] = await safe(users.verify(admin.id, 'bad', 'appid'));
expect(result).to.not.be.ok();
expect(error.reason).to.be(BoxError.INVALID_CREDENTIALS);
});
it('cannot verify password for another app', async function () {
const [error, result] = await safe(users.verify(ADMIN.id, password, 'appid2'));
const [error, result] = await safe(users.verify(admin.id, password, 'appid2'));
expect(result).to.not.be.ok();
expect(error.reason).to.be(BoxError.INVALID_CREDENTIALS);
});
@@ -82,7 +82,7 @@ describe('App passwords', function () {
});
it('cannot verify deleted app password', async function () {
const [error] = await safe(users.verify(ADMIN.id, password, 'appid'));
const [error] = await safe(users.verify(admin.id, password, 'appid'));
expect(error.reason).to.be(BoxError.INVALID_CREDENTIALS);
});