async'ify avatar and apppassword code
This commit is contained in:
62
src/test/apppasswords-test.js
Normal file
62
src/test/apppasswords-test.js
Normal file
@@ -0,0 +1,62 @@
|
||||
/* 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);
|
||||
});
|
||||
});
|
||||
36
src/test/blobs-test.js
Normal file
36
src/test/blobs-test.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/* global it:false */
|
||||
/* global describe:false */
|
||||
/* global before:false */
|
||||
/* global after:false */
|
||||
|
||||
'use strict';
|
||||
|
||||
const blobs = require('../blobs.js'),
|
||||
common = require('./common.js'),
|
||||
expect = require('expect.js');
|
||||
|
||||
describe('blobs', function () {
|
||||
const { setup, cleanup } = common;
|
||||
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
|
||||
it('can set value', async function () {
|
||||
await blobs.set('someid', Buffer.from('somevalue'));
|
||||
});
|
||||
it('can get the set value', async function () {
|
||||
const value = await blobs.get('someid');
|
||||
expect(value).to.eql(Buffer.from('somevalue'));
|
||||
});
|
||||
it('can update a value', async function () {
|
||||
await blobs.set('someid', Buffer.from('someothervalue'));
|
||||
});
|
||||
it('can get updated value', async function () {
|
||||
const value = await blobs.get('someid');
|
||||
expect(value).to.eql(Buffer.from('someothervalue'));
|
||||
});
|
||||
it('cannot get randome value', async function () {
|
||||
const value = await blobs.get('unknownid');
|
||||
expect(value).to.be(null);
|
||||
});
|
||||
});
|
||||
@@ -137,7 +137,13 @@ function setup(done) {
|
||||
settings.initCache,
|
||||
blobs.initSecrets,
|
||||
domains.add.bind(null, DOMAIN.domain, DOMAIN, AUDIT_SOURCE),
|
||||
users.createOwner.bind(null, ADMIN.username, ADMIN.password, ADMIN.email, ADMIN.displayName, AUDIT_SOURCE),
|
||||
function createOwner(done) {
|
||||
users.createOwner(ADMIN.username, ADMIN.password, ADMIN.email, ADMIN.displayName, AUDIT_SOURCE, function (error, result) {
|
||||
if (error) return done(error);
|
||||
ADMIN.id = result.id;
|
||||
done();
|
||||
});
|
||||
},
|
||||
appdb.add.bind(null, APP.id, APP.appStoreId, APP.manifest, APP.location, APP.domain, APP.portBindings, APP),
|
||||
settingsdb.set.bind(null, settings.CLOUDRON_TOKEN_KEY, exports.APPSTORE_TOKEN), // appstore token
|
||||
], done);
|
||||
|
||||
@@ -10,7 +10,6 @@ const appdb = require('../appdb.js'),
|
||||
async = require('async'),
|
||||
backupdb = require('../backupdb.js'),
|
||||
backups = require('../backups.js'),
|
||||
blobs = require('../blobs.js'),
|
||||
BoxError = require('../boxerror.js'),
|
||||
database = require('../database'),
|
||||
domaindb = require('../domaindb'),
|
||||
@@ -512,44 +511,6 @@ describe('database', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('appPasswords', function () {
|
||||
before(function (done) {
|
||||
userdb.add(USER_0.id, USER_0, done);
|
||||
});
|
||||
after(function (done) {
|
||||
userdb.del(USER_0.id, done);
|
||||
});
|
||||
|
||||
it('can add app password', function (done) {
|
||||
userdb.addAppPassword('someid', { userId: USER_0.id, hashedPassword: 'hash', name: 'spark', identifier: 'appid' }, done);
|
||||
});
|
||||
|
||||
it('can get app password', function (done) {
|
||||
userdb.getAppPassword('someid', function (error, result) {
|
||||
if (error) return done(error);
|
||||
expect(result.hashedPassword).to.be('hash');
|
||||
expect(result.name).to.be('spark');
|
||||
expect(result.identifier).to.be('appid');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can get app passwords', function (done) {
|
||||
userdb.getAppPasswords(USER_0.id, function (error, results) {
|
||||
if (error) return done(error);
|
||||
expect(results.length).to.be(1);
|
||||
expect(results[0].hashedPassword).to.be('hash');
|
||||
expect(results[0].name).to.be('spark');
|
||||
expect(results[0].identifier).to.be('appid');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can del app password', function (done) {
|
||||
userdb.delAppPassword('someid', done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('apps', function () {
|
||||
var APP_0 = {
|
||||
id: 'appid-0',
|
||||
@@ -1008,27 +969,6 @@ describe('database', function () {
|
||||
|
||||
});
|
||||
|
||||
describe('blobs', function () {
|
||||
it('can set value', async function () {
|
||||
await blobs.set('someid', Buffer.from('somevalue'));
|
||||
});
|
||||
it('can get the set value', async function () {
|
||||
const value = await blobs.get('someid');
|
||||
expect(value).to.eql(Buffer.from('somevalue'));
|
||||
});
|
||||
it('can update a value', async function () {
|
||||
await blobs.set('someid', Buffer.from('someothervalue'));
|
||||
});
|
||||
it('can get updated value', async function () {
|
||||
const value = await blobs.get('someid');
|
||||
expect(value).to.eql(Buffer.from('someothervalue'));
|
||||
});
|
||||
it('cannot get randome value', async function () {
|
||||
const value = await blobs.get('unknownid');
|
||||
expect(value).to.be(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('backup', function () {
|
||||
|
||||
it('add succeeds', function (done) {
|
||||
|
||||
Reference in New Issue
Block a user