mastodon-app/test/test.js

214 lines
8.6 KiB
JavaScript
Raw Normal View History

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 */
/* 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'),
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);
2021-05-17 18:12:12 +00:00
const 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-02-14 10:13:42 +00:00
var athenticated_by_oidc = false;
2021-05-17 18:12:12 +00:00
let username = process.env.USERNAME;
let password = process.env.PASSWORD;
let manifest = require('../CloudronManifest.json');
2019-07-18 00:16:01 +00:00
2021-05-17 18:12:12 +00:00
before(function () {
browser = new Builder().forBrowser('chrome').setChromeOptions(new Options().windowSize({ width: 1280, height: 1024 })).build();
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-02-14 10:13:42 +00:00
function sleep(millis) {
return new Promise(resolve => setTimeout(resolve, millis));
}
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-02-14 10:13:42 +00:00
async function loginOIDC(username, password) {
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);
if (!athenticated_by_oidc) {
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);
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);
athenticated_by_oidc = true;
}
await waitForElement(By.xpath('//a[contains(., "Edit profile")] | //strong[text()="Successfully authenticated from Cloudron account."]'));
}
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
}
2023-09-22 02:43:33 +00:00
async function dismissHelp() {
await browser.get('https://' + app.fqdn + '/home');
await visible(By.xpath('//button[@title = "Dismiss"]'));
await browser.findElement(By.xpath('//button[@title ="Dismiss"]')).click();
2019-07-18 19:32:04 +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 () {
let output = execSync('cloudron exec --app ' + LOCATION + ' -- bin/tootctl accounts create test --email=test@cloudron.io', { cwd: path.resolve(__dirname, '..'), encoding: 'utf8' });
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);
});
it('shows confirmation page', function () {
return browser.wait(until.elementLocated(By.xpath('//div[contains(text(), "Waiting for e-mail confirmation to be completed")]')), TEST_TIMEOUT);
});
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-02-14 10:13:42 +00:00
it('can OIDC login', loginOIDC.bind(null, username, password));
2023-09-22 02:43:33 +00:00
it('can dismiss help', dismissHelp);
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-02-14 10:13:42 +00:00
it('can OIDC login', loginOIDC.bind(null, username, password));
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-02-14 10:13:42 +00:00
it('can OIDC login', loginOIDC.bind(null, username, password));
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
2021-05-17 18:12:12 +00:00
it('can install app', function () { execSync('cloudron install --appstore-id ' + manifest.id + ' --location ' + LOCATION, EXEC_ARGS); });
2020-08-16 09:04:41 +00:00
it('can get app information', getAppInfo);
2024-02-14 10:13:42 +00:00
// needs to be changed to loginOIDC on the next release
2024-02-23 15:45:18 +00:00
it('can OIDC login', loginOIDC.bind(null, username, password));
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-02-14 10:13:42 +00:00
it('can OIDC login', loginOIDC.bind(null, username, password));
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
});