cloudron-e2e-test/test/alt-domain-test.js
2016-06-23 22:56:59 -05:00

149 lines
4.6 KiB
JavaScript

/*
* This tests if setting an alternate domain works
*/
'use strict';
var AppStore = require('../appstore.js'),
AWS = require('aws-sdk'),
Cloudron = require('../cloudron.js'),
common = require('../common.js');
require('colors');
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
var BOX_VERSION = process.env.BOX_VERSION;
var CUSTOM_DOMAIN = process.env.CUSTOM_DOMAIN;
var ALT_LOCATION = 'altlocation';
describe('Alt domain test', function () {
this.timeout(0);
var appStore = new AppStore('https://api.staging.cloudron.io');
var route53 = new AWS.Route53({ accessKeyId: process.env.AWS_STAGING_ACCESS_KEY, secretAccessKey: process.env.AWS_STAGING_SECRET_KEY });
var owner = common.getOwner();
var admin = common.getAdmin();
var cloudron, appId, box;
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 create a cloudron', function () {
box = appStore.createCloudron({
domain: common.cloudronDomain(__filename),
region: 'sfo1',
size: '1gb',
version: BOX_VERSION
});
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);
});
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 setup cname for altlocation', function (done) {
route53.listHostedZonesByName({ DNSName: CUSTOM_DOMAIN, MaxItems: '1'}, function (error, result) {
if (error) return done(error);
var params = {
ChangeBatch: {
Changes: [{
Action: 'UPSERT',
ResourceRecordSet: {
Type: 'CNAME',
Name: ALT_LOCATION + '.' + CUSTOM_DOMAIN + '.',
ResourceRecords: [ { Value: cloudron.appFqdn(location) } ],
TTL: 1
}
}]
},
HostedZoneId: result.HostedZones[0].Id
};
route53.changeResourceRecordSets(params, function(error) {
if (error) return done(error);
done();
});
});
});
it('can configure app to alt location', function () {
cloudron.configureApp(appId, location, ALT_LOCATION + '.' + CUSTOM_DOMAIN);
});
it('can check the addons', function () {
cloudron.checkAddons(ALT_LOCATION + '.' + CUSTOM_DOMAIN, owner);
});
it('can reboot the cloudron', function () {
cloudron.reboot();
});
it('can check the addons', function () {
cloudron.checkAddons(ALT_LOCATION + '.' + CUSTOM_DOMAIN, owner);
});
it('can uninstall app', function () {
cloudron.uninstallApp(appId);
});
it('can delete cname for altlocation', function (done) {
route53.listHostedZonesByName({ DNSName: CUSTOM_DOMAIN, MaxItems: '1'}, function (error, result) {
if (error) return done(error);
var params = {
ChangeBatch: {
Changes: [{
Action: 'DELETE',
ResourceRecordSet: {
Type: 'CNAME',
Name: ALT_LOCATION + '.' + CUSTOM_DOMAIN + '.',
ResourceRecords: [ { Value: cloudron.appFqdn(location) } ],
TTL: 1
}
}]
},
HostedZoneId: result.HostedZones[0].Id
};
route53.changeResourceRecordSets(params, function(error) {
if (error) return done(error);
done();
});
});
});
it('can delete the cloudron', function () {
appStore.deleteCloudron(box);
});
});