cloudron-e2e-test/test/cloudron-migrate-test.js

220 lines
6.7 KiB
JavaScript

/*
* This tests a flow for cloudron owner creating a cloudron
* with a custom domain from the appstore. Owner creates a cloudron, activates
* it, installs an app. The cloudron then updates and we check if box updated
* correctly. It deletes the cloudron eventually.
*
*/
'use strict';
var AppStore = require('../appstore.js'),
assert = require('assert'),
async = require('async'),
Cloudron = require('../cloudron.js'),
common = require('../common.js'),
mailer = require('../mailer.js'),
request = require('superagent-sync'),
semver = require('semver'),
sleep = require('../shell.js').sleep;
require('colors');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
var BOX_VERSION = process.env.BOX_VERSION;
var CUSTOM_DOMAIN = process.env.CUSTOM_DOMAIN;
describe('Custom domain test', function () {
this.timeout(0);
var appStore = new AppStore('https://api.staging.cloudron.io');
var owner = common.getOwner();
var admin = common.getAdmin();
var cloudron, appId, box, backupInfo, nextVersion;
it('can query versions', function () {
var res = request.get('https://s3.amazonaws.com/staging-cloudron-releases/versions.json').end();
common.verifyResponse2xx(res);
var boxVersions = Object.keys(common.stripUnreachable(res.body)).sort(semver.rcompare);
var curVersion = boxVersions[1];
assert.strictEqual(curVersion, BOX_VERSION);
nextVersion = boxVersions[0];
});
it('can login to the store', function () {
var accessToken = appStore.getAccessToken(owner);
appStore.setCredentials(owner.password, accessToken);
var adminAccessToken = appStore.getAccessToken(admin);
appStore.setAdminCredentials(admin.password, adminAccessToken);
});
it('can get profile', function () {
var profile = appStore.getProfile();
owner.id = profile.id;
});
it('can setup billing details', function (done) {
appStore.setupBilling(owner, done);
});
it('can create a cloudron', function () {
box = appStore.createCloudron({
domain: common.cloudronDomain(__filename),
region: 'ams2',
size: '1gb',
version: BOX_VERSION
});
});
it('can wait for cloudron', function () {
box = appStore.waitForCloudron(box.id);
cloudron = new Cloudron(box);
});
it('can activate the box', function () {
cloudron.activate(owner);
});
it('can login to the box', function () {
var token = cloudron.getOauthToken(owner);
cloudron.setCredentials(owner.password, token);
});
it('can enable email', function () {
cloudron.setEmailEnabled(true);
});
it('can migrate cloudron to custom domain', function () {
cloudron.migrate({
domain: CUSTOM_DOMAIN,
provider: 'route53',
accessKeyId: process.env.AWS_STAGING_ACCESS_KEY,
secretAccessKey: process.env.AWS_STAGING_SECRET_KEY
});
});
it('can wait for cloudron', function () {
box = appStore.waitForCloudron(box.id);
cloudron = new Cloudron(box);
});
it('can login to the box', function () {
var token = cloudron.getOauthToken(owner);
cloudron.setCredentials(owner.password, token);
});
it('send mail to cloudron user', function (done) {
mailer.sendMailToCloudronUser(owner.username + '@' + CUSTOM_DOMAIN, done);
});
it('can set dns credentials again', function () {
cloudron.setDnsConfig({ provider: 'route53', accessKeyId: process.env.AWS_STAGING_ACCESS_KEY, secretAccessKey: process.env.AWS_STAGING_SECRET_KEY });
});
var location = 'test' + (Math.random() * 10000).toFixed();
it('can install app', function () {
var manifest = appStore.getManifest(common.TESTAPP_ID, common.TESTAPP_VERSION);
appId = cloudron.installApp(location, manifest);
});
it('can populate the addons', function () {
cloudron.populateAddons(cloudron.appFqdn(location));
});
it('can check the addons', function () {
cloudron.checkAddons(cloudron.appFqdn(location), owner);
});
it('can backup the box', function () {
backupInfo = cloudron.backup();
assert.strictEqual(backupInfo.dependsOn.length, 1);
});
it('can restore the box', function () {
appStore.restore(box.id, backupInfo.id + '.tar.gz.enc');
box = appStore.waitForCloudron(box.id);
});
it('wait for app to be ready', function () {
cloudron.waitForApp(appId);
});
it('can configure app', function () {
location = location + 'x';
cloudron.configureApp(appId, location);
});
it('can check the addons', function () {
cloudron.checkAddons(cloudron.appFqdn(location), owner);
});
it('can reboot the cloudron', function () {
cloudron.reboot();
});
it('can check the addons', function () {
cloudron.checkAddons(cloudron.appFqdn(location), owner);
});
it('can check dnsbl', function () {
cloudron.checkDnsbl(cloudron.appFqdn(location));
});
it('can migrate to bigger size', function () {
cloudron.migrate({ size: '2gb' });
});
it('can wait for cloudron', function () {
box = appStore.waitForCloudron(box.id);
cloudron = new Cloudron(box);
});
it('can login to the box', function () {
var token = cloudron.getOauthToken(owner);
cloudron.setCredentials(owner.password, token);
});
it('can check the addons', function () {
cloudron.checkAddons(cloudron.appFqdn(location), owner);
});
it('can update to new version', function () {
console.log('Wait for cloudron to get the update to ' + nextVersion);
cloudron.checkForUpdates();
sleep(60 * 2);
cloudron.update(nextVersion);
});
it('runs the app', function () {
cloudron.waitForApp(appId);
});
it('can check the addons', function () {
cloudron.checkAddons(cloudron.appFqdn(location), owner);
});
it('can uninstall app', function () {
cloudron.uninstallApp(appId);
});
it('can check mail', function (done) {
cloudron.checkMail(owner, done);
});
// check this after activation
it('has setup DNS records correctly', function (done) {
async.series([
// cloudron.checkA.bind(cloudron), // this is at user's discretion
cloudron.checkSPF.bind(cloudron),
cloudron.checkDKIM.bind(cloudron),
cloudron.checkMX.bind(cloudron),
// cloudron.checkDMARC.bind(cloudron)
], done);
});
it('can delete the cloudron', function () {
appStore.deleteCloudron(box);
});
});