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'),
|
2023-01-19 19:05:44 +01:00
|
|
|
BoxError = require('../boxerror.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'),
|
2023-01-19 19:05:44 +01:00
|
|
|
tokens = require('../tokens.js'),
|
|
|
|
|
safe = require('safetydance');
|
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
|
|
|
|
2023-01-19 19:05:44 +01:00
|
|
|
it('can set backup config', async function () {
|
|
|
|
|
let backupConfig = await settings.getBackupConfig();
|
2023-03-09 19:54:04 +01:00
|
|
|
backupConfig = Object.assign({}, backupConfig, { backupFolder: '/tmp/backups' });
|
2023-01-19 19:05:44 +01:00
|
|
|
await settings.setBackupConfig(backupConfig);
|
|
|
|
|
|
|
|
|
|
const newBackupConfig = await settings.getBackupConfig();
|
|
|
|
|
expect(newBackupConfig.backupFolder).to.be('/tmp/backups');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('cannot set backup config with invalid schedulePattern', async function () {
|
|
|
|
|
let backupConfig = await settings.getBackupConfig();
|
|
|
|
|
backupConfig.schedulePattern = '';
|
|
|
|
|
const [error] = await safe(settings.setBackupConfig(backupConfig));
|
|
|
|
|
expect(error.reason).to.be(BoxError.BAD_FIELD);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can set backup config with valid schedulePattern', async function () {
|
|
|
|
|
let backupConfig = await settings.getBackupConfig();
|
|
|
|
|
backupConfig.schedulePattern = '00 00 2,23 * * 0,1,2';
|
|
|
|
|
await settings.setBackupConfig(backupConfig);
|
|
|
|
|
});
|
|
|
|
|
|
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 () {
|
2022-09-24 18:26:31 +02:00
|
|
|
await tokens.add({ name: 'token1', identifier: admin.id, clientId: tokens.ID_WEBADMIN, expires: Number.MAX_SAFE_INTEGER, lastUsedTime: null });
|
2021-09-17 14:32:13 -07:00
|
|
|
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
|
|
|
});
|