#!/usr/bin/env node /* * This tests a flow for the cloudron owner backs up a cloudron. * The backup is validated and restored from. */ 'use strict'; var AppStore = require('../appstore.js'), assert = require('assert'), Cloudron = require('../cloudron.js'), common = require('../common.js'), dnsSync = require('dns-sync'), request = require('superagent-sync'), semver = require('semver'), sleep = require('sleep').sleep; require('colors'); process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; describe('Cloudron backup testing', function () { this.timeout(0); var appStore = new AppStore('https://api.staging.cloudron.io'); var owner = common.getOwner(); var res, latestVersion, cloudron, appId, box, backupInfo; it('can query versions', function () { res = request.get('https://s3.amazonaws.com/staging-cloudron-releases/versions.json').end(); common.verifyResponse(res); var boxVersions = Object.keys(res.body).sort(semver.rcompare); latestVersion = boxVersions[0]; }); it('can login to the store', function () { var accessToken = appStore.getAccessToken(owner); appStore.setCredentials(owner.password, accessToken); }); it('can create a cloudron', function () { box = appStore.createCloudron({ domain: common.cloudronDomain(__filename), zoneName: 'smartserver.io', region: 'sfo1', size: '512mb', version: latestVersion }); 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 () { var res = request.post('https://' + location + '-' + box.domain + '/populate_addons').end(); assert.strictEqual(res.statusCode, 200); assert.strictEqual(res.body.mysql, 'OK'); assert.strictEqual(res.body.postgresql, 'OK'); assert.strictEqual(res.body.mongodb, 'OK'); assert.strictEqual(res.body.localstorage, 'OK'); }); it('can check the addons', function () { var res = request.query({ username: owner.username, password: owner.password }).post('https://' + location + '-' + box.domain + '/check_addons').end(); assert.strictEqual(res.statusCode, 200); assert.strictEqual(res.body.mysql, 'OK'); assert.strictEqual(res.body.postgresql, 'OK'); assert.strictEqual(res.body.mongodb, 'OK'); assert.strictEqual(res.body.localstorage, 'OK'); assert.strictEqual(res.body.ldap, 'OK'); assert.strictEqual(res.body.sendmail, 'OK'); }); 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.restoreKey); box = appStore.waitForCloudron(box.id); }); it('wait for local dns', function () { for (var i = 0; i < 50; i++) { var ip = dnsSync.resolve(box.domain); if (ip === box.ip) return; console.log('waiting for local dns to change from %s to %s', ip, box.ip); sleep(30); } }); it('can login to cloudron', function () { var token = cloudron.getOauthToken(owner); cloudron.setCredentials(owner.password, token); }); it('wait for app', function () { cloudron.waitForApp(appId); }); it('can check the addons', function () { var res = request.query({ username: owner.username, password: owner.password }).post('https://' + location + '-' + box.domain + '/check_addons').end(); assert.strictEqual(res.statusCode, 200); assert.strictEqual(res.body.mysql, 'OK'); assert.strictEqual(res.body.postgresql, 'OK'); assert.strictEqual(res.body.mongodb, 'OK'); assert.strictEqual(res.body.localstorage, 'OK'); assert.strictEqual(res.body.ldap, 'OK'); assert.strictEqual(res.body.sendmail, 'OK'); }); it('can uninstall app', function () { cloudron.uninstallApp(appId); }); it('can delete the cloudron', function () { appStore.deleteCloudron(box); }); });