|
@@ -0,0 +1,271 @@
|
|
|
+#!/usr/bin/env node
|
|
|
+
|
|
|
+'use strict';
|
|
|
+
|
|
|
+require('chromedriver');
|
|
|
+
|
|
|
+var execSync = require('child_process').execSync,
|
|
|
+ expect = require('expect.js'),
|
|
|
+ fs = require('fs'),
|
|
|
+ path = require('path'),
|
|
|
+ superagent = require('superagent'),
|
|
|
+ util = require('util');
|
|
|
+
|
|
|
+var by = require('selenium-webdriver').By,
|
|
|
+ until = require('selenium-webdriver').until;
|
|
|
+
|
|
|
+if (!process.env.USERNAME || !process.env.PASSWORD) {
|
|
|
+ console.log('USERNAME and PASSWORD env vars need to be set');
|
|
|
+ process.exit(1);
|
|
|
+}
|
|
|
+
|
|
|
+describe('Application life cycle test', function () {
|
|
|
+ this.timeout(0);
|
|
|
+
|
|
|
+ var chrome = require('selenium-webdriver/chrome');
|
|
|
+ var browser = new chrome.Driver();
|
|
|
+
|
|
|
+ var TEST_TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 20000;
|
|
|
+ var LOCATION = 'test';
|
|
|
+ var app, apiKey;
|
|
|
+ var username = process.env.USERNAME;
|
|
|
+ var password = process.env.PASSWORD;
|
|
|
+
|
|
|
+ after(function () {
|
|
|
+ browser.quit();
|
|
|
+ });
|
|
|
+
|
|
|
+ function getAppInfo() {
|
|
|
+ var inspect = JSON.parse(execSync('cloudron inspect'));
|
|
|
+ app = inspect.apps.filter(function (a) { return a.location === LOCATION || a.location === LOCATION + '2'; })[0];
|
|
|
+ expect(app).to.be.an('object');
|
|
|
+ }
|
|
|
+
|
|
|
+ function login(username, password, done) {
|
|
|
+ browser.manage().deleteAllCookies().then(function () {
|
|
|
+ return browser.get('https://' + app.fqdn);
|
|
|
+ }).then(function () {
|
|
|
+ return browser.wait(until.elementLocated(by.id('username')));
|
|
|
+ }).then(function () {
|
|
|
+ return browser.findElement(by.id('username')).sendKeys(username);
|
|
|
+ }).then(function () {
|
|
|
+ return browser.findElement(by.id('password')).sendKeys(password);
|
|
|
+ }).then(function () {
|
|
|
+ return browser.findElement(by.tagName('form')).submit();
|
|
|
+ }).then(function () {
|
|
|
+ return browser.wait(until.elementLocated(by.id('documentName')));
|
|
|
+ }).then(function () {
|
|
|
+ done();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function createDocument(done) {
|
|
|
+ browser.get('https://' + app.fqdn).then(function () {
|
|
|
+ return browser.wait(until.elementLocated(by.id('documentName')));
|
|
|
+ }).then(function () {
|
|
|
+ return browser.findElement(by.id('documentName')).sendKeys('paddington');
|
|
|
+ }).then(function () {
|
|
|
+ return browser.findElement(by.tagName('form')).submit();
|
|
|
+ }).then(function () {
|
|
|
+ return browser.wait(function () {
|
|
|
+ return browser.getCurrentUrl().then(function (url) {
|
|
|
+ return url === 'https://' + app.fqdn + '/p/paddington';
|
|
|
+ });
|
|
|
+ }, TEST_TIMEOUT);
|
|
|
+ }).then(function () {
|
|
|
+ return browser.wait(until.elementLocated(by.name('ace_outer')), TEST_TIMEOUT);
|
|
|
+ }).then(function () {
|
|
|
+ return browser.switchTo().frame(browser.findElement(by.name('ace_outer')));
|
|
|
+ }).then(function () {
|
|
|
+ return browser.wait(until.elementLocated(by.name('ace_inner')), TEST_TIMEOUT);
|
|
|
+ }).then(function () {
|
|
|
+ return browser.switchTo().frame(browser.findElement(by.name('ace_inner')));
|
|
|
+ }).then(function () {
|
|
|
+ return browser.findElement(by.xpath('//body')).sendKeys('Cloudron');
|
|
|
+ }).then(function () { // do not navigate away too fast before ep commits the text
|
|
|
+ return browser.sleep(5000);
|
|
|
+ }).then(function () {
|
|
|
+ done();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function getDocument(done) {
|
|
|
+ browser.get('https://' + app.fqdn + '/p/paddington').then(function () {
|
|
|
+ return browser.wait(function () {
|
|
|
+ return browser.getCurrentUrl().then(function (url) {
|
|
|
+ return url === 'https://' + app.fqdn + '/p/paddington';
|
|
|
+ });
|
|
|
+ }, TEST_TIMEOUT);
|
|
|
+ }).then(function () {
|
|
|
+ return browser.wait(until.elementLocated(by.name('ace_outer')), TEST_TIMEOUT);
|
|
|
+ }).then(function () {
|
|
|
+ return browser.switchTo().frame(browser.findElement(by.name('ace_outer')));
|
|
|
+ }).then(function () {
|
|
|
+ return browser.wait(until.elementLocated(by.name('ace_inner')), TEST_TIMEOUT);
|
|
|
+ }).then(function () {
|
|
|
+ return browser.switchTo().frame(browser.findElement(by.name('ace_inner')));
|
|
|
+ }).then(function () {
|
|
|
+ return browser.findElement(by.xpath('//span[text()="Cloudron"]'));
|
|
|
+ }).then(function () {
|
|
|
+ done();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function installPlugin(done) {
|
|
|
+ browser.get('https://' + app.fqdn + '/admin/plugins').then(function () {
|
|
|
+ return browser.wait(until.elementLocated(by.xpath('//a[text()="delete_after_delay"]')), TEST_TIMEOUT);
|
|
|
+ }).then(function () {
|
|
|
+ var button = browser.findElement(by.xpath('//tr[@class="ep_delete_after_delay"]//input[@class="do-install"]'));
|
|
|
+ return browser.executeScript('arguments[0].scrollIntoView(true)', button);
|
|
|
+ }).then(function () {
|
|
|
+ return browser.findElement(by.xpath('//tr[@class="ep_delete_after_delay"]//input[@class="do-install"]')).click();
|
|
|
+ }).then(function () {
|
|
|
+ return browser.wait(until.elementLocated(by.xpath('//tr[@class="ep_delete_after_delay"]//input[@class="do-uninstall"]')), TEST_TIMEOUT);
|
|
|
+ }).then(function () {
|
|
|
+ done();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function checkPlugin(done) {
|
|
|
+ browser.get('https://' + app.fqdn + '/admin/plugins').then(function () {
|
|
|
+ return browser.wait(until.elementLocated(by.xpath('//tr[@class="ep_delete_after_delay"]')), TEST_TIMEOUT);
|
|
|
+ }).then(function () {
|
|
|
+ return browser.wait(until.elementLocated(by.xpath('//tr[@class="ep_delete_after_delay"]//input[@class="do-uninstall"]')), TEST_TIMEOUT);
|
|
|
+ }).then(function () {
|
|
|
+ done();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function getApiKey(done) {
|
|
|
+ var out = execSync(util.format('cloudron exec --app %s -- cat /app/data/APIKEY.txt', app.id));
|
|
|
+ apiKey = out.toString('utf8');
|
|
|
+ console.log('apiKey is ' + apiKey);
|
|
|
+ expect(apiKey.length).to.be(64);
|
|
|
+ done();
|
|
|
+ }
|
|
|
+
|
|
|
+ function testApiAccess(done) {
|
|
|
+ superagent.get('https://' + app.fqdn + '/api/1.2.7/listAllPads').query({ apikey: apiKey }).end(function (error, result) {
|
|
|
+ expect(error).to.be(null);
|
|
|
+ expect(result.statusCode).to.be(200);
|
|
|
+ expect(result.body.data.padIDs).to.contain('paddington');
|
|
|
+ done();
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ xit('build app', function () {
|
|
|
+ execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('install app without sso', function () {
|
|
|
+ execSync('cloudron install --new --wait --no-sso --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('can get app information', getAppInfo);
|
|
|
+ it('can setup custom users', function () {
|
|
|
+ fs.writeFileSync('/tmp/settings.json', JSON.stringify({ users: { admin: { password: 'secret123', is_admin: true } } }), 'utf8');
|
|
|
+ execSync('cloudron push --app ' + app.id + ' /tmp/settings.json /app/data/settings.json', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
+ execSync('cloudron restart --wait --app ' + app.id);
|
|
|
+ });
|
|
|
+ it('can login', login.bind(null, 'admin', 'secret123'));
|
|
|
+ it('can create document', createDocument);
|
|
|
+ it('can get existing document', getDocument);
|
|
|
+ it('can install plugin', installPlugin);
|
|
|
+ it('can get api key', getApiKey);
|
|
|
+ it('can access api', testApiAccess);
|
|
|
+ it('uninstall app', function (done) {
|
|
|
+ // ensure we don't hit NXDOMAIN in the mean time
|
|
|
+ browser.get('about:blank').then(function () {
|
|
|
+ execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
+ done();
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('install app', function () {
|
|
|
+ execSync('cloudron install --new --wait --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('can get app information', getAppInfo);
|
|
|
+
|
|
|
+ it('can login', login.bind(null, username, password));
|
|
|
+ it('can create document', createDocument);
|
|
|
+ it('can get existing document', getDocument);
|
|
|
+ it('can install plugin', installPlugin);
|
|
|
+ it('can get api key', getApiKey);
|
|
|
+ it('can access api', testApiAccess);
|
|
|
+
|
|
|
+ it('can restart app', function () {
|
|
|
+ execSync('cloudron restart --wait --app ' + app.id);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('can get existing document', getDocument);
|
|
|
+ it('can check plugin', checkPlugin);
|
|
|
+ it('can access api', testApiAccess);
|
|
|
+
|
|
|
+ it('backup app', function () {
|
|
|
+ execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('restore app', function () {
|
|
|
+ execSync('cloudron restore --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('can get existing document', getDocument);
|
|
|
+ it('can check plugin', checkPlugin);
|
|
|
+ it('can access api', testApiAccess);
|
|
|
+
|
|
|
+ it('move to different location', function (done) {
|
|
|
+ browser.manage().deleteAllCookies();
|
|
|
+
|
|
|
+ // ensure we don't hit NXDOMAIN in the mean time
|
|
|
+ browser.get('about:blank').then(function () {
|
|
|
+ execSync('cloudron configure --wait --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
+
|
|
|
+ var inspect = JSON.parse(execSync('cloudron inspect'));
|
|
|
+ app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
|
|
|
+ expect(app).to.be.an('object');
|
|
|
+
|
|
|
+ done();
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('can login', login.bind(null, username, password));
|
|
|
+ it('can get existing document', getDocument);
|
|
|
+ it('can check plugin', checkPlugin);
|
|
|
+ it('can access api', testApiAccess);
|
|
|
+
|
|
|
+ it('uninstall app', function (done) {
|
|
|
+ // ensure we don't hit NXDOMAIN in the mean time
|
|
|
+ browser.get('about:blank').then(function () {
|
|
|
+ execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
+ done();
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ // test update
|
|
|
+ it('can install app', function () {
|
|
|
+ execSync('cloudron install --new --wait --appstore-id org.etherpad.cloudronapp --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('can get app information', getAppInfo);
|
|
|
+ it('can login', login.bind(null, username, password));
|
|
|
+ it('can create document', createDocument);
|
|
|
+ it('can get existing document', getDocument);
|
|
|
+ it('can install plugin', installPlugin);
|
|
|
+ it('can get api key', getApiKey);
|
|
|
+
|
|
|
+ it('can update', function () {
|
|
|
+ execSync('cloudron install --wait --app ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
+ });
|
|
|
+
|
|
|
+ it('can get existing document', getDocument);
|
|
|
+ it('can check plugin', checkPlugin);
|
|
|
+ it('can access api', testApiAccess);
|
|
|
+ it('uninstall app', function (done) {
|
|
|
+ // ensure we don't hit NXDOMAIN in the mean time
|
|
|
+ browser.get('about:blank').then(function () {
|
|
|
+ execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
+ done();
|
|
|
+ });
|
|
|
+ });
|
|
|
+});
|