2015-07-20 00:09:47 -07:00
|
|
|
/* global it:false */
|
|
|
|
|
/* global describe:false */
|
|
|
|
|
/* global before:false */
|
|
|
|
|
/* global after:false */
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var appdb = require('../appdb.js'),
|
|
|
|
|
apps = require('../apps.js'),
|
|
|
|
|
AppsError = apps.AppsError,
|
|
|
|
|
async = require('async'),
|
|
|
|
|
config = require('../config.js'),
|
|
|
|
|
database = require('../database.js'),
|
2018-01-26 20:36:27 +01:00
|
|
|
domains = require('../domains.js'),
|
2016-02-25 11:28:45 +01:00
|
|
|
expect = require('expect.js'),
|
2016-09-30 12:09:33 -07:00
|
|
|
groupdb = require('../groupdb.js'),
|
2016-02-25 11:28:45 +01:00
|
|
|
groups = require('../groups.js'),
|
2018-06-11 12:38:15 -07:00
|
|
|
hat = require('../hat.js'),
|
2016-10-13 15:04:12 -07:00
|
|
|
settings = require('../settings.js'),
|
|
|
|
|
settingsdb = require('../settingsdb.js'),
|
2016-02-25 11:28:45 +01:00
|
|
|
userdb = require('../userdb.js');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
describe('Apps', function () {
|
2016-02-25 11:28:45 +01:00
|
|
|
var ADMIN_0 = {
|
|
|
|
|
id: 'admin123',
|
|
|
|
|
username: 'admin123',
|
|
|
|
|
password: 'secret',
|
|
|
|
|
email: 'admin@me.com',
|
2018-01-22 11:52:58 +01:00
|
|
|
fallbackEmail: 'admin@me.com',
|
2016-02-25 11:28:45 +01:00
|
|
|
salt: 'morton',
|
|
|
|
|
createdAt: 'sometime back',
|
|
|
|
|
modifiedAt: 'now',
|
|
|
|
|
resetToken: hat(256),
|
2018-07-26 11:15:57 -07:00
|
|
|
displayName: '',
|
2018-07-26 17:17:52 -07:00
|
|
|
groupIds: [],
|
|
|
|
|
admin: true
|
2016-02-25 11:28:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var USER_0 = {
|
|
|
|
|
id: 'uuid213',
|
|
|
|
|
username: 'uuid213',
|
|
|
|
|
password: 'secret',
|
|
|
|
|
email: 'safe@me.com',
|
2018-01-22 11:52:58 +01:00
|
|
|
fallbackEmail: 'safe@me.com',
|
2016-02-25 11:28:45 +01:00
|
|
|
salt: 'morton',
|
|
|
|
|
createdAt: 'sometime back',
|
|
|
|
|
modifiedAt: 'now',
|
|
|
|
|
resetToken: hat(256),
|
2018-07-26 11:15:57 -07:00
|
|
|
displayName: '',
|
2018-07-26 17:17:52 -07:00
|
|
|
groupIds: [],
|
|
|
|
|
admin: false
|
2016-02-25 11:28:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var USER_1 = {
|
|
|
|
|
id: 'uuid2134',
|
|
|
|
|
username: 'uuid2134',
|
|
|
|
|
password: 'secret',
|
|
|
|
|
email: 'safe1@me.com',
|
2018-01-22 11:52:58 +01:00
|
|
|
fallbackEmail: 'safe1@me.com',
|
2016-02-25 11:28:45 +01:00
|
|
|
salt: 'morton',
|
|
|
|
|
createdAt: 'sometime back',
|
|
|
|
|
modifiedAt: 'now',
|
|
|
|
|
resetToken: hat(256),
|
2018-07-26 11:15:57 -07:00
|
|
|
displayName: '',
|
2018-07-26 17:17:52 -07:00
|
|
|
groupIds: [ 'somegroup' ],
|
|
|
|
|
admin: false
|
2016-02-25 11:28:45 +01:00
|
|
|
};
|
|
|
|
|
|
2016-09-30 12:09:33 -07:00
|
|
|
var GROUP_0 = {
|
|
|
|
|
id: 'somegroup',
|
|
|
|
|
name: 'group0'
|
|
|
|
|
};
|
|
|
|
|
var GROUP_1 = {
|
|
|
|
|
id: 'anothergroup',
|
|
|
|
|
name: 'group1'
|
|
|
|
|
};
|
2016-02-25 11:28:45 +01:00
|
|
|
|
2017-11-11 01:34:20 +01:00
|
|
|
const DOMAIN_0 = {
|
|
|
|
|
domain: 'example.com',
|
|
|
|
|
zoneName: 'example.com',
|
2018-01-09 14:46:38 -08:00
|
|
|
provider: 'manual',
|
2018-01-31 18:09:38 +01:00
|
|
|
config: { },
|
|
|
|
|
tlsConfig: { provider: 'fallback' }
|
2017-11-11 01:34:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const DOMAIN_1 = {
|
|
|
|
|
domain: 'example2.com',
|
|
|
|
|
zoneName: 'example2.com',
|
2018-01-09 14:46:38 -08:00
|
|
|
provider: 'manual',
|
2018-01-31 18:09:38 +01:00
|
|
|
config: { },
|
|
|
|
|
tlsConfig: { provider: 'fallback' }
|
2017-11-11 01:34:20 +01:00
|
|
|
};
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
var APP_0 = {
|
|
|
|
|
id: 'appid-0',
|
|
|
|
|
appStoreId: 'appStoreId-0',
|
|
|
|
|
location: 'some-location-0',
|
2017-11-11 01:34:20 +01:00
|
|
|
domain: DOMAIN_0.domain,
|
2015-07-20 00:09:47 -07:00
|
|
|
manifest: {
|
|
|
|
|
version: '0.1', dockerImage: 'docker/app0', healthCheckPath: '/', httpPort: 80, title: 'app0',
|
|
|
|
|
tcpPorts: {
|
|
|
|
|
PORT: {
|
|
|
|
|
description: 'this is a port that i expose',
|
|
|
|
|
containerPort: '1234'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
portBindings: { PORT: 5678 },
|
2015-10-16 15:35:14 +02:00
|
|
|
accessRestriction: null,
|
2018-05-22 13:22:45 -07:00
|
|
|
memoryLimit: 0,
|
|
|
|
|
robotsTxt: null,
|
2018-05-13 21:02:57 -07:00
|
|
|
sso: false,
|
|
|
|
|
ownerId: USER_0.id
|
2015-07-20 00:09:47 -07:00
|
|
|
};
|
|
|
|
|
|
2016-02-25 11:28:45 +01:00
|
|
|
var APP_1 = {
|
|
|
|
|
id: 'appid-1',
|
|
|
|
|
appStoreId: 'appStoreId-1',
|
|
|
|
|
location: 'some-location-1',
|
2017-11-11 01:34:20 +01:00
|
|
|
domain: DOMAIN_0.domain,
|
2016-02-25 11:28:45 +01:00
|
|
|
manifest: {
|
|
|
|
|
version: '0.1', dockerImage: 'docker/app1', healthCheckPath: '/', httpPort: 80, title: 'app1',
|
|
|
|
|
tcpPorts: {}
|
|
|
|
|
},
|
2018-05-22 13:22:45 -07:00
|
|
|
portBindings: {},
|
2016-09-30 12:09:33 -07:00
|
|
|
accessRestriction: { users: [ 'someuser' ], groups: [ GROUP_0.id ] },
|
2018-05-13 21:02:57 -07:00
|
|
|
memoryLimit: 0,
|
|
|
|
|
ownerId: USER_0.id
|
2016-02-25 11:28:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var APP_2 = {
|
|
|
|
|
id: 'appid-2',
|
|
|
|
|
appStoreId: 'appStoreId-2',
|
|
|
|
|
location: 'some-location-2',
|
2017-11-11 01:34:20 +01:00
|
|
|
domain: DOMAIN_1.domain,
|
2016-02-25 11:28:45 +01:00
|
|
|
manifest: {
|
|
|
|
|
version: '0.1', dockerImage: 'docker/app2', healthCheckPath: '/', httpPort: 80, title: 'app2',
|
|
|
|
|
tcpPorts: {}
|
|
|
|
|
},
|
2018-05-22 13:22:45 -07:00
|
|
|
portBindings: {},
|
2016-09-30 12:09:33 -07:00
|
|
|
accessRestriction: { users: [ 'someuser', USER_0.id ], groups: [ GROUP_1.id ] },
|
2018-05-22 13:22:45 -07:00
|
|
|
memoryLimit: 0,
|
|
|
|
|
robotsTxt: null,
|
2018-05-13 21:02:57 -07:00
|
|
|
sso: false,
|
|
|
|
|
ownerId: USER_0.id
|
2016-02-25 11:28:45 +01:00
|
|
|
};
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
before(function (done) {
|
2017-11-27 15:27:54 -08:00
|
|
|
config._reset();
|
|
|
|
|
|
2017-11-11 03:06:57 +01:00
|
|
|
config.setFqdn(DOMAIN_0.domain);
|
2018-01-10 20:40:15 -08:00
|
|
|
config.setAdminFqdn('my.' + DOMAIN_0.domain);
|
2017-02-06 22:18:20 -08:00
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
async.series([
|
|
|
|
|
database.initialize,
|
|
|
|
|
database._clear,
|
2018-01-31 18:09:38 +01:00
|
|
|
domains.add.bind(null, DOMAIN_0.domain, DOMAIN_0.zoneName, DOMAIN_0.provider, DOMAIN_0.config, null, DOMAIN_0.tlsConfig),
|
|
|
|
|
domains.add.bind(null, DOMAIN_1.domain, DOMAIN_1.zoneName, DOMAIN_1.provider, DOMAIN_1.config, null, DOMAIN_1.tlsConfig),
|
2016-02-25 11:28:45 +01:00
|
|
|
userdb.add.bind(null, ADMIN_0.id, ADMIN_0),
|
|
|
|
|
userdb.add.bind(null, USER_0.id, USER_0),
|
|
|
|
|
userdb.add.bind(null, USER_1.id, USER_1),
|
2018-07-26 10:20:19 -07:00
|
|
|
groupdb.add.bind(null, GROUP_0.id, GROUP_0.name),
|
|
|
|
|
groupdb.add.bind(null, GROUP_1.id, GROUP_1.name),
|
2016-09-30 12:09:33 -07:00
|
|
|
groups.addMember.bind(null, GROUP_0.id, USER_1.id),
|
2018-08-12 19:33:11 -07:00
|
|
|
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.ownerId, apps._translatePortBindings(APP_0.portBindings), APP_0),
|
|
|
|
|
appdb.add.bind(null, APP_1.id, APP_1.appStoreId, APP_1.manifest, APP_1.location, APP_1.domain, APP_1.ownerId, apps._translatePortBindings(APP_1.portBindings), APP_1),
|
|
|
|
|
appdb.add.bind(null, APP_2.id, APP_2.appStoreId, APP_2.manifest, APP_2.location, APP_2.domain, APP_2.ownerId, apps._translatePortBindings(APP_2.portBindings), APP_2),
|
2016-10-13 15:04:12 -07:00
|
|
|
settingsdb.set.bind(null, settings.BACKUP_CONFIG_KEY, JSON.stringify({ provider: 'caas', token: 'BACKUP_TOKEN', bucket: 'Bucket', prefix: 'Prefix' }))
|
2015-07-20 00:09:47 -07:00
|
|
|
], done);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
after(function (done) {
|
2017-11-27 11:48:36 -08:00
|
|
|
async.series([
|
|
|
|
|
database._clear,
|
|
|
|
|
database.uninitialize
|
|
|
|
|
], done);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('validateHostname', function () {
|
|
|
|
|
it('does not allow admin subdomain', function () {
|
2018-01-10 20:40:15 -08:00
|
|
|
expect(apps._validateHostname('my', DOMAIN_0.domain, 'my.' + DOMAIN_0.domain)).to.be.an(Error);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot have >63 length subdomains', function () {
|
2018-08-04 09:23:30 -07:00
|
|
|
var s = Array(64).fill('s').join('');
|
2018-01-09 21:03:59 -08:00
|
|
|
expect(apps._validateHostname(s, 'example.com', s + '.example.com')).to.be.an(Error);
|
2018-08-04 09:23:30 -07:00
|
|
|
expect(apps._validateHostname(`dev.${s}`, 'example.com', `dev.${s}.example.com`)).to.be.an(Error);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('allows only alphanumerics and hypen', function () {
|
2018-01-09 21:03:59 -08:00
|
|
|
expect(apps._validateHostname('#2r', 'example.com', '#2r.example.com')).to.be.an(Error);
|
|
|
|
|
expect(apps._validateHostname('a%b', 'example.com', 'a%b.example.com')).to.be.an(Error);
|
|
|
|
|
expect(apps._validateHostname('ab_', 'example.com', 'ab_.example.com')).to.be.an(Error);
|
2018-08-04 09:23:30 -07:00
|
|
|
expect(apps._validateHostname('ab.', 'example.com', 'ab.example.com')).to.be.an(Error);
|
|
|
|
|
expect(apps._validateHostname('ab..c', 'example.com', 'ab..c.example.com')).to.be.an(Error);
|
|
|
|
|
expect(apps._validateHostname('.ab', 'example.com', '.ab.example.com')).to.be.an(Error);
|
2018-01-09 21:03:59 -08:00
|
|
|
expect(apps._validateHostname('-ab', 'example.com', '-ab.example.com')).to.be.an(Error);
|
|
|
|
|
expect(apps._validateHostname('ab-', 'example.com', 'ab-.example.com')).to.be.an(Error);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('total length cannot exceed 255', function () {
|
|
|
|
|
var s = '';
|
2017-11-11 01:34:20 +01:00
|
|
|
for (var i = 0; i < (255 - 'example.com'.length); i++) s += 's';
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2018-01-09 21:03:59 -08:00
|
|
|
expect(apps._validateHostname(s, 'example.com', s + '.example.com')).to.be.an(Error);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('allow valid domains', function () {
|
2018-01-09 21:03:59 -08:00
|
|
|
expect(apps._validateHostname('a', 'example.com', 'a.example.com')).to.be(null);
|
|
|
|
|
expect(apps._validateHostname('a0-x', 'example.com', 'a0-x.example.com')).to.be(null);
|
2018-08-04 09:23:30 -07:00
|
|
|
expect(apps._validateHostname('a0.x', 'example.com', 'a0-x.example.com')).to.be(null);
|
|
|
|
|
expect(apps._validateHostname('a0.x.y', 'example.com', 'a0.x.y.example.com')).to.be(null);
|
2018-01-09 21:03:59 -08:00
|
|
|
expect(apps._validateHostname('01', 'example.com', '01.example.com')).to.be(null);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('validatePortBindings', function () {
|
|
|
|
|
it('does not allow invalid host port', function () {
|
2017-01-29 13:01:09 -08:00
|
|
|
expect(apps._validatePortBindings({ port: -1 }, { port: 5000 })).to.be.an(Error);
|
|
|
|
|
expect(apps._validatePortBindings({ port: 0 }, { port: 5000 })).to.be.an(Error);
|
|
|
|
|
expect(apps._validatePortBindings({ port: 'text' }, { port: 5000 })).to.be.an(Error);
|
|
|
|
|
expect(apps._validatePortBindings({ port: 65536 }, { port: 5000 })).to.be.an(Error);
|
|
|
|
|
expect(apps._validatePortBindings({ port: 470 }, { port: 5000 })).to.be.an(Error);
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('does not allow ports not as part of manifest', function () {
|
2017-01-29 13:01:09 -08:00
|
|
|
expect(apps._validatePortBindings({ port: 1567 }, { })).to.be.an(Error);
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(apps._validatePortBindings({ port: 1567 }, { port3: null })).to.be.an(Error);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('allows valid bindings', function () {
|
2017-01-29 13:01:09 -08:00
|
|
|
expect(apps._validatePortBindings({ port: 1024 }, { port: 5000 })).to.be(null);
|
|
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(apps._validatePortBindings({
|
|
|
|
|
port1: 4033,
|
|
|
|
|
port2: 3242,
|
|
|
|
|
port3: 1234
|
|
|
|
|
}, { port1: null, port2: null, port3: null })).to.be(null);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getters', function () {
|
|
|
|
|
it('cannot get invalid app', function (done) {
|
2018-01-21 00:06:08 -08:00
|
|
|
apps.get('nope', function (error) {
|
2015-07-20 00:09:47 -07:00
|
|
|
expect(error).to.be.ok();
|
|
|
|
|
expect(error.reason).to.be(AppsError.NOT_FOUND);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can get valid app', function (done) {
|
|
|
|
|
apps.get(APP_0.id, function (error, app) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(app).to.be.ok();
|
|
|
|
|
expect(app.iconUrl).to.be(null);
|
2018-01-24 14:58:37 -08:00
|
|
|
expect(app.fqdn).to.eql(APP_0.location + '.' + DOMAIN_0.domain);
|
2016-02-05 15:51:01 +01:00
|
|
|
expect(app.memoryLimit).to.eql(0);
|
2015-07-20 00:09:47 -07:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can getAll', function (done) {
|
|
|
|
|
apps.getAll(function (error, apps) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(apps).to.be.an(Array);
|
|
|
|
|
expect(apps[0].id).to.be(APP_0.id);
|
|
|
|
|
expect(apps[0].iconUrl).to.be(null);
|
2018-01-24 14:58:37 -08:00
|
|
|
expect(apps[0].fqdn).to.eql(APP_0.location + '.' + DOMAIN_0.domain);
|
2015-07-20 00:09:47 -07:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-10-15 12:26:48 +02:00
|
|
|
|
|
|
|
|
describe('validateAccessRestriction', function () {
|
2015-10-16 15:35:14 +02:00
|
|
|
it('allows null input', function () {
|
|
|
|
|
expect(apps._validateAccessRestriction(null)).to.eql(null);
|
2015-10-15 12:26:48 +02:00
|
|
|
});
|
|
|
|
|
|
2015-10-16 15:35:14 +02:00
|
|
|
it('does not allow wrong user type', function () {
|
|
|
|
|
expect(apps._validateAccessRestriction({ users: {} })).to.be.an(Error);
|
2015-10-15 12:26:48 +02:00
|
|
|
});
|
|
|
|
|
|
2016-09-07 08:46:36 -07:00
|
|
|
it('allows user input', function () {
|
|
|
|
|
expect(apps._validateAccessRestriction({ users: [] })).to.eql(null);
|
2015-10-15 12:26:48 +02:00
|
|
|
});
|
|
|
|
|
|
2015-10-16 15:35:14 +02:00
|
|
|
it('allows single user input', function () {
|
|
|
|
|
expect(apps._validateAccessRestriction({ users: [ 'someuserid' ] })).to.eql(null);
|
2015-10-15 12:26:48 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('allows multi user input', function () {
|
2015-10-16 15:35:14 +02:00
|
|
|
expect(apps._validateAccessRestriction({ users: [ 'someuserid', 'someuserid1', 'someuserid2', 'someuserid3' ] })).to.eql(null);
|
2015-10-15 12:26:48 +02:00
|
|
|
});
|
|
|
|
|
});
|
2015-10-15 15:06:34 +02:00
|
|
|
|
|
|
|
|
describe('hasAccessTo', function () {
|
2018-07-26 17:17:52 -07:00
|
|
|
const someuser = { id: 'someuser', groupIds: [], admin: false };
|
|
|
|
|
const adminuser = { id: 'adminuser', groupIds: [ 'groupie' ], admin: true };
|
2018-07-26 11:15:57 -07:00
|
|
|
|
2016-02-09 12:48:21 -08:00
|
|
|
it('returns true for unrestricted access', function (done) {
|
2018-07-26 11:15:57 -07:00
|
|
|
apps.hasAccessTo({ accessRestriction: null }, someuser, function (error, access) {
|
2016-02-09 12:48:21 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(access).to.be(true);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-10-15 15:06:34 +02:00
|
|
|
});
|
|
|
|
|
|
2016-02-09 12:48:21 -08:00
|
|
|
it('returns true for allowed user', function (done) {
|
2018-07-26 11:15:57 -07:00
|
|
|
apps.hasAccessTo({ accessRestriction: { users: [ 'someuser' ] } }, someuser, function (error, access) {
|
2016-02-09 12:48:21 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(access).to.be(true);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-10-15 15:06:34 +02:00
|
|
|
});
|
|
|
|
|
|
2016-02-09 12:48:21 -08:00
|
|
|
it('returns true for allowed user with multiple allowed', function (done) {
|
2018-07-26 11:15:57 -07:00
|
|
|
apps.hasAccessTo({ accessRestriction: { users: [ 'foo', 'someuser', 'anotheruser' ] } }, someuser, function (error, access) {
|
2016-02-09 12:48:21 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(access).to.be(true);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-10-15 15:06:34 +02:00
|
|
|
});
|
|
|
|
|
|
2016-02-09 12:48:21 -08:00
|
|
|
it('returns false for not allowed user', function (done) {
|
2018-07-26 11:15:57 -07:00
|
|
|
apps.hasAccessTo({ accessRestriction: { users: [ 'foo' ] } }, someuser, function (error, access) {
|
2016-02-09 12:48:21 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(access).to.be(false);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-10-15 15:06:34 +02:00
|
|
|
});
|
|
|
|
|
|
2016-02-09 12:48:21 -08:00
|
|
|
it('returns false for not allowed user with multiple allowed', function (done) {
|
2018-07-26 11:15:57 -07:00
|
|
|
apps.hasAccessTo({ accessRestriction: { users: [ 'foo', 'anotheruser' ] } }, someuser, function (error, access) {
|
2016-02-09 12:48:21 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(access).to.be(false);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-10-15 15:06:34 +02:00
|
|
|
});
|
2016-02-09 16:52:54 -08:00
|
|
|
|
|
|
|
|
it('returns false for no group or user', function (done) {
|
2018-07-26 11:15:57 -07:00
|
|
|
apps.hasAccessTo({ accessRestriction: { users: [ ], groups: [ ] } }, someuser, function (error, access) {
|
2016-02-09 16:52:54 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(access).to.be(false);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('returns false for invalid group or user', function (done) {
|
2018-07-26 11:15:57 -07:00
|
|
|
apps.hasAccessTo({ accessRestriction: { users: [ ], groups: [ 'nop' ] } }, someuser, function (error, access) {
|
2016-02-09 16:52:54 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(access).to.be(false);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-07-26 11:15:57 -07:00
|
|
|
|
|
|
|
|
it('returns true for admin user', function (done) {
|
|
|
|
|
apps.hasAccessTo({ accessRestriction: { users: [ ], groups: [ 'nop' ] } }, adminuser, function (error, access) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(access).to.be(true);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-02-25 11:28:45 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('getAllByUser', function () {
|
|
|
|
|
it('succeeds for USER_0', function (done) {
|
|
|
|
|
apps.getAllByUser(USER_0, function (error, result) {
|
|
|
|
|
expect(error).to.equal(null);
|
|
|
|
|
expect(result.length).to.equal(2);
|
|
|
|
|
expect(result[0].id).to.equal(APP_0.id);
|
|
|
|
|
expect(result[1].id).to.equal(APP_2.id);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2016-02-09 16:52:54 -08:00
|
|
|
|
2016-02-25 11:28:45 +01:00
|
|
|
it('succeeds for USER_1', function (done) {
|
|
|
|
|
apps.getAllByUser(USER_1, function (error, result) {
|
|
|
|
|
expect(error).to.equal(null);
|
2016-02-25 11:41:09 +01:00
|
|
|
expect(result.length).to.equal(2);
|
2016-02-25 11:28:45 +01:00
|
|
|
expect(result[0].id).to.equal(APP_0.id);
|
2016-02-25 11:41:09 +01:00
|
|
|
expect(result[1].id).to.equal(APP_1.id);
|
2016-02-25 11:28:45 +01:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-11-15 18:07:10 -08:00
|
|
|
it('returns all apps for admin', function (done) {
|
2016-02-25 11:28:45 +01:00
|
|
|
apps.getAllByUser(ADMIN_0, function (error, result) {
|
|
|
|
|
expect(error).to.equal(null);
|
2017-11-15 18:07:10 -08:00
|
|
|
expect(result.length).to.equal(3);
|
2016-02-25 11:28:45 +01:00
|
|
|
expect(result[0].id).to.equal(APP_0.id);
|
2017-11-15 18:07:10 -08:00
|
|
|
expect(result[1].id).to.equal(APP_1.id);
|
|
|
|
|
expect(result[2].id).to.equal(APP_2.id);
|
2016-02-25 11:28:45 +01:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-10-15 15:06:34 +02:00
|
|
|
});
|
2016-05-24 10:33:10 -07:00
|
|
|
|
|
|
|
|
describe('configureInstalledApps', function () {
|
|
|
|
|
before(function (done) {
|
|
|
|
|
async.series([
|
|
|
|
|
appdb.update.bind(null, APP_0.id, { installationState: appdb.ISTATE_INSTALLED }),
|
|
|
|
|
appdb.update.bind(null, APP_1.id, { installationState: appdb.ISTATE_ERROR }),
|
|
|
|
|
appdb.update.bind(null, APP_2.id, { installationState: appdb.ISTATE_INSTALLED })
|
|
|
|
|
], done);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can mark apps for reconfigure', function (done) {
|
|
|
|
|
apps.configureInstalledApps(function (error) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
|
|
|
|
|
apps.getAll(function (error, apps) {
|
|
|
|
|
expect(apps[0].installationState).to.be(appdb.ISTATE_PENDING_CONFIGURE);
|
|
|
|
|
expect(apps[0].oldConfig).to.be(null);
|
2016-06-20 15:07:55 -05:00
|
|
|
expect(apps[1].installationState).to.be(appdb.ISTATE_PENDING_CONFIGURE); // erorred app can be reconfigured after restore
|
|
|
|
|
expect(apps[1].oldConfig).to.be(null);
|
2016-05-24 10:33:10 -07:00
|
|
|
expect(apps[2].installationState).to.be(appdb.ISTATE_PENDING_CONFIGURE);
|
|
|
|
|
expect(apps[2].oldConfig).to.be(null);
|
|
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('restoreInstalledApps', function () {
|
|
|
|
|
before(function (done) {
|
|
|
|
|
async.series([
|
|
|
|
|
appdb.update.bind(null, APP_0.id, { installationState: appdb.ISTATE_INSTALLED }),
|
|
|
|
|
appdb.update.bind(null, APP_1.id, { installationState: appdb.ISTATE_ERROR }),
|
|
|
|
|
appdb.update.bind(null, APP_2.id, { installationState: appdb.ISTATE_INSTALLED })
|
|
|
|
|
], done);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can mark apps for reconfigure', function (done) {
|
|
|
|
|
apps.restoreInstalledApps(function (error) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
|
2018-05-22 13:22:45 -07:00
|
|
|
apps.getAll(function (error, result) {
|
|
|
|
|
expect(result[0].installationState).to.be(appdb.ISTATE_PENDING_RESTORE);
|
|
|
|
|
expect(result[0].oldConfig).to.eql(apps.getAppConfig(APP_0));
|
|
|
|
|
expect(result[1].installationState).to.be(appdb.ISTATE_PENDING_RESTORE);
|
|
|
|
|
expect(result[2].installationState).to.be(appdb.ISTATE_PENDING_RESTORE);
|
|
|
|
|
expect(result[2].oldConfig).to.eql(apps.getAppConfig(APP_2));
|
2016-05-24 10:33:10 -07:00
|
|
|
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
2016-05-24 10:33:10 -07:00
|
|
|
|