1
0
mirror of https://git.cloudron.io/cloudron/freshrss-app synced 2025-09-02 05:15:12 +00:00

OIDC auth implemented, tests amended

This commit is contained in:
Vladimir D
2023-10-27 12:36:22 +04:00
parent 8b6fbb5aab
commit f8e08f1c51
6 changed files with 132 additions and 22 deletions

View File

@@ -18,7 +18,12 @@ const execSync = require('child_process').execSync,
{ Builder, By, Key, until } = require('selenium-webdriver'),
{ Options } = require('selenium-webdriver/chrome');
const username = 'admin', password = 'changeme';
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);
}
describe('Application life cycle test', function () {
this.timeout(0);
@@ -27,7 +32,11 @@ describe('Application life cycle test', function () {
const TEST_TIMEOUT = 10000;
const EXEC_ARGS = { cwd: path.resolve(__dirname, '..'), stdio: 'inherit' };
const USERNAME = process.env.USERNAME;
const PASSWORD = process.env.PASSWORD;
let browser, app;
let athenticated_by_oidc = false;
before(function () {
const options = new Options().windowSize({ width: 1280, height: 1024 });
@@ -56,7 +65,7 @@ describe('Application life cycle test', function () {
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TEST_TIMEOUT);
}
async function login(password) {
async function login(username, password) {
await browser.get('https://' + app.fqdn);
await waitForElement(By.id('loginButton'));
await browser.findElement(By.id('username')).sendKeys(username);
@@ -65,6 +74,25 @@ describe('Application life cycle test', function () {
await waitForElement(By.id('btn-subscription'));
}
async function loginOIDC(username, password) {
browser.manage().deleteAllCookies();
await browser.get(`https://${app.fqdn}/i/`);
await browser.sleep(6000);
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);
await browser.findElement(By.xpath('//button[@type="submit" and contains(text(), "Sign in")]')).click();
await browser.sleep(2000);
athenticated_by_oidc = true;
}
await waitForElement(By.id('btn-subscription'));
}
async function logout() {
var logout_btn = By.xpath('//li/a[@class="signout"]');
@@ -87,12 +115,10 @@ describe('Application life cycle test', function () {
await waitForElement(By.xpath('//div[@id="notification" and @class="notification good"]'));
}
async function addUser(password) {
var test_username = 'test';
async function addUser(username, password) {
await browser.get(`${baseUrl()}/i/?c=user&a=manage`);
await waitForElement(By.id('new_user_name'));
await browser.findElement(By.id('new_user_name')).sendKeys(test_username);
await browser.findElement(By.id('new_user_name')).sendKeys(username);
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"]'));
@@ -128,18 +154,33 @@ describe('Application life cycle test', function () {
}
xit('build app', function () { execSync('cloudron build', EXEC_ARGS); });
it('install app', function () { execSync('cloudron install --location ' + LOCATION, EXEC_ARGS); });
// No SSO
it('install app', function () { execSync('cloudron install --no-sso --location ' + LOCATION, EXEC_ARGS); });
it('can get app information', getAppInfo);
it('can login', login.bind(null, password));
it('can login', login.bind(null, admin_username, admin_password));
it('can subscribe', addSubscription);
it('can add users', addUser.bind(null, password));
it('can add users', addUser.bind(null, 'test', admin_password));
it('can enable API', enableApi);
it('can check configuration', checkApiConfiguration);
it('subscription exists', subscriptionExists);
it('can get static extension file', getStaticExtensionFile);
it('can logout', logout);
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
// SSO
it('install app', function () { execSync('cloudron install --location ' + LOCATION, EXEC_ARGS); });
it('can get app information', getAppInfo);
it('can login OIDC', loginOIDC.bind(null, USERNAME, PASSWORD));
it('can make user Administrator', function () { execSync(`cloudron exec --app ${app.id} -- bash -c "php cli/reconfigure.php --default_user ${USERNAME}"`); });
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);
it('backup app', function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); });
@@ -151,11 +192,10 @@ describe('Application life cycle test', function () {
execSync(`cloudron restore --backup ${backups[0].id} --app ${app.id}`, EXEC_ARGS);
});
it('can login', login.bind(null, password));
it('can login OIDC', loginOIDC.bind(null, USERNAME, PASSWORD));
it('can check configuration', checkApiConfiguration);
it('subscription exists', subscriptionExists);
it('can get static extension file', getStaticExtensionFile);
it('can logout', logout);
it('move to different location', function () {
browser.manage().deleteAllCookies();
@@ -165,11 +205,10 @@ describe('Application life cycle test', function () {
expect(app).to.be.an('object');
});
it('can login', login.bind(null, password));
it('can login OIDC', loginOIDC.bind(null, USERNAME, PASSWORD));
it('can check configuration', checkApiConfiguration);
it('subscription exists', subscriptionExists);
it('can get static extension file', getStaticExtensionFile);
it('can logout', logout);
it('uninstall app', function () { execSync('cloudron uninstall --app ' + app.id, EXEC_ARGS); });
@@ -177,9 +216,10 @@ describe('Application life cycle test', function () {
it('can install app', function () { execSync('cloudron install --appstore-id org.freshrss.cloudronapp --location ' + LOCATION, EXEC_ARGS); });
it('can get app information', getAppInfo);
it('can login', login.bind(null, password));
// it can be changed to loginOIDC in the nextrelease
it('can login', login.bind(null, admin_username, admin_password));
it('can subscribe', addSubscription);
it('can add users', addUser.bind(null, password));
it('can add users', addUser.bind(null, 'test', admin_password));
it('can update', function () {
execSync('cloudron update --app ' + app.id, EXEC_ARGS);
@@ -188,7 +228,7 @@ describe('Application life cycle test', function () {
expect(app).to.be.an('object');
});
it('can login', login.bind(null, password));
it('can login', login.bind(null, admin_username, admin_password));
it('subscription exists', subscriptionExists);
it('can get static extension file', getStaticExtensionFile);