1
0
mirror of https://git.cloudron.io/cloudron/gitea-app synced 2025-09-15 01:19:13 +00:00

LDAP to OIDC auth migration, tests refactored

This commit is contained in:
Vladimir D
2023-09-26 15:30:53 +04:00
parent dd44f81d04
commit e176d6c705
6 changed files with 94 additions and 32 deletions

View File

@@ -33,6 +33,7 @@ describe('Application life cycle test', function () {
const SSH_PORT = 29420;
let app, browser;
var athenticated_by_oidc = false;
const repodir = '/tmp/testrepo';
const reponame = 'testrepo';
@@ -56,6 +57,11 @@ describe('Application life cycle test', function () {
expect(app).to.be.an('object');
}
async function waitForElement(elem) {
await browser.wait(until.elementLocated(elem), TIMEOUT);
await browser.wait(until.elementIsVisible(browser.findElement(elem)), TIMEOUT);
}
function sleep(millis) {
return new Promise(resolve => setTimeout(resolve, millis));
}
@@ -93,6 +99,29 @@ describe('Application life cycle test', function () {
await login('root', 'changeme');
}
async function loginOIDC(username, password) {
browser.manage().deleteAllCookies();
await browser.get(`https://${app.fqdn}/user/login`);
await browser.sleep(2000);
await browser.findElement(By.xpath('//a[contains(@class, "openidConnect") and contains(., "Sign in with cloudron")]')).click();
await browser.sleep(2000);
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.xpath('//img[contains(@class, "avatar")]'));
}
async function logout() {
await browser.get('https://' + app.fqdn);
@@ -182,7 +211,7 @@ describe('Application life cycle test', function () {
it('can send mail', sendMail);
it('can logout', logout);
it('can login', login.bind(null, username, password));
it('can login', loginOIDC.bind(null, username, password));
it('can set avatar', setAvatar);
it('can get avatar', checkAvatar);
@@ -198,7 +227,7 @@ describe('Application life cycle test', function () {
it('can restart app', function () { execSync('cloudron restart --app ' + app.id); });
xit('can login', login.bind(null, username, password)); // no need to relogin since session persists
xit('can login', loginOIDC.bind(null, username, password)); // no need to relogin since session persists
it('displays correct clone url', checkCloneUrl);
it('can clone the url', cloneRepo);
it('file exists in repo', fileExists);
@@ -206,7 +235,7 @@ describe('Application life cycle test', function () {
it('backup app', function () { execSync('cloudron backup create --app ' + app.id, EXEC_ARGS); });
it('restore app', function () { execSync('cloudron restore --app ' + app.id, EXEC_ARGS); });
it('can login', login.bind(null, username, password));
it('can login', loginOIDC.bind(null, username, password));
it('can get avatar', checkAvatar);
it('can clone the url', cloneRepo);
it('file exists in repo', function () { expect(fs.existsSync(repodir + '/newfile')).to.be(true); });
@@ -220,7 +249,7 @@ describe('Application life cycle test', function () {
});
it('can get app information', getAppInfo);
it('can login', login.bind(null, username, password));
it('can login', loginOIDC.bind(null, username, password));
it('can get avatar', checkAvatar);
it('displays correct clone url', checkCloneUrl);
it('can clone the url', cloneRepo);
@@ -248,6 +277,7 @@ describe('Application life cycle test', function () {
it('can install app', function () { execSync(`cloudron install --appstore-id ${app.manifest.id} --location ${LOCATION} -p SSH_PORT=${SSH_PORT}`, EXEC_ARGS); });
it('can get app information', getAppInfo);
// to be replaced with loginOIDC in the next release
it('can login', login.bind(null, username, password));
it('can set avatar', setAvatar);
it('can get avatar', checkAvatar);
@@ -263,7 +293,7 @@ describe('Application life cycle test', function () {
it('can send mail', sendMail);
it('can logout', logout);
it('can login', login.bind(null, username, password));
it('can login', loginOIDC.bind(null, username, password));
it('can get avatar', checkAvatar);
it('can clone the url', cloneRepo);
it('file exists in cloned repo', fileExists);