2019-07-18 00:16:01 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2021-05-17 18:12:12 +00:00
|
|
|
/* jshint esversion: 8 */
|
|
|
|
/* global describe */
|
|
|
|
/* global before */
|
|
|
|
/* global after */
|
2024-10-08 13:34:33 +00:00
|
|
|
/* global afterEach */
|
2021-05-17 18:12:12 +00:00
|
|
|
/* global it */
|
2021-09-23 19:02:43 +00:00
|
|
|
/* global xit */
|
2019-07-18 00:16:01 +00:00
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
require('chromedriver');
|
|
|
|
|
2021-09-23 18:37:38 +00:00
|
|
|
const execSync = require('child_process').execSync,
|
2019-07-18 00:16:01 +00:00
|
|
|
expect = require('expect.js'),
|
2024-10-08 13:34:33 +00:00
|
|
|
fs = require('fs'),
|
2021-05-17 18:12:12 +00:00
|
|
|
path = require('path'),
|
2021-09-23 18:37:38 +00:00
|
|
|
{ Builder, By, until } = require('selenium-webdriver'),
|
2021-05-17 18:12:12 +00:00
|
|
|
{ Options } = require('selenium-webdriver/chrome');
|
2019-07-18 00:16:01 +00:00
|
|
|
|
2021-05-17 18:12:12 +00:00
|
|
|
if (!process.env.USERNAME || !process.env.PASSWORD) {
|
|
|
|
console.log('USERNAME and PASSWORD env vars need to be set');
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2019-07-18 00:16:01 +00:00
|
|
|
|
|
|
|
describe('Application life cycle test', function () {
|
|
|
|
this.timeout(0);
|
|
|
|
|
2024-10-08 13:34:33 +00:00
|
|
|
const LOCATION = process.env.LOCATION || 'test';
|
2022-11-15 09:47:36 +00:00
|
|
|
const TEST_TIMEOUT = parseInt(process.env.TIMEOUT) || 10000;
|
2021-05-17 18:12:12 +00:00
|
|
|
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
|
2019-07-18 00:16:01 +00:00
|
|
|
|
2021-05-17 18:12:12 +00:00
|
|
|
let browser, app;
|
2024-10-18 20:58:16 +00:00
|
|
|
const username = process.env.USERNAME;
|
|
|
|
const password = process.env.PASSWORD;
|
2019-07-18 00:16:01 +00:00
|
|
|
|
2021-05-17 18:12:12 +00:00
|
|
|
before(function () {
|
2024-10-08 13:34:33 +00:00
|
|
|
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');
|
2019-07-18 00:16:01 +00:00
|
|
|
});
|
|
|
|
|
2021-05-17 18:12:12 +00:00
|
|
|
after(function () {
|
2019-07-18 00:16:01 +00:00
|
|
|
browser.quit();
|
|
|
|
});
|
|
|
|
|
2024-10-08 13:34:33 +00:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2024-02-14 10:13:42 +00:00
|
|
|
async function waitForElement(elem) {
|
|
|
|
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
|
|
|
|
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
2022-11-15 09:47:36 +00:00
|
|
|
async function exists(selector) {
|
|
|
|
await browser.wait(until.elementLocated(selector), TEST_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function visible(selector) {
|
|
|
|
await exists(selector);
|
|
|
|
await browser.wait(until.elementIsVisible(browser.findElement(selector)), TEST_TIMEOUT);
|
|
|
|
}
|
|
|
|
|
2021-09-23 18:37:38 +00:00
|
|
|
async function checkRegistration(mode) {
|
2023-09-22 02:43:33 +00:00
|
|
|
if (mode === 'none') {
|
2022-11-15 09:47:36 +00:00
|
|
|
await browser.get('https://' + app.fqdn);
|
|
|
|
await browser.sleep(2000);
|
2024-02-14 10:13:42 +00:00
|
|
|
await browser.findElement(By.xpath('//div[@class="sign-in-banner"]/descendant::button/span[contains(text(), "Create account")] | //div[@class="sign-in-banner"]/descendant::a/span[contains(text(), "Create account")]')).click();
|
2022-11-15 09:47:36 +00:00
|
|
|
await visible(By.xpath('//span[contains(text()[2], "is currently not possible")]'));
|
2021-09-23 18:37:38 +00:00
|
|
|
} else if (mode === 'open') {
|
2022-11-15 09:47:36 +00:00
|
|
|
await browser.get('https://' + app.fqdn + '/auth/sign_up');
|
|
|
|
await visible(By.xpath('//button[contains(text(), "Sign up")]'));
|
2021-09-23 18:37:38 +00:00
|
|
|
}
|
2019-07-18 19:32:04 +00:00
|
|
|
}
|
|
|
|
|
2021-09-23 18:37:38 +00:00
|
|
|
async function login(username, password) {
|
|
|
|
await browser.get('https://' + app.fqdn + '/auth/sign_in'); // there is also separate login page at /users/sign_in
|
2023-09-22 02:43:33 +00:00
|
|
|
await visible(By.xpath('//button[contains(text(), "Log in")]'));
|
2021-09-23 18:37:38 +00:00
|
|
|
await browser.findElement(By.id('user_email')).sendKeys(username);
|
|
|
|
await browser.findElement(By.id('user_password')).sendKeys(password);
|
|
|
|
await browser.findElement(By.xpath('//button[contains(text(), "Log in")]')).click();
|
|
|
|
await browser.sleep(3000); // can be wizard or timeline at this point
|
2020-01-23 20:56:15 +00:00
|
|
|
}
|
|
|
|
|
2024-10-18 20:58:16 +00:00
|
|
|
async function loginOIDC(username, password, hasSession) {
|
2024-02-14 10:13:42 +00:00
|
|
|
browser.manage().deleteAllCookies();
|
|
|
|
await browser.get(`https://${app.fqdn}/auth/sign_in`);
|
|
|
|
await browser.sleep(4000);
|
|
|
|
|
|
|
|
await browser.findElement(By.xpath('//a[contains(@class, "button") and text()="Cloudron"]')).click();
|
|
|
|
await browser.sleep(4000);
|
|
|
|
|
2024-10-18 20:58:16 +00:00
|
|
|
if (!hasSession) {
|
2024-02-14 10:13:42 +00:00
|
|
|
await waitForElement(By.xpath('//input[@name="username"]'));
|
2024-10-18 20:58:16 +00:00
|
|
|
await browser.findElement(By.xpath('//input[@name="username"]')).sendKeys(username);
|
2024-02-14 10:13:42 +00:00
|
|
|
await browser.findElement(By.xpath('//input[@name="password"]')).sendKeys(password);
|
|
|
|
await browser.sleep(2000);
|
2024-02-14 13:30:06 +00:00
|
|
|
await browser.findElement(By.id('loginSubmitButton')).click();
|
2024-02-14 10:13:42 +00:00
|
|
|
await browser.sleep(2000);
|
|
|
|
}
|
|
|
|
|
2024-10-18 20:58:16 +00:00
|
|
|
await waitForElement(By.xpath('//span[contains(., "Bookmarks")] | //strong[text()="Successfully authenticated from Cloudron account."]'));
|
2024-02-14 10:13:42 +00:00
|
|
|
}
|
|
|
|
|
2021-09-23 18:37:38 +00:00
|
|
|
async function logout() {
|
|
|
|
await browser.get('https://' + app.fqdn + '/settings/preferences/appearance'); // there is also separate login page at /users/sign_in
|
|
|
|
await browser.wait(until.elementLocated(By.id('logout')), TEST_TIMEOUT);
|
|
|
|
await browser.findElement(By.id('logout')).click();
|
2023-09-22 02:43:33 +00:00
|
|
|
await visible(By.id('user_email'));
|
2021-05-17 18:12:12 +00:00
|
|
|
}
|
|
|
|
|
2021-09-23 18:37:38 +00:00
|
|
|
async function checkTimeline() {
|
2022-11-15 09:47:36 +00:00
|
|
|
await browser.get('https://' + app.fqdn + '/home');
|
2023-09-22 02:43:33 +00:00
|
|
|
await visible(By.xpath('//span[contains(text(), "Your home timeline is empty")]'));
|
2019-07-18 19:32:04 +00:00
|
|
|
}
|
|
|
|
|
2020-08-16 09:04:41 +00:00
|
|
|
function getAppInfo() {
|
2023-09-22 02:43:33 +00:00
|
|
|
const inspect = JSON.parse(execSync('cloudron inspect'));
|
2020-08-16 09:04:41 +00:00
|
|
|
app = inspect.apps.filter(function (a) { return a.location === LOCATION || a.location === LOCATION + '2'; })[0];
|
|
|
|
expect(app).to.be.an('object');
|
|
|
|
}
|
2019-07-18 00:16:01 +00:00
|
|
|
|
2020-08-16 09:04:41 +00:00
|
|
|
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
|
2024-02-14 10:13:42 +00:00
|
|
|
|
|
|
|
// No SSO
|
|
|
|
it('install app (no sso)', function () { execSync('cloudron install --no-sso --location ' + LOCATION, EXEC_ARGS); });
|
|
|
|
it('can get app information', getAppInfo);
|
|
|
|
|
2024-02-23 15:45:18 +00:00
|
|
|
it('has registration open', checkRegistration.bind(null, 'none'));
|
2024-02-14 10:13:42 +00:00
|
|
|
let testPassword;
|
|
|
|
it('create a user with CLI', function () {
|
2024-10-18 20:58:16 +00:00
|
|
|
const output = execSync('cloudron exec --app ' + LOCATION + ' -- bin/tootctl accounts create test --email=test@cloudron.io', { cwd: path.resolve(__dirname, '..'), encoding: 'utf8' });
|
2024-02-14 10:13:42 +00:00
|
|
|
console.log(output);
|
|
|
|
testPassword = output.slice(output.indexOf('New password: ') + 'New password: '.length).trim();
|
|
|
|
console.log(testPassword);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can login (no sso)', async function () {
|
|
|
|
await login('test@cloudron.io', testPassword);
|
|
|
|
});
|
|
|
|
|
2024-10-16 07:41:14 +00:00
|
|
|
it('shows confirmation page', async function () {
|
|
|
|
await waitForElement(By.xpath('//a[@href="/auth/confirmation/new"]'));
|
2024-02-14 10:13:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('uninstall app (no sso)', async function () {
|
|
|
|
await browser.get('about:blank');
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
|
|
|
|
});
|
|
|
|
|
|
|
|
// SSO
|
|
|
|
it('install app (sso)', function () { execSync('cloudron install --location ' + LOCATION, EXEC_ARGS); });
|
2019-07-18 00:16:01 +00:00
|
|
|
|
2020-08-16 09:04:41 +00:00
|
|
|
it('can get app information', getAppInfo);
|
2019-07-18 19:32:04 +00:00
|
|
|
it('registration is disabled', checkRegistration.bind(null, 'none'));
|
2024-10-18 20:58:16 +00:00
|
|
|
it('can OIDC login', loginOIDC.bind(null, username, password, false));
|
2019-07-18 19:32:04 +00:00
|
|
|
it('can see timeline', checkTimeline);
|
2021-09-23 19:00:17 +00:00
|
|
|
it('can logout', logout);
|
2019-07-18 00:16:01 +00:00
|
|
|
|
2021-09-23 19:00:17 +00:00
|
|
|
it('backup app', function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); });
|
2021-09-23 18:37:38 +00:00
|
|
|
it('restore app', function () {
|
|
|
|
const backups = JSON.parse(execSync('cloudron backup list --raw'));
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
|
|
|
|
execSync('cloudron install --location ' + LOCATION, EXEC_ARGS);
|
|
|
|
getAppInfo();
|
|
|
|
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS);
|
|
|
|
});
|
2019-07-18 00:16:01 +00:00
|
|
|
|
2024-10-18 20:58:16 +00:00
|
|
|
it('can OIDC login', loginOIDC.bind(null, username, password, true));
|
2019-07-18 19:32:04 +00:00
|
|
|
it('can see timeline', checkTimeline);
|
2019-07-18 00:16:01 +00:00
|
|
|
|
2020-08-16 09:04:41 +00:00
|
|
|
it('can restart app', function () { execSync('cloudron restart --app ' + app.id, EXEC_ARGS); });
|
2019-07-18 19:32:04 +00:00
|
|
|
it('can see timeline', checkTimeline);
|
2019-07-18 00:16:01 +00:00
|
|
|
|
2021-05-17 18:12:12 +00:00
|
|
|
it('move to different location', async function () {
|
|
|
|
await browser.get('about:blank');
|
|
|
|
execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, EXEC_ARGS);
|
|
|
|
});
|
2020-08-16 09:04:41 +00:00
|
|
|
it('can get app information', getAppInfo);
|
|
|
|
|
2024-10-18 20:58:16 +00:00
|
|
|
it('can OIDC login', loginOIDC.bind(null, username, password, true));
|
2019-07-18 19:32:04 +00:00
|
|
|
it('can see timeline', checkTimeline);
|
2019-07-18 00:16:01 +00:00
|
|
|
|
2021-05-17 18:12:12 +00:00
|
|
|
it('uninstall app', async function () {
|
|
|
|
await browser.get('about:blank');
|
|
|
|
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
|
|
|
|
});
|
2019-07-18 00:16:01 +00:00
|
|
|
|
|
|
|
// test update
|
2024-10-18 20:58:16 +00:00
|
|
|
it('can install app', function () { execSync('cloudron install --appstore-id org.joinmastodon.cloudronapp --location ' + LOCATION, EXEC_ARGS); });
|
2020-08-16 09:04:41 +00:00
|
|
|
it('can get app information', getAppInfo);
|
2024-10-18 20:58:16 +00:00
|
|
|
it('can OIDC login', loginOIDC.bind(null, username, password, true));
|
2021-05-17 18:12:12 +00:00
|
|
|
it('can logout', logout);
|
|
|
|
|
|
|
|
it('can update', async function () {
|
|
|
|
await browser.get('about:blank');
|
|
|
|
execSync('cloudron update --app ' + LOCATION, EXEC_ARGS);
|
|
|
|
});
|
|
|
|
|
2024-10-18 20:58:16 +00:00
|
|
|
it('can OIDC login', loginOIDC.bind(null, username, password, true));
|
2019-07-18 00:16:01 +00:00
|
|
|
|
2020-08-16 09:04:41 +00:00
|
|
|
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
|
2019-07-18 00:16:01 +00:00
|
|
|
});
|