Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[security_page] improve force logout #170227

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading