2015-07-20 00:09:47 -07:00
|
|
|
/* global it:false */
|
|
|
|
|
/* global describe:false */
|
|
|
|
|
/* global before:false */
|
|
|
|
|
/* global after:false */
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
2017-02-07 10:30:52 -08:00
|
|
|
var async = require('async'),
|
|
|
|
|
config = require('../config.js'),
|
2017-01-10 16:44:28 -08:00
|
|
|
database = require('../database.js'),
|
2015-07-20 00:09:47 -07:00
|
|
|
expect = require('expect.js'),
|
2017-09-27 10:25:36 -07:00
|
|
|
MockS3 = require('mock-aws-s3'),
|
|
|
|
|
nock = require('nock'),
|
|
|
|
|
os = require('os'),
|
|
|
|
|
path = require('path'),
|
|
|
|
|
rimraf = require('rimraf'),
|
|
|
|
|
s3 = require('../storage/s3.js'),
|
2017-06-28 09:51:01 -05:00
|
|
|
settings = require('../settings.js'),
|
|
|
|
|
settingsdb = require('../settingsdb.js');
|
2015-07-20 00:09:47 -07:00
|
|
|
|
|
|
|
|
function setup(done) {
|
2017-11-27 15:27:54 -08:00
|
|
|
config._reset();
|
|
|
|
|
config.set('fqdn', 'example.com');
|
2017-04-14 01:13:42 -07:00
|
|
|
config.set('provider', 'caas');
|
2017-09-27 10:25:36 -07:00
|
|
|
nock.cleanAll();
|
2017-04-14 01:13:42 -07:00
|
|
|
|
2017-02-07 10:30:52 -08:00
|
|
|
async.series([
|
|
|
|
|
database.initialize,
|
|
|
|
|
settings.initialize,
|
|
|
|
|
function (callback) {
|
2017-09-27 10:25:36 -07:00
|
|
|
MockS3.config.basePath = path.join(os.tmpdir(), 's3-settings-test-buckets/');
|
|
|
|
|
|
|
|
|
|
s3._mockInject(MockS3);
|
|
|
|
|
|
2017-02-07 10:30:52 -08:00
|
|
|
// a cloudron must have a backup config to startup
|
2017-09-27 10:25:36 -07:00
|
|
|
settingsdb.set(settings.BACKUP_CONFIG_KEY, JSON.stringify({ provider: 'caas', token: 'foo', key: 'key', format: 'tgz'}), function (error) {
|
2017-02-07 10:30:52 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
callback();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
], done);
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cleanup(done) {
|
2017-09-27 10:25:36 -07:00
|
|
|
s3._mockRestore();
|
|
|
|
|
rimraf.sync(MockS3.config.basePath);
|
|
|
|
|
|
2017-02-07 10:30:52 -08:00
|
|
|
async.series([
|
|
|
|
|
settings.uninitialize,
|
2017-11-27 11:48:36 -08:00
|
|
|
database._clear,
|
|
|
|
|
database.uninitialize
|
2017-02-07 10:30:52 -08:00
|
|
|
], done);
|
2015-07-20 00:09:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe('Settings', function () {
|
2015-10-28 14:35:39 +01:00
|
|
|
describe('values', function () {
|
|
|
|
|
before(setup);
|
|
|
|
|
after(cleanup);
|
2015-07-20 00:09:47 -07:00
|
|
|
|
2015-10-28 14:35:39 +01:00
|
|
|
it('can get default timezone', function (done) {
|
|
|
|
|
settings.getTimeZone(function (error, tz) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(tz.length).to.not.be(0);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
2015-07-23 12:42:52 +02:00
|
|
|
|
2015-10-28 14:35:39 +01:00
|
|
|
it('can get default autoupdate_pattern', function (done) {
|
|
|
|
|
settings.getAutoupdatePattern(function (error, pattern) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(pattern).to.be('00 00 1,3,5,23 * * *');
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
2015-07-23 12:42:52 +02:00
|
|
|
|
2015-10-28 14:35:39 +01:00
|
|
|
it ('can get default cloudron name', function (done) {
|
|
|
|
|
settings.getCloudronName(function (error, name) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(name).to.be('Cloudron');
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
2015-07-23 12:42:52 +02:00
|
|
|
|
2015-10-28 14:35:39 +01:00
|
|
|
it('can get default cloudron avatar', function (done) {
|
|
|
|
|
settings.getCloudronAvatar(function (error, gravatar) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(gravatar).to.be.a(Buffer);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|
2015-07-23 12:42:52 +02:00
|
|
|
|
2015-12-11 22:32:34 -08:00
|
|
|
it('can set tls config', function (done) {
|
|
|
|
|
settings.setTlsConfig({ provider: 'caas' }, function (error) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can get tls config', function (done) {
|
|
|
|
|
settings.getTlsConfig(function (error, dnsConfig) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(dnsConfig.provider).to.be('caas');
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-11-07 22:17:08 -08:00
|
|
|
it('can set backup config', function (done) {
|
2017-09-27 10:25:36 -07:00
|
|
|
var scope2 = nock(config.apiServerOrigin())
|
|
|
|
|
.post('/api/v1/boxes/' + config.fqdn() + '/awscredentials?token=TOKEN')
|
|
|
|
|
.reply(201, { credentials: { AccessKeyId: 'accessKeyId', SecretAccessKey: 'secretAccessKey', SessionToken: 'sessionToken' } });
|
|
|
|
|
|
|
|
|
|
settings.setBackupConfig({ provider: 'caas', token: 'TOKEN', format: 'tgz', prefix: 'boxid', bucket: 'bucket' }, function (error) {
|
2015-11-07 22:17:08 -08:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can get backup config', function (done) {
|
2016-01-23 05:06:09 -08:00
|
|
|
settings.getBackupConfig(function (error, backupConfig) {
|
2015-11-07 22:17:08 -08:00
|
|
|
expect(error).to.be(null);
|
2016-01-23 05:06:09 -08:00
|
|
|
expect(backupConfig.provider).to.be('caas');
|
|
|
|
|
expect(backupConfig.token).to.be('TOKEN');
|
|
|
|
|
done();
|
2016-01-23 05:07:12 -08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-08-30 21:08:29 -07:00
|
|
|
it('can set mail config', function (done) {
|
2016-08-30 21:12:14 -07:00
|
|
|
settings.setMailConfig({ enabled: true }, function (error) {
|
2016-08-30 21:08:29 -07:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-08-30 21:12:14 -07:00
|
|
|
it('can get mail config', function (done) {
|
|
|
|
|
settings.getMailConfig(function (error, mailConfig) {
|
2016-08-30 21:08:29 -07:00
|
|
|
expect(error).to.be(null);
|
2016-08-30 21:12:14 -07:00
|
|
|
expect(mailConfig.enabled).to.be(true);
|
2016-08-30 21:08:29 -07:00
|
|
|
done();
|
2017-07-18 16:58:37 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can set mail from validation', function (done) {
|
|
|
|
|
settings.setMailFromValidation(true, function (error) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can get mail from validation', function (done) {
|
|
|
|
|
settings.getMailFromValidation(function (error, enabled) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(enabled).to.be(true);
|
|
|
|
|
done();
|
2017-07-23 10:53:16 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can enable mail digest', function (done) {
|
|
|
|
|
settings.setEmailDigest(true, function (error) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can get mail digest', function (done) {
|
|
|
|
|
settings.getEmailDigest(function (error, enabled) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(enabled).to.be(true);
|
|
|
|
|
done();
|
2016-08-30 21:08:29 -07:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-27 12:09:57 -05:00
|
|
|
it('can get mail relay', function (done) {
|
|
|
|
|
settings.getMailRelay(function (error, address) {
|
|
|
|
|
expect(error).to.be(null);
|
2017-06-28 09:51:01 -05:00
|
|
|
expect(address).to.eql({ provider: 'cloudron-smtp' });
|
2017-06-27 12:09:57 -05:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can set mail relay', function (done) {
|
2017-06-28 09:51:01 -05:00
|
|
|
var relay = { provider: 'external-smtp', host: 'mx.foo.com', port: 25 };
|
|
|
|
|
+ settingsdb.set(settings.MAIL_RELAY_KEY, JSON.stringify(relay), function (error) { // skip the mail server verify()
|
2017-06-27 12:09:57 -05:00
|
|
|
expect(error).to.be(null);
|
|
|
|
|
|
|
|
|
|
settings.getMailRelay(function (error, address) {
|
|
|
|
|
expect(error).to.be(null);
|
2017-06-28 09:51:01 -05:00
|
|
|
expect(address).to.eql(relay);
|
2017-06-27 12:09:57 -05:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-06-11 17:51:08 -07:00
|
|
|
it('can get catch all address', function (done) {
|
|
|
|
|
settings.getCatchAllAddress(function (error, address) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(address).to.eql([ ]);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can set catch all address', function (done) {
|
|
|
|
|
settings.setCatchAllAddress([ "user1", "user2" ], function (error) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
|
|
|
|
|
settings.getCatchAllAddress(function (error, address) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
expect(address).to.eql([ "user1", "user2" ]);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2015-10-28 14:35:39 +01:00
|
|
|
it('can get all values', function (done) {
|
|
|
|
|
settings.getAll(function (error, allSettings) {
|
|
|
|
|
expect(error).to.be(null);
|
|
|
|
|
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');
|
|
|
|
|
done();
|
|
|
|
|
});
|
2015-10-26 00:44:54 -07:00
|
|
|
});
|
|
|
|
|
});
|
2015-07-20 00:09:47 -07:00
|
|
|
});
|