2015-07-20 00:09:47 -07:00
|
|
|
/* global it:false */
|
|
|
|
|
/* global describe:false */
|
|
|
|
|
/* global before:false */
|
|
|
|
|
/* global after:false */
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
2021-08-20 08:58:00 -07:00
|
|
|
const common = require('./common.js'),
|
2015-07-20 00:09:47 -07:00
|
|
|
expect = require('expect.js'),
|
2021-09-17 14:32:13 -07:00
|
|
|
settings = require('../settings.js'),
|
|
|
|
|
tokens = require('../tokens.js');
|
2018-01-23 15:47:41 -08:00
|
|
|
|
2015-07-20 00:09:47 -07:00
|
|
|
describe('Settings', function () {
|
2021-09-17 14:32:13 -07:00
|
|
|
const { setup, cleanup, admin } = common;
|
2021-08-20 08:58:00 -07:00
|
|
|
|
|
|
|
|
before(setup);
|
|
|
|
|
after(cleanup);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2021-08-20 08:58:00 -07:00
|
|
|
it('can get default timezone', async function () {
|
|
|
|
|
const tz = await settings.getTimeZone();
|
|
|
|
|
expect(tz.length).to.not.be(0);
|
|
|
|
|
});
|
2015-07-23 12:42:52 +02:00
|
|
|
|
2021-08-20 08:58:00 -07:00
|
|
|
it('can get default autoupdate_pattern', async function () {
|
|
|
|
|
const pattern = await settings.getAutoupdatePattern();
|
|
|
|
|
expect(pattern).to.be('00 00 1,3,5,23 * * *');
|
|
|
|
|
});
|
2018-02-06 18:57:30 +01:00
|
|
|
|
2021-08-20 08:58:00 -07:00
|
|
|
it ('can get default cloudron name', async function () {
|
|
|
|
|
const name = await settings.getCloudronName();
|
|
|
|
|
expect(name).to.be('Cloudron');
|
|
|
|
|
});
|
2015-07-23 12:42:52 +02:00
|
|
|
|
2021-08-20 08:58:00 -07:00
|
|
|
it('can get default cloudron avatar', async function () {
|
|
|
|
|
const avatar = await settings.getCloudronAvatar();
|
|
|
|
|
expect(avatar).to.be.a(Buffer);
|
|
|
|
|
});
|
2015-07-23 12:42:52 +02:00
|
|
|
|
2021-08-20 08:58:00 -07:00
|
|
|
it('can get backup config', async function () {
|
|
|
|
|
const backupConfig = await settings.getBackupConfig();
|
|
|
|
|
expect(backupConfig.provider).to.be('filesystem');
|
|
|
|
|
expect(backupConfig.backupFolder).to.be('/var/backups');
|
|
|
|
|
});
|
2016-01-23 05:07:12 -08:00
|
|
|
|
2021-08-20 08:58:00 -07:00
|
|
|
it('can get default unstable apps setting', async function () {
|
|
|
|
|
const enabled = await settings.getUnstableAppsConfig();
|
|
|
|
|
expect(enabled).to.be(true);
|
|
|
|
|
});
|
2019-04-27 22:34:52 +02:00
|
|
|
|
2021-08-20 08:58:00 -07:00
|
|
|
it('can set unstable apps setting', async function () {
|
|
|
|
|
await settings.setUnstableAppsConfig(false);
|
2019-04-27 22:34:52 +02:00
|
|
|
|
2021-08-20 08:58:00 -07:00
|
|
|
const enabled = await settings.getUnstableAppsConfig();
|
|
|
|
|
expect(enabled).to.be(false);
|
|
|
|
|
});
|
2019-04-27 22:34:52 +02:00
|
|
|
|
2022-01-06 08:58:46 -08:00
|
|
|
it('can get default IPv6 setting', async function () {
|
2022-02-15 12:31:55 -08:00
|
|
|
const config = await settings.getIPv6Config();
|
|
|
|
|
expect(config.provider).to.be('noop');
|
2022-01-06 08:58:46 -08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can set IPv6 setting', async function () {
|
2022-02-15 12:31:55 -08:00
|
|
|
await settings.setIPv6Config({ provider: 'generic' });
|
2022-01-06 08:58:46 -08:00
|
|
|
|
2022-02-15 12:31:55 -08:00
|
|
|
const config = await settings.getIPv6Config();
|
|
|
|
|
expect(config.provider).to.be('generic');
|
2022-01-06 08:58:46 -08:00
|
|
|
});
|
|
|
|
|
|
2022-01-13 15:20:16 -08:00
|
|
|
it('can get default profile config', async function () {
|
|
|
|
|
const profileConfig = await settings.getProfileConfig();
|
|
|
|
|
expect(profileConfig.lockUserProfiles).to.be(false);
|
|
|
|
|
expect(profileConfig.mandatory2FA).to.be(false);
|
2021-09-17 14:32:13 -07:00
|
|
|
});
|
|
|
|
|
|
2022-01-13 15:20:16 -08:00
|
|
|
it('can set default profile config', async function () {
|
2021-09-17 14:32:13 -07:00
|
|
|
await tokens.add({ name: 'token1', identifier: admin.id, clientId: tokens.ID_WEBADMIN, expires: Number.MAX_SAFE_INTEGER, lastUsedTime: null, scope: 'unused' });
|
|
|
|
|
let result = await tokens.listByUserId(admin.id);
|
|
|
|
|
expect(result.length).to.be(1); // just confirm the token was really added!
|
|
|
|
|
|
2022-01-13 15:20:16 -08:00
|
|
|
await settings.setProfileConfig({ mandatory2FA: true, lockUserProfiles: true });
|
2021-09-17 14:32:13 -07:00
|
|
|
result = await tokens.listByUserId(admin.id);
|
|
|
|
|
expect(result.length).to.be(0); // should have been removed by mandatory 2fa setting change
|
|
|
|
|
});
|
|
|
|
|
|
2021-08-20 08:58:00 -07:00
|
|
|
it('can get all values', async function () {
|
|
|
|
|
const allSettings = await settings.list();
|
|
|
|
|
expect(allSettings[settings.TIME_ZONE_KEY]).to.be.a('string');
|
|
|
|
|
expect(allSettings[settings.AUTOUPDATE_PATTERN_KEY]).to.be.a('string');
|
|
|
|
|
expect(allSettings[settings.CLOUDRON_NAME_KEY]).to.be.a('string');
|
|
|
|
|
expect(allSettings[settings.UNSTABLE_APPS_KEY]).to.be.a('boolean');
|
2022-02-15 12:31:55 -08:00
|
|
|
expect(allSettings[settings.IPV6_CONFIG_KEY]).to.be.an('object');
|
2015-10-26 00:44:54 -07:00
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|