Skip to content

Commit

Permalink
[security_page] improve force logout
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlemeshko committed Oct 31, 2023
1 parent 0bbcdaa commit 4f154cb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions x-pack/test/functional/page_objects/security_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export class SecurityPageObject extends FtrService {
private readonly monacoEditor = this.ctx.getService('monacoEditor');
private readonly es = this.ctx.getService('es');

delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

public loginPage = Object.freeze({
login: async (username?: string, password?: string, options: LoginOptions = {}) => {
if (!(await this.isLoginFormVisible())) {
Expand Down Expand Up @@ -316,20 +318,27 @@ export class SecurityPageObject extends FtrService {
await this.waitForLoginPage();
} else {
this.log.debug('Waiting for logout to complete');
await this.retry.waitFor('Waiting for logout to complete', async () => {
await this.retry.waitFor('logout to complete', async () => {
// There are cases when browser/Kibana would like users to confirm that they want to navigate away from the
// current page and lose the state (e.g. unsaved changes) via native alert dialog.
const alert = await this.browser.getAlert();
if (alert?.accept) {
await alert.accept();
}

await this.retry.waitFor('URL redirects to finish', async () => {
const urlBefore = await this.browser.getCurrentUrl();
await this.delay(1000);
const urlAfter = await this.browser.getCurrentUrl();
return urlAfter === urlBefore;
});

const currentUrl = await this.browser.getCurrentUrl();
if (this.config.get('serverless')) {
// Logout might trigger multiple redirects, but in the end we expect the Cloud login page
this.log.debug('Wait 5 sec for Cloud login page to be displayed');
return await this.find.existsByDisplayedByCssSelector('.login-form-password', 5000);
return currentUrl.includes('/login') || currentUrl.includes('/projects');
} else {
return !(await this.browser.getCurrentUrl()).includes('/logout');
return !currentUrl.includes('/logout');
}
});
}
Expand Down

0 comments on commit 4f154cb

Please sign in to comment.