2016-04-15 12:33:54 -07:00
|
|
|
/* global it:false */
|
|
|
|
|
/* global describe:false */
|
|
|
|
|
/* global before:false */
|
|
|
|
|
/* global after:false */
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
2018-06-30 14:33:51 +02:00
|
|
|
var async = require('async'),
|
2016-04-15 12:33:54 -07:00
|
|
|
config = require('../../config.js'),
|
|
|
|
|
database = require('../../database.js'),
|
2018-01-26 21:31:04 +01:00
|
|
|
domains = require('../../domains.js'),
|
2018-06-30 14:33:51 +02:00
|
|
|
eventlog = require('../../eventlog.js'),
|
2016-04-15 12:33:54 -07:00
|
|
|
expect = require('expect.js'),
|
|
|
|
|
server = require('../../server.js'),
|
2017-09-19 08:19:01 -07:00
|
|
|
settings = require('../../settings.js'),
|
2017-09-27 10:25:36 -07:00
|
|
|
settingsdb = require('../../settingsdb.js'),
|
2018-06-30 14:33:51 +02:00
|
|
|
superagent = require('superagent');
|
2016-04-15 12:33:54 -07:00
|
|
|
|
2018-01-26 21:31:04 +01:00
|
|
|
const SERVER_URL = 'http://localhost:' + config.get('port');
|
2016-04-15 12:33:54 -07:00
|
|
|
|
2018-01-26 21:31:04 +01:00
|
|
|
const USERNAME = 'superadmin', PASSWORD = 'Foobar?1337', EMAIL ='silly@me.com';
|
|
|
|
|
|
|
|
|
|
const DOMAIN_0 = {
|
|
|
|
|
domain: 'example-sysadmin-test.com',
|
|
|
|
|
zoneName: 'example-sysadmin-test.com',
|
|
|
|
|
config: {},
|
|
|
|
|
provider: 'noop',
|
2018-01-31 18:09:38 +01:00
|
|
|
fallbackCertificate: null,
|
|
|
|
|
tlsConfig: { provider: 'fallback' }
|
2018-01-26 21:31:04 +01:00
|
|
|
};
|
2016-04-15 12:33:54 -07:00
|
|
|
|
|
|
|
|
function setup(done) {
|
2017-11-27 15:30:55 -08:00
|
|
|
config._reset();
|
2018-01-26 21:31:04 +01:00
|
|
|
config.setFqdn(DOMAIN_0.domain);
|
2016-04-15 12:33:54 -07:00
|
|
|
config.setVersion('1.2.3');
|
|
|
|
|
|
|
|
|
|
async.series([
|
2018-01-26 21:31:04 +01:00
|
|
|
server.start,
|
2016-04-15 12:33:54 -07:00
|
|
|
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, DOMAIN_0.fallbackCertificate, DOMAIN_0.tlsConfig),
|
2016-04-15 12:33:54 -07:00
|
|
|
|
|
|
|
|
function createAdmin(callback) {
|
|
|
|
|
superagent.post(SERVER_URL + '/api/v1/cloudron/activate')
|
2017-09-17 18:50:26 -07:00
|
|
|
.query({ setupToken: 'somesetuptoken' })
|
|
|
|
|
.send({ username: USERNAME, password: PASSWORD, email: EMAIL })
|
|
|
|
|
.end(function (error, result) {
|
|
|
|
|
expect(result).to.be.ok();
|
|
|
|
|
expect(result.statusCode).to.eql(201);
|
|
|
|
|
callback();
|
|
|
|
|
});
|
2016-04-15 12:33:54 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
function createSettings(callback) {
|
2018-01-26 21:31:04 +01:00
|
|
|
settingsdb.set(settings.BACKUP_CONFIG_KEY, JSON.stringify({ provider: 'caas', token: 'BACKUP_TOKEN', fqdn: DOMAIN_0.domain, key: 'key', prefix: 'boxid', format: 'tgz'}), callback);
|
2016-04-15 12:33:54 -07:00
|
|
|
}
|
|
|
|
|
], done);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function cleanup(done) {
|
|
|
|
|
database._clear(function (error) {
|
|
|
|
|
expect(!error).to.be.ok();
|
|
|
|
|
server.stop(done);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe('Internal API', function () {
|
2018-06-30 14:33:51 +02:00
|
|
|
this.timeout(5000);
|
|
|
|
|
|
2016-04-15 12:33:54 -07:00
|
|
|
before(setup);
|
|
|
|
|
after(cleanup);
|
|
|
|
|
|
|
|
|
|
describe('backup', function () {
|
|
|
|
|
it('succeeds', function (done) {
|
|
|
|
|
superagent.post(config.sysadminOrigin() + '/api/v1/backup')
|
2018-06-30 14:33:51 +02:00
|
|
|
.end(function (error, result) {
|
|
|
|
|
expect(result.statusCode).to.equal(202);
|
2016-04-15 12:33:54 -07:00
|
|
|
|
2018-06-30 14:33:51 +02:00
|
|
|
function checkBackupStartEvent() {
|
|
|
|
|
eventlog.getAllPaged([ eventlog.ACTION_BACKUP_START ], '', 1, 100, function (error, result) {
|
|
|
|
|
expect(error).to.equal(null);
|
2016-04-15 12:33:54 -07:00
|
|
|
|
2018-06-30 14:33:51 +02:00
|
|
|
if (result.length === 0) return setTimeout(checkBackupStartEvent, 1000);
|
2016-04-15 12:33:54 -07:00
|
|
|
|
2018-06-30 14:33:51 +02:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkBackupStartEvent();
|
|
|
|
|
});
|
2016-04-15 12:33:54 -07:00
|
|
|
});
|
|
|
|
|
});
|
2018-06-30 14:33:51 +02:00
|
|
|
});
|