freshrss-app/test/test.js

231 lines
9.5 KiB
JavaScript
Raw Permalink Normal View History

2017-02-17 10:28:42 +00:00
#!/usr/bin/env node
2022-01-02 15:43:53 +00:00
/* jshint esversion: 8 */
/* global describe */
/* global before */
/* global after */
/* global it */
2023-10-09 02:21:48 +00:00
/* global xit */
2022-01-02 15:43:53 +00:00
2017-02-17 10:28:42 +00:00
'use strict';
2018-05-21 19:36:04 +00:00
require('chromedriver');
2023-10-09 02:21:48 +00:00
const execSync = require('child_process').execSync,
2017-02-17 10:28:42 +00:00
expect = require('expect.js'),
path = require('path'),
2018-05-31 20:59:21 +00:00
superagent = require('superagent'),
2022-01-02 15:43:53 +00:00
{ Builder, By, Key, until } = require('selenium-webdriver'),
{ Options } = require('selenium-webdriver/chrome');
2017-02-17 10:28:42 +00:00
2023-10-27 08:36:22 +00:00
const admin_username = 'admin', admin_password = 'changeme';
if (!process.env.USERNAME || !process.env.PASSWORD) {
console.log('USERNAME and PASSWORD env vars need to be set');
process.exit(1);
}
2017-02-17 10:28:42 +00:00
describe('Application life cycle test', function () {
this.timeout(0);
2022-01-02 15:43:53 +00:00
const LOCATION = 'test';
2023-10-27 13:48:46 +00:00
const TEST_TIMEOUT = parseInt(process.env.TIMEOUT, 10) || 10000;
2022-01-02 15:43:53 +00:00
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
2023-10-27 08:36:22 +00:00
const USERNAME = process.env.USERNAME;
const PASSWORD = process.env.PASSWORD;
2023-10-09 02:21:48 +00:00
let browser, app;
2023-10-27 08:36:22 +00:00
let athenticated_by_oidc = false;
2017-02-17 10:28:42 +00:00
2022-01-02 15:43:53 +00:00
before(function () {
const options = new Options().windowSize({ width: 1280, height: 1024 });
if (process.env.HEADLESS) options.addArguments('headless');
2017-02-17 10:28:42 +00:00
2022-01-02 15:43:53 +00:00
browser = new Builder().forBrowser('chrome').setChromeOptions(options).build();
2017-02-17 10:28:42 +00:00
});
2022-01-02 15:43:53 +00:00
after(function () {
2017-02-17 10:28:42 +00:00
browser.quit();
});
2022-01-02 15:43:53 +00:00
function getAppInfo() {
var inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location.indexOf(LOCATION) === 0; })[0];
expect(app).to.be.an('object');
}
2017-02-17 10:28:42 +00:00
2019-01-04 00:36:12 +00:00
function baseUrl() {
if (app.manifest.version === '1.4.0') return `https://${app.fqdn}/p`;
return `https://${app.fqdn}`;
}
2022-01-03 10:45:00 +00:00
async function waitForElement(elem) {
await browser.wait(until.elementLocated(elem), TEST_TIMEOUT);
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
2019-01-04 00:36:12 +00:00
}
2023-10-27 08:36:22 +00:00
async function login(username, password) {
2022-01-03 10:45:00 +00:00
await browser.get('https://' + app.fqdn);
await waitForElement(By.id('loginButton'));
await browser.findElement(By.id('username')).sendKeys(username);
await browser.findElement(By.id('passwordPlain')).sendKeys(password);
await browser.findElement(By.id('loginButton')).click();
await waitForElement(By.id('btn-subscription'));
2017-02-17 10:28:42 +00:00
}
2023-10-27 08:36:22 +00:00
async function loginOIDC(username, password) {
browser.manage().deleteAllCookies();
await browser.get(`https://${app.fqdn}/i/`);
if (!athenticated_by_oidc) {
2024-06-05 18:29:29 +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();
2023-10-27 08:36:22 +00:00
athenticated_by_oidc = true;
}
await waitForElement(By.id('btn-subscription'));
}
2022-01-03 10:45:00 +00:00
async function logout() {
2022-01-02 15:43:53 +00:00
var logout_btn = By.xpath('//li/a[@class="signout"]');
2017-02-17 10:28:42 +00:00
2022-01-03 10:45:00 +00:00
await browser.get('https://' + app.fqdn);
await waitForElement(By.id('stream'));
await browser.findElement(By.className('dropdown-toggle')).click();
await waitForElement(logout_btn);
await browser.findElement(logout_btn).click();
await waitForElement(By.id('loginButton'));
2017-02-17 10:28:42 +00:00
}
2022-01-03 10:45:00 +00:00
async function addSubscription() {
2020-09-23 21:34:55 +00:00
var url = 'https://blog.cloudron.io/rss/';
const addUrl = app.manifest.version === '1.10.0' ? `${baseUrl()}/i/?c=subscription` : `${baseUrl()}/i/?c=subscription&a=add`;
2017-02-17 10:28:42 +00:00
2022-01-03 10:45:00 +00:00
await browser.get(addUrl);
await waitForElement(By.xpath('//input[@name="url_rss"]'));
await browser.findElement(By.xpath('//input[@name="url_rss"]')).sendKeys(url);
await browser.findElement(By.xpath('//form[@id="add_rss"]//button[text()="Add"]')).click();
await waitForElement(By.xpath('//div[@id="notification" and @class="notification good"]'));
2017-02-17 10:28:42 +00:00
}
2023-10-27 08:36:22 +00:00
async function addUser(username, password) {
2022-01-03 10:45:00 +00:00
await browser.get(`${baseUrl()}/i/?c=user&a=manage`);
await waitForElement(By.id('new_user_name'));
2023-10-27 08:36:22 +00:00
await browser.findElement(By.id('new_user_name')).sendKeys(username);
2022-01-03 10:45:00 +00:00
await browser.findElement(By.id('new_user_passwordPlain')).sendKeys(password);
await browser.findElement(By.xpath('//button[text()="Create"]')).click();
await waitForElement(By.xpath('//div[@id="notification" and @class="notification good"]'));
2017-02-17 10:28:42 +00:00
}
2022-01-03 10:45:00 +00:00
async function enableApi() {
await browser.get(`${baseUrl()}/i/?c=auth`);
await waitForElement(By.id('api_enabled'));
await browser.findElement(By.id('api_enabled')).click();
await browser.findElement(By.xpath('//button[text()="Submit"]')).click();
2023-10-27 13:48:46 +00:00
await browser.sleep(5000);
}
2022-01-03 10:45:00 +00:00
async function checkApiConfiguration() {
await browser.get(`${baseUrl()}/api/`);
await waitForElement(By.xpath('//dd[@id="greaderOutput" and contains(text(), "PASS")]'));
await waitForElement(By.xpath('//dd[@id="feverOutput" and contains(text(), "PASS")]'));
}
2017-02-17 10:28:42 +00:00
2022-01-03 10:45:00 +00:00
async function subscriptionExists() {
await browser.get(`${baseUrl()}/i/?get=c_1`);
return waitForElement(By.xpath('//span[text()="Cloudron"]'));
2018-03-19 11:01:48 +00:00
}
2023-10-27 13:48:46 +00:00
async function getStaticExtensionFile() {
const response = await superagent.get(`${baseUrl()}/ext.php?f=xExtension-StickyFeeds/static/script.js&t=js`)
2018-05-31 20:59:21 +00:00
.buffer(true)
2023-10-27 13:48:46 +00:00
.ok(() => true);
expect(response.statusCode).to.be(200);
expect(response.text).to.contain('sticky_feeds'); // relies on the buffer flag above
2018-05-31 20:59:21 +00:00
}
2022-01-02 15:43:53 +00:00
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
2023-10-27 08:36:22 +00:00
// No SSO
2023-10-27 13:48:46 +00:00
it('install app (no sso)', function () { execSync('cloudron install --no-sso --location ' + LOCATION, EXEC_ARGS); });
2017-02-17 10:28:42 +00:00
2018-03-19 11:01:48 +00:00
it('can get app information', getAppInfo);
2017-02-17 10:28:42 +00:00
2023-10-27 08:36:22 +00:00
it('can login', login.bind(null, admin_username, admin_password));
2017-02-17 10:28:42 +00:00
it('can subscribe', addSubscription);
2023-10-27 08:36:22 +00:00
it('can add users', addUser.bind(null, 'test', admin_password));
it('can enable API', enableApi);
it('can check configuration', checkApiConfiguration);
2018-03-19 11:01:48 +00:00
it('subscription exists', subscriptionExists);
2018-05-31 20:59:21 +00:00
it('can get static extension file', getStaticExtensionFile);
2017-02-17 10:28:42 +00:00
it('can logout', logout);
2023-10-27 08:36:22 +00:00
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
// SSO
2023-10-27 13:48:46 +00:00
it('install app (sso)', function () { execSync('cloudron install --location ' + LOCATION, EXEC_ARGS); });
2023-10-27 08:36:22 +00:00
it('can get app information', getAppInfo);
it('can login OIDC', loginOIDC.bind(null, USERNAME, PASSWORD));
2024-06-05 18:29:29 +00:00
it('can make user Administrator', function () { execSync(`cloudron exec --app ${app.id} -- bash -c "php cli/reconfigure.php --default-user ${USERNAME}"`); });
2023-10-27 08:36:22 +00:00
it('can subscribe', addSubscription);
it('can enable API', enableApi);
it('can check configuration', checkApiConfiguration);
it('subscription exists', subscriptionExists);
it('can get static extension file', getStaticExtensionFile);
2017-02-17 10:28:42 +00:00
2022-01-02 15:43:53 +00:00
it('backup app', function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); });
2017-02-17 10:28:42 +00:00
it('restore app', function () {
2022-01-02 15:43:53 +00:00
const backups = JSON.parse(execSync(`cloudron backup list --raw --app ${app.id}`));
execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS);
execSync('cloudron install --location ' + LOCATION, EXEC_ARGS);
2020-07-16 23:02:38 +00:00
getAppInfo();
2022-01-02 15:43:53 +00:00
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS);
2017-02-17 10:28:42 +00:00
});
2023-10-27 08:36:22 +00:00
it('can login OIDC', loginOIDC.bind(null, USERNAME, PASSWORD));
it('can check configuration', checkApiConfiguration);
2018-03-19 11:01:48 +00:00
it('subscription exists', subscriptionExists);
2018-05-31 20:59:21 +00:00
it('can get static extension file', getStaticExtensionFile);
2017-02-17 10:28:42 +00:00
it('move to different location', function () {
browser.manage().deleteAllCookies();
2022-01-02 15:43:53 +00:00
execSync('cloudron configure --location ' + LOCATION + '2 --app ' + app.id, EXEC_ARGS);
2017-02-17 10:28:42 +00:00
var inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location === LOCATION + '2'; })[0];
expect(app).to.be.an('object');
});
2023-10-27 08:36:22 +00:00
it('can login OIDC', loginOIDC.bind(null, USERNAME, PASSWORD));
it('can check configuration', checkApiConfiguration);
2018-03-19 11:01:48 +00:00
it('subscription exists', subscriptionExists);
2018-05-31 20:59:21 +00:00
it('can get static extension file', getStaticExtensionFile);
2017-02-17 10:28:42 +00:00
2022-01-02 15:43:53 +00:00
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
2017-02-17 10:28:42 +00:00
2018-03-19 11:01:48 +00:00
// test update
2024-05-23 16:10:22 +00:00
it('can install app for update', function () { execSync('cloudron install --appstore-id org.freshrss.cloudronapp --location ' + LOCATION, EXEC_ARGS); });
2018-03-19 11:01:48 +00:00
it('can get app information', getAppInfo);
2023-10-30 23:00:04 +00:00
it('can login OIDC', loginOIDC.bind(null, USERNAME, PASSWORD));
2024-06-05 18:29:29 +00:00
it('can make user Administrator', function () { execSync(`cloudron exec --app ${app.id} -- bash -c "php cli/reconfigure.php --default-user ${USERNAME}"`); });
2018-03-19 11:01:48 +00:00
it('can subscribe', addSubscription);
it('can update', function () {
2022-01-02 15:43:53 +00:00
execSync('cloudron update --app ' + app.id, EXEC_ARGS);
2018-03-19 11:01:48 +00:00
var inspect = JSON.parse(execSync('cloudron inspect'));
app = inspect.apps.filter(function (a) { return a.location === LOCATION; })[0];
expect(app).to.be.an('object');
});
2024-06-05 18:29:29 +00:00
it('can add users', addUser.bind(null, 'test', admin_password));
2018-03-19 11:01:48 +00:00
it('subscription exists', subscriptionExists);
2018-05-31 20:59:21 +00:00
it('can get static extension file', getStaticExtensionFile);
2018-03-19 11:01:48 +00:00
2022-01-02 15:43:53 +00:00
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
2017-02-17 10:28:42 +00:00
});