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

[ftr] pass password for UI login + improve login/logout steps with proper wait logic #166936

Merged
merged 23 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d96ee7d
[ftr] pass password for UI login + retry login via API in advance
dmlemeshko Sep 21, 2023
79cdcdc
fix port & retry logic
dmlemeshko Sep 21, 2023
575502a
Merge branch 'main' into ftr/fix-login-on-MKI
dmlemeshko Sep 25, 2023
a1dffd4
fix flaky logout > login navigation
dmlemeshko Sep 25, 2023
07a5606
remove await for log service
dmlemeshko Sep 25, 2023
8f69cd6
Merge branch 'ftr/fix-login-on-MKI' of github.com:dmlemeshko/kibana i…
dmlemeshko Sep 25, 2023
264f014
Merge branch 'main' into ftr/fix-login-on-MKI
dmlemeshko Sep 25, 2023
df1eb78
Revert "remove await for log service"
dmlemeshko Sep 25, 2023
c64871e
Merge branch 'ftr/fix-login-on-MKI' of github.com:dmlemeshko/kibana i…
dmlemeshko Sep 25, 2023
d59c88b
[ftr] retry login via UI
dmlemeshko Sep 25, 2023
a228bf9
remove API call, split logic on retry failure
dmlemeshko Sep 25, 2023
1cfc4c0
Merge branch 'main' into ftr/fix-login-on-MKI
dmlemeshko Sep 25, 2023
9b8651f
update nav, unskip tests
dmlemeshko Sep 26, 2023
c00b312
Merge branch 'ftr/fix-login-on-MKI' of github.com:dmlemeshko/kibana i…
dmlemeshko Sep 26, 2023
fefbac8
Revert "update nav, unskip tests"
dmlemeshko Sep 26, 2023
ae83d7d
Merge branch 'main' into ftr/fix-login-on-MKI
dmlemeshko Sep 26, 2023
d89048e
Merge branch 'main' into ftr/fix-login-on-MKI
dmlemeshko Sep 27, 2023
1cf92ce
Merge branch 'main' into ftr/fix-login-on-MKI
dmlemeshko Sep 27, 2023
ba20b20
Merge branch 'main' into ftr/fix-login-on-MKI
dmlemeshko Sep 27, 2023
6a02860
Merge branch 'main' into ftr/fix-login-on-MKI
kibanamachine Sep 27, 2023
96dd1ac
Merge branch 'main' into ftr/fix-login-on-MKI
dmlemeshko Sep 27, 2023
76ac2fc
Merge branch 'main' into ftr/fix-login-on-MKI
dmlemeshko Sep 27, 2023
1dace28
Merge branch 'main' into ftr/fix-login-on-MKI
dmlemeshko Sep 28, 2023
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
11 changes: 9 additions & 2 deletions x-pack/test/functional/page_objects/security_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class SecurityPageObject extends FtrService {
);
}

private async isLoginFormVisible() {
public async isLoginFormVisible() {
return await this.testSubjects.exists('loginForm');
}

Expand Down Expand Up @@ -323,7 +323,14 @@ export class SecurityPageObject extends FtrService {
if (alert?.accept) {
await alert.accept();
}
return !(await this.browser.getCurrentUrl()).includes('/logout');

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);
} else {
return !(await this.browser.getCurrentUrl()).includes('/logout');
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,90 @@ import { FtrProviderContext } from '../ftr_provider_context';
export function SvlCommonPageProvider({ getService, getPageObjects }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const config = getService('config');
const pageObjects = getPageObjects(['security']);
const pageObjects = getPageObjects(['security', 'common']);
const retry = getService('retry');
const deployment = getService('deployment');
const log = getService('log');
const browser = getService('browser');

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

return {
async navigateToLoginForm() {
const url = deployment.getHostPort() + '/login';
await browser.get(url);
// ensure welcome screen won't be shown. This is relevant for environments which don't allow
// to use the yml setting, e.g. cloud
await browser.setLocalStorageItem('home:welcome:show', 'false');

log.debug('Waiting for Login Form to appear.');
await retry.waitForWithTimeout('login form', 10_000, async () => {
return await pageObjects.security.isLoginFormVisible();
});
},

async login() {
await pageObjects.security.forceLogout({ waitForLoginPage: false });
return await pageObjects.security.login(config.get('servers.kibana.username'));

// adding sleep to settle down logout
await pageObjects.common.sleep(2500);

await retry.waitForWithTimeout(
'Waiting for successful authentication',
90_000,
async () => {
if (!(await testSubjects.exists('loginUsername', { timeout: 1000 }))) {
await this.navigateToLoginForm();

await testSubjects.setValue('loginUsername', config.get('servers.kibana.username'));
await testSubjects.setValue('loginPassword', config.get('servers.kibana.password'));
await testSubjects.click('loginSubmit');
}

if (await testSubjects.exists('userMenuButton', { timeout: 10_000 })) {
log.debug('userMenuButton is found, logged in passed');
return true;
} else {
throw new Error(`Failed to login to Kibana via UI`);
}
},
async () => {
// Sometimes authentication fails and user is redirected to Cloud login page
// [plugins.security.authentication] Authentication attempt failed: UNEXPECTED_SESSION_ERROR
const currentUrl = await browser.getCurrentUrl();
if (currentUrl.startsWith('https://cloud.elastic.co')) {
log.debug(
'Probably authentication attempt failed, we are at Cloud login page. Retrying from scratch'
);
} else {
const authError = await testSubjects.exists('promptPage', { timeout: 2500 });
if (authError) {
log.debug('Probably SAML callback page, doing logout again');
await pageObjects.security.forceLogout({ waitForLoginPage: false });
} else {
const isOnLoginPage = await testSubjects.exists('loginUsername', { timeout: 1000 });
if (isOnLoginPage) {
log.debug(
'Probably ES user profile activation failed, waiting 2 seconds and pressing Login button again'
);
await delay(2000);
await testSubjects.click('loginSubmit');
} else {
log.debug('New behaviour, trying to navigate and login again');
}
}
}
}
);
log.debug('Logged in successfully');
},

async forceLogout() {
await pageObjects.security.forceLogout({ waitForLoginPage: false });
log.debug('Logged out successfully');
},

async assertProjectHeaderExists() {
Expand Down
Loading