63 lines
1.9 KiB
JavaScript
63 lines
1.9 KiB
JavaScript
|
|
/* jslint node:true */
|
||
|
|
/* global it:false */
|
||
|
|
/* global describe:false */
|
||
|
|
/* global before:false */
|
||
|
|
/* global after:false */
|
||
|
|
|
||
|
|
'use strict';
|
||
|
|
|
||
|
|
const appPasswords = require('../apppasswords.js'),
|
||
|
|
BoxError = require('../boxerror.js'),
|
||
|
|
common = require('./common.js'),
|
||
|
|
expect = require('expect.js'),
|
||
|
|
safe = require('safetydance');
|
||
|
|
|
||
|
|
describe('App passwords', function () {
|
||
|
|
const { setup, cleanup, ADMIN } = common;
|
||
|
|
|
||
|
|
before(setup);
|
||
|
|
after(cleanup);
|
||
|
|
|
||
|
|
let id;
|
||
|
|
it('cannot add bad app password', async function () {
|
||
|
|
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');
|
||
|
|
expect(result.id).to.be.a('string');
|
||
|
|
expect(result.password).to.be.a('string');
|
||
|
|
id = result.id;
|
||
|
|
});
|
||
|
|
|
||
|
|
it('can get app password', async function () {
|
||
|
|
const result = await appPasswords.get(id);
|
||
|
|
expect(result.hashedPassword).to.be.a('string');
|
||
|
|
expect(result.name).to.be('spark');
|
||
|
|
expect(result.identifier).to.be('appid');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('cannot get random app password', async function () {
|
||
|
|
const result = await appPasswords.get('random');
|
||
|
|
expect(result).to.be(null);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('can get app passwords', async function () {
|
||
|
|
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');
|
||
|
|
expect(results[0].identifier).to.be('appid');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('can del app password', async function () {
|
||
|
|
await appPasswords.del(id);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('cannot del random app password', async function () {
|
||
|
|
const [error] = await safe(appPasswords.del('random'));
|
||
|
|
expect(error.reason).to.be(BoxError.NOT_FOUND);
|
||
|
|
});
|
||
|
|
});
|