2020-07-21 20:46:54 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
/* jslint node:true */
|
|
|
|
/* global it:false */
|
|
|
|
/* global xit:false */
|
|
|
|
/* global describe:false */
|
|
|
|
/* global before:false */
|
|
|
|
/* global after:false */
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
require('chromedriver');
|
|
|
|
|
|
|
|
var execSync = require('child_process').execSync,
|
|
|
|
expect = require('expect.js'),
|
|
|
|
path = require('path'),
|
2021-01-07 16:21:38 +00:00
|
|
|
util = require('util'),
|
|
|
|
{ Builder, By, Key, until } = require('selenium-webdriver'),
|
|
|
|
{ Options } = require('selenium-webdriver/chrome');
|
2020-07-21 20:46:54 +00:00
|
|
|
|
|
|
|
if (!process.env.USERNAME || !process.env.PASSWORD || !process.env.EMAIL) {
|
|
|
|
console.log('USERNAME, EMAIL and PASSWORD env vars need to be set');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Application life cycle test', function () {
|
|
|
|
this.timeout(0);
|
|
|
|
|
2021-01-07 16:21:38 +00:00
|
|
|
var LOCATION = 'test';
|
|
|
|
var TEST_TIMEOUT = parseInt(process.env.TEST_TIMEOUT, 10) || 30000;
|
|
|
|
|
|
|
|
var browser;
|
|
|
|
var app;
|
2020-10-15 04:45:44 +00:00
|
|
|
var username = process.env.USERNAME;
|
|
|
|
var password = process.env.PASSWORD;
|
2020-07-21 20:46:54 +00:00
|
|
|
var email = process.env.EMAIL;
|
|
|
|
|
2021-01-07 16:21:38 +00:00
|
|
|
before(function () {
|
|
|
|
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
|
2020-07-21 20:46:54 +00:00
|
|
|
});
|
|
|
|
|
2021-01-07 16:21:38 +00:00
|
|
|
after(function () {
|
2020-07-21 20:46:54 +00:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
2020-10-15 04:45:44 +00:00
|
|
|
function login(username, password, done) {
|
2020-07-21 20:46:54 +00:00
|
|
|
browser.get('https://' + app.fqdn + '/login').then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
return browser.wait(until.elementLocated(By.id('username')), TEST_TIMEOUT);
|
2020-07-21 20:46:54 +00:00
|
|
|
}).then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
return browser.findElement(By.id('username')).sendKeys(username);
|
2020-07-21 20:46:54 +00:00
|
|
|
}).then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
return browser.findElement(By.id('password')).sendKeys(password);
|
2020-07-21 20:46:54 +00:00
|
|
|
}).then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
return browser.findElement(By.xpath('//input[@value="Login"]')).click();
|
2020-07-21 20:46:54 +00:00
|
|
|
}).then(function () {
|
2021-09-13 18:11:06 +00:00
|
|
|
if (app.version === '2.4.0') {
|
|
|
|
return browser.wait(until.elementLocated(By.xpath('//a[contains(@href, "/my-library")]')), TEST_TIMEOUT);
|
|
|
|
} else {
|
|
|
|
return browser.wait(until.elementLocated(By.xpath('//div[contains(text(), "MY LIBRARY")]')), TEST_TIMEOUT);
|
|
|
|
}
|
2020-07-21 20:46:54 +00:00
|
|
|
}).then(function () {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-15 04:45:44 +00:00
|
|
|
function logout(done) {
|
|
|
|
browser.get('https://' + app.fqdn + '/my-account/videos').then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
return browser.wait(until.elementLocated(By.xpath('//div[@class="logged-in-display-name"]')), TEST_TIMEOUT);
|
|
|
|
}).then(function () {
|
|
|
|
return browser.sleep(2000);
|
2020-10-15 04:45:44 +00:00
|
|
|
}).then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
return browser.findElement(By.xpath('//div[@class="logged-in-display-name"]')).click();
|
2020-10-15 04:45:44 +00:00
|
|
|
}).then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
return browser.sleep(2000);
|
2020-10-15 04:45:44 +00:00
|
|
|
}).then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
return browser.findElement(By.xpath('//a[contains(text(), "Log out")]')).click();
|
2020-10-15 04:45:44 +00:00
|
|
|
}).then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
return browser.sleep(2000);
|
2020-10-15 04:45:44 +00:00
|
|
|
}).then(function () {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-21 22:30:01 +00:00
|
|
|
function completeSetup(done) {
|
|
|
|
var button;
|
|
|
|
|
|
|
|
browser.get('https://' + app.fqdn + '/admin/config/edit-custom').then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
return browser.wait(until.elementLocated(By.xpath('//a[contains(text(), "Configure my instance")]')), TEST_TIMEOUT);
|
2020-07-21 22:30:01 +00:00
|
|
|
}).then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
return browser.findElement(By.xpath('//a[contains(text(), "Configure my instance")]')).click(); // this opens a new window
|
2020-07-21 22:30:01 +00:00
|
|
|
}).then(function () {
|
|
|
|
return browser.get('https://' + app.fqdn + '/admin/config/edit-custom');
|
|
|
|
}).then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
return browser.wait(until.elementLocated(By.xpath('//input[contains(@value, "Update configuration")]')), TEST_TIMEOUT);
|
2020-07-21 22:30:01 +00:00
|
|
|
}).then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
button = browser.findElement(By.xpath('//input[contains(@value, "Update configuration")]'));
|
2020-07-21 22:30:01 +00:00
|
|
|
return browser.executeScript('arguments[0].scrollIntoView(true)', button);
|
|
|
|
}).then(function () {
|
|
|
|
return button.click();
|
|
|
|
}).then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
return browser.wait(until.elementLocated(By.xpath('//h3[contains(text(), "Success")]')), TEST_TIMEOUT);
|
2020-07-21 22:30:01 +00:00
|
|
|
}).then(function () {
|
|
|
|
console.log('Close the newly opened tab. Will wait for 20 seconds');
|
|
|
|
return browser.sleep(20000);
|
|
|
|
}).then(function () {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function uploadVideo(done) {
|
|
|
|
browser.get('https://' + app.fqdn + '/videos/upload').then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
return browser.findElement(By.xpath('//input[@id="videofile" and @type="file"]')).sendKeys(path.resolve(__dirname, './Cloudron Test Video.mp4'));
|
2020-07-21 22:30:01 +00:00
|
|
|
}).then(function () {
|
|
|
|
return browser.sleep(20000); // wait for upload
|
|
|
|
}).then(function () {
|
2021-01-07 16:21:38 +00:00
|
|
|
return browser.findElement(By.xpath('//span[text()="Publish"]')).click();
|
2020-07-21 22:30:01 +00:00
|
|
|
}).then(function () {
|
|
|
|
return browser.sleep(2000);
|
|
|
|
}).then(function () {
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function videoExists(done) {
|
|
|
|
browser.get('https://' + app.fqdn + '/my-account/videos').then(function () {
|
2021-06-03 03:17:59 +00:00
|
|
|
return browser.wait(until.elementLocated(By.xpath('//a[contains(@title, "Cloudron Test Video")]')), TEST_TIMEOUT);
|
2020-07-21 22:30:01 +00:00
|
|
|
}).then(function () {
|
|
|
|
return done();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-21 20:46:54 +00:00
|
|
|
xit('build app', function () {
|
|
|
|
execSync('cloudron build', { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
|
2020-07-21 22:30:01 +00:00
|
|
|
it('install app', function (done) {
|
2020-07-21 20:46:54 +00:00
|
|
|
execSync('cloudron install --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
2020-10-15 02:21:43 +00:00
|
|
|
setTimeout(done, 20000); // takes a bit to create root user in background
|
2020-07-21 20:46:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can get app information', getAppInfo);
|
2020-10-15 04:45:44 +00:00
|
|
|
it('can root login', login.bind(null, 'root', 'changeme'));
|
2021-01-07 19:50:44 +00:00
|
|
|
it('can complete setup', completeSetup);
|
2020-07-21 22:30:01 +00:00
|
|
|
it('can upload video', uploadVideo);
|
|
|
|
it('video exists', videoExists);
|
2020-10-15 04:45:44 +00:00
|
|
|
it('logout', logout);
|
|
|
|
|
|
|
|
it('can login', login.bind(null, username, password));
|
|
|
|
it('logout', logout);
|
2020-07-21 20:46:54 +00:00
|
|
|
|
|
|
|
it('backup app', function () {
|
|
|
|
execSync('cloudron backup create --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
|
|
|
|
it('restore app', function () {
|
|
|
|
const backups = JSON.parse(execSync('cloudron backup list --raw'));
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
execSync('cloudron install --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
getAppInfo();
|
|
|
|
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
|
2020-10-15 04:45:44 +00:00
|
|
|
it('can root login', login.bind(null, 'root', 'changeme'));
|
2020-07-21 22:30:01 +00:00
|
|
|
it('video exists', videoExists);
|
2020-10-15 04:45:44 +00:00
|
|
|
it('logout', logout);
|
|
|
|
|
|
|
|
it('can login', login.bind(null, username, password));
|
|
|
|
it('logout', logout);
|
2020-07-21 20:46:54 +00:00
|
|
|
|
|
|
|
it('can restart app', function () {
|
|
|
|
execSync('cloudron restart --app ' + app.id);
|
|
|
|
});
|
2020-10-15 04:45:44 +00:00
|
|
|
it('can root login', login.bind(null, 'root', 'changeme'));
|
2020-07-21 22:30:01 +00:00
|
|
|
it('video exists', videoExists);
|
2020-10-15 04:45:44 +00:00
|
|
|
it('logout', logout);
|
|
|
|
|
|
|
|
it('can login', login.bind(null, username, password));
|
|
|
|
it('logout', logout);
|
2020-07-21 20:46:54 +00:00
|
|
|
|
2020-07-21 22:30:01 +00:00
|
|
|
// this is not supported for federation
|
2020-07-21 20:46:54 +00:00
|
|
|
it('move to different location', function (done) {
|
|
|
|
execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can get app information', getAppInfo);
|
2020-10-15 04:45:44 +00:00
|
|
|
it('can root login', login.bind(null, 'root', 'changeme'));
|
2020-07-21 22:30:01 +00:00
|
|
|
it('video exists', videoExists);
|
2020-10-15 04:45:44 +00:00
|
|
|
it('logout', logout);
|
|
|
|
|
|
|
|
it('can login', login.bind(null, username, password));
|
|
|
|
it('logout', logout);
|
2020-07-21 20:46:54 +00:00
|
|
|
|
|
|
|
it('uninstall app', function () {
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
|
2020-10-15 04:45:44 +00:00
|
|
|
// No SSO
|
|
|
|
it('install app (no sso)', function (done) {
|
|
|
|
execSync('cloudron install --no-sso --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
setTimeout(done, 20000); // takes a bit to create root user in background
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can get app information', function () {
|
|
|
|
var inspect = JSON.parse(execSync('cloudron inspect'));
|
|
|
|
|
|
|
|
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
|
|
|
|
|
|
|
|
expect(app).to.be.an('object');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can login (no sso)', login.bind(null, 'root', 'changeme'));
|
|
|
|
it('can complete setup', completeSetup);
|
|
|
|
it('can logout', logout);
|
|
|
|
|
|
|
|
it('uninstall app (no sso)', function () {
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
|
2020-07-21 20:46:54 +00:00
|
|
|
// test update
|
2020-10-15 04:45:44 +00:00
|
|
|
it('can install app', function (done) {
|
2020-07-21 20:46:54 +00:00
|
|
|
execSync('cloudron install --appstore-id ' + app.manifest.id + ' --location ' + LOCATION, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
2020-10-15 04:45:44 +00:00
|
|
|
setTimeout(done, 20000); // takes a bit to create root user in background
|
2020-07-21 20:46:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('can get app information', getAppInfo);
|
2021-01-07 16:21:38 +00:00
|
|
|
it('can root login', login.bind(null, 'root', 'changeme'));
|
2020-07-21 22:30:01 +00:00
|
|
|
it('can complete setup', completeSetup);
|
|
|
|
it('can upload video', uploadVideo);
|
|
|
|
it('video exists', videoExists);
|
2020-07-21 20:46:54 +00:00
|
|
|
|
|
|
|
it('can update', function () {
|
|
|
|
execSync('cloudron update --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
2021-01-07 16:21:38 +00:00
|
|
|
it('can root login', login.bind(null, 'root', 'changeme'));
|
2020-07-21 22:30:01 +00:00
|
|
|
it('video exists', videoExists);
|
2020-10-15 04:45:44 +00:00
|
|
|
it('logout', logout);
|
|
|
|
|
|
|
|
it('can login', login.bind(null, username, password));
|
|
|
|
it('logout', logout);
|
2020-07-21 20:46:54 +00:00
|
|
|
|
|
|
|
it('uninstall app', function () {
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' });
|
|
|
|
});
|
|
|
|
});
|