From 476dd27ae5d86824739bee3a74f89cd112a54021 Mon Sep 17 00:00:00 2001 From: Johannes Zellner Date: Thu, 23 Jun 2016 13:57:16 +0200 Subject: [PATCH] Initial ec2 selfhosting test --- test/selfhost-ec2-create-test.js | 138 +++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 test/selfhost-ec2-create-test.js diff --git a/test/selfhost-ec2-create-test.js b/test/selfhost-ec2-create-test.js new file mode 100644 index 0000000..c117553 --- /dev/null +++ b/test/selfhost-ec2-create-test.js @@ -0,0 +1,138 @@ +/* + * This tests a flow for cloudron owner creating a selfhosted cloudron on ec2 + * Owner creates a cloudron, activates it, installs and app and deletes the cloudron eventually + * + */ + +'use strict'; + +var AppStore = require('../appstore.js'), + assert = require('assert'), + async = require('async'), + child_process = require('child_process'), + Cloudron = require('../cloudron.js'), + common = require('../common.js'), + mailer = require('../mailer.js'), + util = require('util'); + +require('colors'); + +process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; +var BOX_VERSION = process.env.BOX_VERSION; +var CUSTOM_DOMAIN = process.env.CUSTOM_DOMAIN; + +function machine(args, options) { + // https://github.com/nodejs/node-v0.x-archive/issues/9265 + options = options || { }; + args = util.isArray(args) ? args : args.match(/[^\s"]+|"([^"]+)"/g); + args = args.map(function (e) { return e[0] === '"' ? e.slice(1, -1) : e; }); // remove the quotes + + console.log('cloudron ' + args.join(' ')); + + try { + var cp = child_process.spawnSync('machine', args, { stdio: [ options.stdin || 'pipe', options.stdout || 'pipe', 'pipe' ], encoding: options.encoding || 'utf8' }); + return cp; + } catch (e) { + console.error(e); + throw e; + } +} + +describe('Selfhost EC2 Cloudron creation', function () { + this.timeout(0); + + var appStore = new AppStore('https://api.staging.cloudron.io'); + + var owner = common.getOwner(); + var cloudron, appId, box, backupInfo; + + it('can create a cloudron', function () { + var out = machine('create ec2'); + console.log(out); + asdf + 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('send mail to cloudron user', function (done) { + mailer.sendMailToCloudronUser(owner.username + '@' + CUSTOM_DOMAIN, done); + }); + + it('can set dns credentials', 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); + 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 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 () { + }); +});