|
|
|
|
@@ -1,11 +1,7 @@
|
|
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
|
|
/* jshint esversion: 8 */
|
|
|
|
|
/* global it:false */
|
|
|
|
|
/* global xit:false */
|
|
|
|
|
/* global describe:false */
|
|
|
|
|
/* global before:false */
|
|
|
|
|
/* global after:false */
|
|
|
|
|
/* global it, xit, describe, before, after, afterEach */
|
|
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
@@ -13,11 +9,11 @@ require('chromedriver');
|
|
|
|
|
|
|
|
|
|
const execSync = require('child_process').execSync,
|
|
|
|
|
expect = require('expect.js'),
|
|
|
|
|
fs = require('fs'),
|
|
|
|
|
path = require('path'),
|
|
|
|
|
{ Builder, By, Key, until } = require('selenium-webdriver'),
|
|
|
|
|
{ Options } = require('selenium-webdriver/chrome');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!process.env.USERNAME || !process.env.PASSWORD) {
|
|
|
|
|
console.log('USERNAME and PASSWORD env vars need to be set');
|
|
|
|
|
process.exit(1);
|
|
|
|
|
@@ -27,7 +23,7 @@ describe('Application life cycle test', function () {
|
|
|
|
|
this.timeout(0);
|
|
|
|
|
|
|
|
|
|
const ELEMENT_LOCATION = 'element-test';
|
|
|
|
|
const LOCATION = 'test';
|
|
|
|
|
const LOCATION = process.env.LOCATION || 'test';
|
|
|
|
|
const TEST_TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 10000;
|
|
|
|
|
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
|
|
|
|
const USERNAME = process.env.USERNAME;
|
|
|
|
|
@@ -36,22 +32,40 @@ describe('Application life cycle test', function () {
|
|
|
|
|
const ROOM_NAME = 'Test room ' + ROOM_ID;
|
|
|
|
|
const MSG_TEXT = 'Test message ';
|
|
|
|
|
|
|
|
|
|
let browser, app;
|
|
|
|
|
let athenticated_by_oidc = false;
|
|
|
|
|
let browser, app, elementApp;
|
|
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
|
const options = new Options().windowSize({ width: 1280, height: 1024 });
|
|
|
|
|
if (process.env.HEADLESS) options.addArguments('headless');
|
|
|
|
|
const chromeOptions = new Options().windowSize({ width: 1280, height: 1024 });
|
|
|
|
|
if (process.env.CI) chromeOptions.addArguments('no-sandbox', 'disable-dev-shm-usage', 'headless');
|
|
|
|
|
browser = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
|
|
|
|
|
if (!fs.existsSync('./screenshots')) fs.mkdirSync('./screenshots');
|
|
|
|
|
|
|
|
|
|
browser = new Builder().forBrowser('chrome').setChromeOptions(options).build();
|
|
|
|
|
if (process.env.CI) execSync(`cloudron uninstall --app ${ELEMENT_LOCATION} || true`, EXEC_ARGS);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
after(function () {
|
|
|
|
|
browser.quit();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function sleep(millis) {
|
|
|
|
|
return new Promise(resolve => setTimeout(resolve, millis));
|
|
|
|
|
afterEach(async function () {
|
|
|
|
|
if (!process.env.CI || !app) return;
|
|
|
|
|
|
|
|
|
|
const currentUrl = await browser.getCurrentUrl();
|
|
|
|
|
if (!currentUrl.includes(app.domain)) return;
|
|
|
|
|
expect(this.currentTest.title).to.be.a('string');
|
|
|
|
|
|
|
|
|
|
const screenshotData = await browser.takeScreenshot();
|
|
|
|
|
fs.writeFileSync(`./screenshots/${new Date().getTime()}-${this.currentTest.title.replaceAll(' ', '_')}.png`, screenshotData, 'base64');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async function clearCache() {
|
|
|
|
|
await browser.manage().deleteAllCookies();
|
|
|
|
|
await browser.quit();
|
|
|
|
|
browser = null;
|
|
|
|
|
const chromeOptions = new Options().windowSize({ width: 1280, height: 1024 });
|
|
|
|
|
if (process.env.CI) chromeOptions.addArguments('no-sandbox', 'disable-dev-shm-usage', 'headless');
|
|
|
|
|
chromeOptions.addArguments(`--user-data-dir=${await fs.promises.mkdtemp('/tmp/test-')}`); // --profile-directory=Default
|
|
|
|
|
browser = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function waitForElement(elem) {
|
|
|
|
|
@@ -67,8 +81,8 @@ describe('Application life cycle test', function () {
|
|
|
|
|
|
|
|
|
|
function getElementAppInfo() {
|
|
|
|
|
const inspect = JSON.parse(execSync('cloudron inspect'));
|
|
|
|
|
app = inspect.apps.filter(function (a) { return a.location.indexOf(ELEMENT_LOCATION) === 0; })[0];
|
|
|
|
|
expect(app).to.be.an('object');
|
|
|
|
|
elementApp = inspect.apps.filter(function (a) { return a.location.indexOf(ELEMENT_LOCATION) === 0; })[0];
|
|
|
|
|
expect(elementApp).to.be.an('object');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getMessage() {
|
|
|
|
|
@@ -80,7 +94,7 @@ describe('Application life cycle test', function () {
|
|
|
|
|
execSync(`cloudron exec --app ${ELEMENT_LOCATION} -- bash -c "jq '.default_server_config[\\"m.homeserver\\"].base_url = \\"https://${app.fqdn}\\"' /app/data/config.json | sponge /app/data/config.json"`);
|
|
|
|
|
execSync(`cloudron restart --app ${ELEMENT_LOCATION}`);
|
|
|
|
|
// wait when all services are up and running
|
|
|
|
|
await sleep(15000);
|
|
|
|
|
await browser.sleep(15000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function checkLandingPage() {
|
|
|
|
|
@@ -89,7 +103,7 @@ describe('Application life cycle test', function () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function registerUser() {
|
|
|
|
|
await browser.get(`https://${app.fqdn}/#/register`);
|
|
|
|
|
await browser.get(`https://${elementApp.fqdn}/#/register`);
|
|
|
|
|
await waitForElement(By.xpath('//input[@label="Username"]'));
|
|
|
|
|
await browser.findElement(By.xpath('//input[@label="Username"]')).sendKeys(USERNAME);
|
|
|
|
|
await browser.sleep(2000);
|
|
|
|
|
@@ -106,35 +120,29 @@ describe('Application life cycle test', function () {
|
|
|
|
|
await waitForElement(By.xpath(`//h1[contains(., "Welcome")]`));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function loginOIDC(username, password) {
|
|
|
|
|
async function loginOIDC(username, password, hasSession, proceedWithReset) {
|
|
|
|
|
browser.manage().deleteAllCookies();
|
|
|
|
|
await browser.get(`https://${app.fqdn}/#/login`);
|
|
|
|
|
await browser.get(`https://${elementApp.fqdn}/#/login`);
|
|
|
|
|
await browser.sleep(6000);
|
|
|
|
|
|
|
|
|
|
await waitForElement(By.xpath('//div[@role="button" and contains(., "Continue with Cloudron")]'));
|
|
|
|
|
await browser.findElement(By.xpath('//div[@role="button" and contains(., "Continue with Cloudron")]')).click();
|
|
|
|
|
await browser.sleep(2000);
|
|
|
|
|
|
|
|
|
|
if (!athenticated_by_oidc) {
|
|
|
|
|
if (!hasSession) {
|
|
|
|
|
await waitForElement(By.xpath('//input[@name="username"]'));
|
|
|
|
|
await browser.findElement(By.xpath('//input[@name="username"]')).sendKeys(username);
|
|
|
|
|
await browser.findElement(By.xpath('//input[@name="password"]')).sendKeys(password);
|
|
|
|
|
await browser.sleep(2000);
|
|
|
|
|
await browser.findElement(By.id('loginSubmitButton')).click();
|
|
|
|
|
await browser.sleep(2000);
|
|
|
|
|
|
|
|
|
|
athenticated_by_oidc = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await waitForElement(By.xpath('//p[@class="confirm-trust" and contains(., "Continuing will grant ")]'));
|
|
|
|
|
await browser.findElement(By.xpath('//a[contains(., "Continue")]')).click();
|
|
|
|
|
await browser.sleep(2000);
|
|
|
|
|
|
|
|
|
|
//if (await browser.findElements(By.xpath('//div[@aria-label="Skip verification for now"]')).then(found => !!found.length)) {
|
|
|
|
|
// await skipVerification();
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
if (await browser.findElements(By.xpath('//div[text()="Proceed with reset"]')).then(found => !!found.length)) {
|
|
|
|
|
if (proceedWithReset) {
|
|
|
|
|
await browser.findElement(By.xpath('//div[text()="Proceed with reset"]')).click();
|
|
|
|
|
|
|
|
|
|
await waitForElement(By.xpath('//button[text()="Continue"]'));
|
|
|
|
|
@@ -160,17 +168,13 @@ describe('Application life cycle test', function () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function login() {
|
|
|
|
|
await browser.get('https://' + app.fqdn + '/#/login');
|
|
|
|
|
await browser.get(`https://${elementApp.fqdn}/#/login`);
|
|
|
|
|
await browser.wait(until.elementLocated(By.xpath('//input[@value="Sign in"]')), TEST_TIMEOUT);
|
|
|
|
|
await browser.findElement(By.xpath('//input[@name="username"]')).sendKeys(USERNAME);
|
|
|
|
|
await browser.findElement(By.xpath('//input[@name="password"]')).sendKeys(PASSWORD);
|
|
|
|
|
await browser.findElement(By.xpath('//input[@value="Sign in"]')).click();
|
|
|
|
|
await browser.sleep(5000);
|
|
|
|
|
|
|
|
|
|
if (await browser.findElements(By.xpath('//div[@aria-label="Skip verification for now"]')).then(found => !!found.length)) {
|
|
|
|
|
await skipVerification();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await skipVerification();
|
|
|
|
|
await browser.wait(until.elementLocated(By.xpath('//span[text()="Rooms"]')), TEST_TIMEOUT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -185,7 +189,7 @@ describe('Application life cycle test', function () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function logout() {
|
|
|
|
|
await browser.get('https://' + app.fqdn + '/#/home');
|
|
|
|
|
await browser.get(`https://${elementApp.fqdn}/#/home`);
|
|
|
|
|
await browser.sleep(5000);
|
|
|
|
|
await waitForElement(By.xpath('//div[@role="button" and @aria-label="User menu"]'));
|
|
|
|
|
|
|
|
|
|
@@ -195,21 +199,21 @@ describe('Application life cycle test', function () {
|
|
|
|
|
await browser.findElement(By.xpath('//li[@role="menuitem" and @aria-label="Sign out"]')).click();
|
|
|
|
|
await browser.sleep(2000);
|
|
|
|
|
|
|
|
|
|
// if (await browser.findElements(By.xpath('//button[contains(text(), "I don\'t want my encrypted messages")]')).then(found => !!found.length)) {
|
|
|
|
|
if (await browser.findElements(By.xpath('//button[contains(text(), "I don\'t want my encrypted messages")]')).then(found => !!found.length)) {
|
|
|
|
|
await browser.findElement(By.xpath('//button[contains(text(), "I don\'t want my encrypted messages")]')).click();
|
|
|
|
|
await browser.sleep(3000);
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await waitForElement(By.xpath('//h1[text()="Sign in"]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function isLoggedIn() {
|
|
|
|
|
await browser.get('https://' + app.fqdn + '/#/home');
|
|
|
|
|
await browser.get(`https://${elementApp.fqdn}/#/home`);
|
|
|
|
|
await browser.wait(until.elementLocated(By.xpath('//span[text()="Rooms"]')), TEST_TIMEOUT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function createRoom() {
|
|
|
|
|
await browser.get('https://' + app.fqdn + '/#/home');
|
|
|
|
|
await browser.get(`https://${elementApp.fqdn}/#/home`);
|
|
|
|
|
await browser.sleep(4000);
|
|
|
|
|
await waitForElement(By.xpath('//div[@role="button" and @aria-label="Add room"]'));
|
|
|
|
|
await browser.findElement(By.xpath('//div[@role="button" and @aria-label="Add room"]')).click();
|
|
|
|
|
@@ -229,7 +233,7 @@ describe('Application life cycle test', function () {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function checkRoom() {
|
|
|
|
|
await browser.get('https://' + app.fqdn + '/#/home');
|
|
|
|
|
await browser.get(`https://${elementApp.fqdn}/#/home`);
|
|
|
|
|
await browser.sleep(4000);
|
|
|
|
|
await waitForElement(By.xpath('//div[@role="treeitem" and @aria-label="' + ROOM_NAME + '"]'));
|
|
|
|
|
await browser.findElement(By.xpath('//div[@role="treeitem" and @aria-label="' + ROOM_NAME + '"]')).click();
|
|
|
|
|
@@ -261,15 +265,12 @@ describe('Application life cycle test', function () {
|
|
|
|
|
it('can register new user', registerUser);
|
|
|
|
|
it('create room', createRoom);
|
|
|
|
|
it('can send message', sendMessage);
|
|
|
|
|
|
|
|
|
|
it('can logout', logout);
|
|
|
|
|
it('can logout', logout); // from auto-login
|
|
|
|
|
|
|
|
|
|
it('can login', login);
|
|
|
|
|
it('check room', checkRoom);
|
|
|
|
|
it('can logout', logout);
|
|
|
|
|
|
|
|
|
|
it('can get app info', getAppInfo);
|
|
|
|
|
|
|
|
|
|
it('uninstall element-web app', async function () {
|
|
|
|
|
await browser.get('about:blank');
|
|
|
|
|
execSync(`cloudron uninstall --app ${ELEMENT_LOCATION}`, EXEC_ARGS);
|
|
|
|
|
@@ -281,10 +282,10 @@ describe('Application life cycle test', function () {
|
|
|
|
|
it('can get app info', getAppInfo);
|
|
|
|
|
|
|
|
|
|
it('can install element-web app (sso)', function () { execSync('cloudron install --appstore-id im.riot.cloudronapp --location ' + ELEMENT_LOCATION, EXEC_ARGS); });
|
|
|
|
|
it('can get Element app info', getElementAppInfo);
|
|
|
|
|
it('update element-app config', updateSynapseConfig);
|
|
|
|
|
|
|
|
|
|
it('can get Element app info', getElementAppInfo);
|
|
|
|
|
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD));
|
|
|
|
|
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD, false, false /* proceedWithReset */));
|
|
|
|
|
it('create room', createRoom);
|
|
|
|
|
it('can send message', sendMessage);
|
|
|
|
|
it('can get app info', getAppInfo);
|
|
|
|
|
@@ -293,10 +294,8 @@ describe('Application life cycle test', function () {
|
|
|
|
|
|
|
|
|
|
it('backup app', function () { execSync(`cloudron backup create --app ${app.id}`, EXEC_ARGS); });
|
|
|
|
|
|
|
|
|
|
it('can get Element app info', getElementAppInfo);
|
|
|
|
|
it('is logged in', isLoggedIn);
|
|
|
|
|
it('check room', checkRoom);
|
|
|
|
|
it('can get app info', getAppInfo);
|
|
|
|
|
|
|
|
|
|
it('restore app', async function () {
|
|
|
|
|
const backups = JSON.parse(execSync(`cloudron backup list --raw --app ${app.id}`));
|
|
|
|
|
@@ -310,7 +309,6 @@ describe('Application life cycle test', function () {
|
|
|
|
|
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can get Element app info', getElementAppInfo);
|
|
|
|
|
it('is logged in', isLoggedIn);
|
|
|
|
|
it('check room', checkRoom);
|
|
|
|
|
it('can send message', sendMessage);
|
|
|
|
|
@@ -323,50 +321,49 @@ describe('Application life cycle test', function () {
|
|
|
|
|
|
|
|
|
|
execSync(`cloudron configure --location ${LOCATION}2`, EXEC_ARGS);
|
|
|
|
|
getAppInfo();
|
|
|
|
|
// wait when all services are up and running
|
|
|
|
|
await sleep(15000);
|
|
|
|
|
await browser.sleep(15000);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('update element-app config', updateSynapseConfig);
|
|
|
|
|
|
|
|
|
|
it('can get Element app info', getElementAppInfo);
|
|
|
|
|
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD));
|
|
|
|
|
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD, true, true /* proceedWithReset */));
|
|
|
|
|
it('check room', checkRoom);
|
|
|
|
|
it('can send message', sendMessage);
|
|
|
|
|
|
|
|
|
|
it('can logout', logout);
|
|
|
|
|
it('can get app info', getAppInfo);
|
|
|
|
|
|
|
|
|
|
it('uninstall app', async function () {
|
|
|
|
|
await browser.get('about:blank');
|
|
|
|
|
execSync(`cloudron uninstall --app ${app.id}`, EXEC_ARGS);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('uninstall element-web app', function () {
|
|
|
|
|
execSync(`cloudron uninstall --app ${ELEMENT_LOCATION}`, EXEC_ARGS);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// test update
|
|
|
|
|
it('clear cache', clearCache);
|
|
|
|
|
it('can install app for update', function () { execSync('cloudron install --appstore-id org.matrix.synapse --location ' + LOCATION, EXEC_ARGS); });
|
|
|
|
|
it('can install element-web app (update)', function () { execSync('cloudron install --appstore-id im.riot.cloudronapp --location ' + ELEMENT_LOCATION, EXEC_ARGS); });
|
|
|
|
|
|
|
|
|
|
it('can get app info', getAppInfo);
|
|
|
|
|
it('update element-app config', updateSynapseConfig);
|
|
|
|
|
|
|
|
|
|
it('can install element-web app (update)', function () { execSync('cloudron install --appstore-id im.riot.cloudronapp --location ' + ELEMENT_LOCATION, EXEC_ARGS); });
|
|
|
|
|
it('can get Element app info', getElementAppInfo);
|
|
|
|
|
|
|
|
|
|
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD));
|
|
|
|
|
it('update element-app config', updateSynapseConfig);
|
|
|
|
|
|
|
|
|
|
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD, false, false /* proceedWithReset */));
|
|
|
|
|
it('is logged in', isLoggedIn);
|
|
|
|
|
it('create room', createRoom);
|
|
|
|
|
it('can send message', sendMessage);
|
|
|
|
|
it('can logout', logout);
|
|
|
|
|
it('can get app info', getAppInfo);
|
|
|
|
|
|
|
|
|
|
it('can update', async function () {
|
|
|
|
|
await browser.get('about:blank');
|
|
|
|
|
execSync(`cloudron update --app ${app.id}`, EXEC_ARGS);
|
|
|
|
|
// wait when all services are up and running
|
|
|
|
|
await sleep(15000);
|
|
|
|
|
await browser.sleep(15000);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('can get Element app info', getElementAppInfo);
|
|
|
|
|
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD));
|
|
|
|
|
it('can login via OIDC', loginOIDC.bind(null, USERNAME, PASSWORD, true, true /* proceedWithReset */));
|
|
|
|
|
it('is logged in', isLoggedIn);
|
|
|
|
|
it('check room', checkRoom);
|
|
|
|
|
it('can send message', sendMessage);
|
|
|
|
|
|