From 21ec8797ccc6268cd4f73a606e3e78c7ee94e674 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Tue, 26 Apr 2016 10:07:47 -0700 Subject: [PATCH] Add test for alt-domain --- cloudron.js | 8 ++- parallel_test.sh | 2 +- test/alt-domain-test.js | 124 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 test/alt-domain-test.js diff --git a/cloudron.js b/cloudron.js index d0bec78..b66bb9a 100644 --- a/cloudron.js +++ b/cloudron.js @@ -182,8 +182,12 @@ Cloudron.prototype.installApp = function (location, manifest, cloudronVersion) { return appId; }; -Cloudron.prototype.configureApp = function (appId, newLocation) { - var res = request.post(this._origin + '/api/v1/apps/' + appId + '/configure').query({ access_token: this._credentials.accessToken }).send({ location: newLocation, accessRestriction: null, oauthProxy: false, password: this._credentials.password }).end(); +Cloudron.prototype.configureApp = function (appId, newLocation, altDomain /* optional */) { + var data = { location: newLocation, accessRestriction: null, oauthProxy: false, password: this._credentials.password }; + + if (altDomain) data.altDomain = altDomain; + + var res = request.post(this._origin + '/api/v1/apps/' + appId + '/configure').query({ access_token: this._credentials.accessToken }).send(data).end(); common.verifyResponse2xx(res, 'App could not be configured'); console.log('App moved to different location'.green); diff --git a/parallel_test.sh b/parallel_test.sh index fd3e204..51417c8 100755 --- a/parallel_test.sh +++ b/parallel_test.sh @@ -18,7 +18,7 @@ if ! ./node_modules/.bin/mocha --bail test/before.js > "logs/before.log" 2>&1; t fi # run tests -readonly tests=(app-flow-test app-update-test cloudron-button-test cloudron-user-test new-user-test cloudron-backup-test custom-domain-test cloudron-update-sfo1-test cloudron-update-ams3-test) +readonly tests=(app-flow-test app-update-test alt-domain-test cloudron-button-test cloudron-user-test new-user-test cloudron-backup-test custom-domain-test cloudron-update-sfo1-test cloudron-update-ams3-test) for t in "${tests[@]}"; do ./node_modules/.bin/mocha --bail "test/${t}.js" > "logs/${t}.log" 2>&1 & test_pids+=("$!") diff --git a/test/alt-domain-test.js b/test/alt-domain-test.js new file mode 100644 index 0000000..4e138a3 --- /dev/null +++ b/test/alt-domain-test.js @@ -0,0 +1,124 @@ +/* + * This tests if setting an alternate domain works + */ + +'use strict'; + +var AppStore = require('../appstore.js'), + assert = require('assert'), + async = require('async'), + AWS = require('aws-sdk'), + Cloudron = require('../cloudron.js'), + common = require('../common.js'), + request = require('superagent-sync'); + +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('Custom 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(location); + }); + + it('can check the addons', function () { + cloudron.checkAddons(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(location, owner); + }); + + it('can reboot the cloudron', function () { + cloudron.reboot(); + }); + + it('can check the addons', function () { + cloudron.checkAddons(location, owner); + }); + + it('can uninstall app', function () { + cloudron.uninstallApp(appId); + }); + + it('can delete the cloudron', function () { + appStore.deleteCloudron(box); + }); +});