peertube-app/test/test.js

262 lines
10 KiB
JavaScript
Raw Normal View History

2020-07-21 20:46:54 +00:00
#!/usr/bin/env node
2021-10-11 10:07:47 +00:00
/* jshint esversion: 8 */
/* global describe */
/* global before */
/* global after */
/* global it */
2020-07-21 20:46:54 +00:00
'use strict';
require('chromedriver');
2022-04-29 22:16:11 +00:00
const execSync = require('child_process').execSync,
2020-07-21 20:46:54 +00:00
expect = require('expect.js'),
2023-06-22 19:09:28 +00:00
readlinePromises = require('readline/promises'),
2020-07-21 20:46:54 +00:00
path = require('path'),
2024-01-16 14:27:31 +00:00
safe = require('safetydance'),
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-10-11 10:07:47 +00:00
const LOCATION = 'test';
const TEST_TIMEOUT = parseInt(process.env.TEST_TIMEOUT, 10) || 30000;
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
2021-01-07 16:21:38 +00:00
2024-01-10 17:04:08 +00:00
let browser;
let app;
let host_os;
let username = process.env.USERNAME;
let password = process.env.PASSWORD;
let email = process.env.EMAIL;
2024-01-15 17:01:40 +00:00
let athenticated_by_oidc = false;
2020-07-21 20:46:54 +00:00
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() {
2024-01-10 17:04:08 +00:00
let inspect = JSON.parse(execSync('cloudron inspect'));
2021-10-11 10:07:47 +00:00
app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0];
2020-07-21 20:46:54 +00:00
expect(app).to.be.an('object');
}
2024-01-10 17:04:08 +00:00
async function getOS() {
if (typeof(host_os) == 'undefined' || host_os == null)
host_os = String(await execSync('uname -s')).trim();
return host_os;
}
2021-12-16 15:56:07 +00:00
async function waitForElement(elem) {
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
2020-07-21 20:46:54 +00:00
}
2021-12-16 15:56:07 +00:00
function sleep(millis) {
return new Promise(resolve => setTimeout(resolve, millis));
2021-09-13 20:27:30 +00:00
}
2021-12-16 15:56:07 +00:00
async function login(username, password) {
await browser.get('https://' + app.fqdn + '/login');
await waitForElement(By.id('username'));
await browser.findElement(By.id('username')).sendKeys(username);
await browser.findElement(By.id('password')).sendKeys(password);
await browser.findElement(By.xpath('//input[@value="Login"]')).click();
await waitForElement(By.xpath('//a[contains(@href, "/my-library")]'));
2020-10-15 04:45:44 +00:00
}
2024-01-15 17:01:40 +00:00
async function loginOIDC(username, password) {
browser.manage().deleteAllCookies();
await browser.get(`https://${app.fqdn}/login`);
await browser.sleep(2000);
await browser.wait(until.elementLocated(By.xpath('//a[contains(., "Cloudron")]')), TEST_TIMEOUT);
await browser.findElement(By.xpath('//a[contains(., "Cloudron")]')).click();
await browser.sleep(2000);
if (!athenticated_by_oidc) {
2024-04-04 13:52:18 +00:00
await waitForElement(By.id('inputUsername'));
await browser.findElement(By.id('inputUsername')).sendKeys(username);
await browser.findElement(By.id('inputPassword')).sendKeys(password);
await browser.findElement(By.id('loginSubmitButton')).click();
2024-01-15 17:01:40 +00:00
athenticated_by_oidc = true;
}
await browser.sleep(20000);
await waitForElement(By.xpath('//a[contains(@href, "/my-library")]'));
}
2021-12-16 15:56:07 +00:00
async function closeAccountSetupDialog() {
await browser.get('https://' + app.fqdn);
2024-01-18 11:21:14 +00:00
await waitForElement(By.xpath('//span[contains(text(), "show me this anymore")]'));
2021-12-16 15:56:07 +00:00
await browser.findElement(By.xpath('//span[contains(text(), "show me this anymore")]')).click();
await browser.findElement(By.xpath('//a[contains(text(), "Set up")]')).click();
await browser.sleep(3000);
}
async function logout() {
await browser.get('https://' + app.fqdn + '/my-account/videos');
await waitForElement(By.xpath('//div[@class="logged-in-display-name"]'));
await browser.sleep(2000);
await browser.findElement(By.xpath('//div[@class="logged-in-display-name"]')).click();
await browser.sleep(2000);
2023-06-21 16:03:32 +00:00
await browser.findElement(By.xpath('//button[contains(text(), "Log out")]')).click();
2021-12-16 15:56:07 +00:00
await browser.sleep(2000);
}
async function completeSetup() {
2024-01-10 17:04:08 +00:00
let button;
2020-07-21 22:30:01 +00:00
2022-09-21 14:55:48 +00:00
await browser.get(`https://${app.fqdn}`);
2024-01-15 17:01:40 +00:00
await browser.sleep(2000);
2021-12-16 15:56:07 +00:00
2024-01-16 14:00:04 +00:00
const [error] = await safe(waitForElement(By.xpath('//a[contains(text(), "Configure my instance")]')));
if (error) return; // sometimes it doesn't appear, maybe it's cached in local storage
2024-01-16 13:23:23 +00:00
await browser.findElement(By.xpath('//a[contains(text(), "Configure my instance")]')).click(); // this opens a new window
2024-01-10 17:04:08 +00:00
2024-01-18 10:47:58 +00:00
const say_cmd = await getOS() == "Darwin" ? "say" : "spd-say";
2024-01-16 13:23:23 +00:00
execSync(`${say_cmd} "Close the newly opened configuration tab."`);
2024-01-15 17:01:40 +00:00
2024-01-18 10:47:58 +00:00
const rl = readlinePromises.createInterface({ input: process.stdin, output: process.stdout });
2024-01-16 13:23:23 +00:00
await rl.question('Is tab closed? ');
2020-07-21 22:30:01 +00:00
}
2021-12-16 15:56:07 +00:00
async function uploadVideo() {
2024-01-18 10:47:58 +00:00
await browser.get(`https://${app.fqdn}/videos/upload#upload`);
await browser.sleep(3000);
await browser.wait(until.elementLocated(By.id('videofile')), TEST_TIMEOUT); // do not do element visible check . it fails, no clue why
await browser.findElement(By.id('videofile')).sendKeys(path.resolve(__dirname, './Cloudron Test Video.mp4'));
console.log('waiting 10 seconds for upload');
2021-12-16 16:33:47 +00:00
await browser.sleep(10000); // wait for upload
2022-11-17 12:38:43 +00:00
2021-12-16 16:33:47 +00:00
await waitForElement(By.xpath('//div[@class="submit-container"]//span[text()="Publish"]'));
2022-11-17 12:38:43 +00:00
let button = browser.findElement(By.xpath('//div[@class="submit-container"]//span[text()="Publish"]'));
await browser.executeScript('arguments[0].scrollIntoView(false)', button);
await browser.sleep(2000);
await button.click();
2021-12-16 15:56:07 +00:00
await browser.sleep(2000);
2020-07-21 22:30:01 +00:00
}
2021-12-16 15:56:07 +00:00
async function videoExists() {
await browser.get('https://' + app.fqdn + '/my-account/videos');
await waitForElement(By.xpath('//a[contains(@title, "Cloudron Test Video")]'));
2020-07-21 22:30:01 +00:00
}
2021-10-11 10:07:47 +00:00
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
2024-01-15 17:01:40 +00:00
it('install app', async function () {
2021-10-11 10:07:47 +00:00
execSync('cloudron install --location ' + LOCATION, EXEC_ARGS);
2023-01-05 11:14:37 +00:00
await sleep(40000); // takes a bit to create root user in background
2020-07-21 20:46:54 +00:00
});
it('can get app information', getAppInfo);
2021-10-11 10:07:47 +00:00
it('can root login', login.bind(null, 'root', 'changeme'));
2024-01-15 17:01:40 +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);
2024-01-15 17:01:40 +00:00
it('can OIDC login', loginOIDC.bind(null, username, password));
2021-09-13 20:27:30 +00:00
it('can close account setup dialog', closeAccountSetupDialog);
2020-10-15 04:45:44 +00:00
it('logout', logout);
2020-07-21 20:46:54 +00:00
2021-10-11 10:07:47 +00:00
it('backup app', function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); });
2020-07-21 20:46:54 +00:00
it('restore app', function () {
const backups = JSON.parse(execSync('cloudron backup list --raw'));
2021-10-11 10:07:47 +00:00
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
execSync('cloudron install --location ' + LOCATION, EXEC_ARGS);
2020-07-21 20:46:54 +00:00
getAppInfo();
2021-10-11 10:07:47 +00:00
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS);
2020-07-21 20:46:54 +00:00
});
2021-10-11 10:07:47 +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);
2024-01-15 17:01:40 +00:00
it('can OIDC login', loginOIDC.bind(null, username, password));
2020-10-15 04:45:44 +00:00
it('logout', logout);
2020-07-21 20:46:54 +00:00
it('can restart app', function () {
execSync('cloudron restart --app ' + app.id);
});
2021-10-11 10:07:47 +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);
2024-01-15 17:01:40 +00:00
it('can OIDC login', loginOIDC.bind(null, username, password));
2020-10-15 04:45:44 +00:00
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
2021-10-11 10:07:47 +00:00
it('move to different location', function () { execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, EXEC_ARGS); });
2020-07-21 20:46:54 +00:00
it('can get app information', getAppInfo);
2021-10-11 10:07:47 +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);
2024-01-15 17:01:40 +00:00
it('can OIDC login', loginOIDC.bind(null, username, password));
2020-10-15 04:45:44 +00:00
it('logout', logout);
2020-07-21 20:46:54 +00:00
2022-09-21 14:55:48 +00:00
it('uninstall app', async function () {
await browser.executeScript('localStorage.clear();');
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
});
2020-07-21 20:46:54 +00:00
2020-10-15 04:45:44 +00:00
// No SSO
2021-12-16 15:56:07 +00:00
it('install app (no sso)', async function () {
2021-10-11 10:07:47 +00:00
execSync('cloudron install --no-sso --location ' + LOCATION, EXEC_ARGS);
2021-12-16 15:56:07 +00:00
await sleep(10000); // takes a bit to create root user in background
2020-10-15 04:45:44 +00:00
});
2021-10-11 10:07:47 +00:00
it('can get app information', getAppInfo);
2020-10-15 04:45:44 +00:00
it('can login (no sso)', login.bind(null, 'root', 'changeme'));
it('can complete setup', completeSetup);
it('can logout', logout);
2022-09-21 14:55:48 +00:00
it('uninstall app (no sso)', async function () {
await browser.executeScript('localStorage.clear();');
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
});
2020-10-15 04:45:44 +00:00
2020-07-21 20:46:54 +00:00
// test update
2021-12-16 15:56:07 +00:00
it('can install app', async function () {
2021-10-11 10:07:47 +00:00
execSync('cloudron install --appstore-id org.joinpeertube.cloudronapp --location ' + LOCATION, EXEC_ARGS);
2021-12-16 15:56:07 +00:00
await sleep(10000); // 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
2021-10-11 10:07:47 +00:00
it('can update', function () { execSync('cloudron update --app ' + app.id, EXEC_ARGS); });
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);
2024-01-15 17:01:40 +00:00
it('can OIDC login', loginOIDC.bind(null, username, password));
2023-12-28 11:21:57 +00:00
it('can close account setup dialog', closeAccountSetupDialog);
2020-10-15 04:45:44 +00:00
it('logout', logout);
2020-07-21 20:46:54 +00:00
2022-09-21 14:55:48 +00:00
it('uninstall app', async function () {
await browser.executeScript('localStorage.clear();');
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
});
2020-07-21 20:46:54 +00:00
});