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 14 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
182 changes: 180 additions & 2 deletions x-pack/test_serverless/functional/page_objects/svl_common_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,199 @@
* 2.0.
*/

import { getUrl } from '@kbn/test';
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 navigateToApp(
appName: string,
{
basePath = '',
shouldLoginIfPrompted = true,
path = '',
hash = '',
search = '',
disableWelcomePrompt = true,
insertTimestamp = true,
retryOnFatalError = true,
} = {}
) {
let appUrl: string;

if (config.has(['apps', appName])) {
// Legacy applications
const appConfig = config.get(['apps', appName]);
appUrl = getUrl.noAuth(config.get('servers.kibana'), {
pathname: `${basePath}${appConfig.pathname}`,
hash: hash || appConfig.hash,
search,
});
} else {
appUrl = getUrl.noAuth(config.get('servers.kibana'), {
pathname: `${basePath}/app/${appName}` + (path ? `/${path}` : ''),
hash,
search,
});
}

log.debug('navigating to ' + appName + ' url: ' + appUrl);

await retry.tryForTime(60_000 * 2, async () => {
let lastUrl = await retry.try(async () => {
// since we're using hash URLs, always reload first to force re-render
log.debug('navigate to: ' + appUrl);
await browser.get(appUrl, insertTimestamp);
// accept alert if it pops up
const alert = await browser.getAlert();
await alert?.accept();
await delay(700);
let currentUrl = await browser.getCurrentUrl();

if (currentUrl.includes('app/kibana')) {
await testSubjects.find('kibanaChrome');
}

// If navigating to the `home` app, and we want to skip the Welcome page, but the chrome is still hidden,
// set the relevant localStorage key to skip the Welcome page and throw an error to try to navigate again.
// if (
// appName === 'home' &&
// currentUrl.includes('app/home') &&
// disableWelcomePrompt &&
// (await this.isWelcomeScreen())
// ) {
// await this.browser.setLocalStorageItem('home:welcome:show', 'false');
// const msg = `Failed to skip the Welcome page when navigating the app ${appName}`;
// this.log.debug(msg);
// throw new Error(msg);
// }

currentUrl = (await browser.getCurrentUrl()).replace(/\/\/\w+:\w+@/, '//');

const navSuccessful = currentUrl
.replace(':80/', '/')
.replace(':443/', '/')
.startsWith(appUrl.replace(':80/', '/').replace(':443/', '/'));

if (!navSuccessful) {
const msg = `App failed to load: ${appName} in 60000 ms appUrl=${appUrl} currentUrl=${currentUrl}`;
log.debug(msg);
throw new Error(msg);
}

if (retryOnFatalError && (await pageObjects.common.isFatalErrorScreen())) {
const msg = `Fatal error screen shown. Let's try refreshing the page once more.`;
log.debug(msg);
throw new Error(msg);
}

if (appName === 'discover') {
await browser.setLocalStorageItem('data.autocompleteFtuePopover', 'true');
}
return currentUrl;
});

await retry.tryForTime(60_000, async () => {
await delay(501);
const currentUrl = await browser.getCurrentUrl();
log.debug('in navigateTo url = ' + currentUrl);
if (lastUrl !== currentUrl) {
lastUrl = currentUrl;
throw new Error('URL changed, waiting for it to settle');
}
});
});
},

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');
}

await testSubjects.existOrFail('userMenuButton', { timeout: 10_000 });
await delay(2000);
await browser.refresh();

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
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export function SvlCommonNavigationServiceProvider({
}: FtrProviderContext) {
const retry = getService('retry');
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects(['common']);
const PageObjects = getPageObjects(['common', 'svlCommonPage']);

return {
async navigateToKibanaHome() {
await retry.tryForTime(60 * 1000, async () => {
await PageObjects.common.navigateToApp('home');
await PageObjects.svlCommonPage.navigateToApp('home');
await testSubjects.existOrFail('homeApp', { timeout: 2000 });
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export function SvlObltNavigationServiceProvider({
}: FtrProviderContext) {
const retry = getService('retry');
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects(['common']);
const PageObjects = getPageObjects(['svlCommonPage']);

return {
async navigateToLandingPage() {
await retry.tryForTime(60 * 1000, async () => {
await PageObjects.common.navigateToApp('landingPage');
await PageObjects.svlCommonPage.navigateToApp('landingPage');
await testSubjects.existOrFail('obltOnboardingHomeTitle', { timeout: 2000 });
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export function SvlSearchNavigationServiceProvider({
getPageObjects,
}: FtrProviderContext) {
const retry = getService('retry');
const PageObjects = getPageObjects(['common']);
const PageObjects = getPageObjects(['svlCommonPage']);

return {
async navigateToLandingPage() {
await retry.tryForTime(60 * 1000, async () => {
await PageObjects.common.navigateToApp('landingPage');
await PageObjects.svlCommonPage.navigateToApp('landingPage');
// The getting started page is currently empty, so there's nothing we could
// assert on. Once something exists here, we should add back a check.
// await testSubjects.existOrFail('svlSearchOverviewPage', { timeout: 2000 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export function SvlSecNavigationServiceProvider({
}: FtrProviderContext) {
const retry = getService('retry');
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects(['common']);
const PageObjects = getPageObjects(['svlCommonPage']);

return {
async navigateToLandingPage() {
await retry.tryForTime(60 * 1000, async () => {
await PageObjects.common.navigateToApp('landingPage');
await PageObjects.svlCommonPage.navigateToApp('landingPage');
// Currently, the security landing page app is not loading correctly.
// Replace '~kbnAppWrapper' with a proper test subject of the landing
// page once it loads successfully.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { FtrProviderContext } from '../../ftr_provider_context';

export default ({ getPageObjects, getService }: FtrProviderContext) => {
const testSubjects = getService('testSubjects');
const pageObjects = getPageObjects(['common']);
const pageObjects = getPageObjects(['svlCommonPage']);
const browser = getService('browser');
const retry = getService('retry');

// Skip until we enable the Advanced settings app in serverless
describe.skip('Common advanced settings', function () {
before(async () => {
await pageObjects.common.navigateToApp('advancedSettings');
await pageObjects.svlCommonPage.navigateToApp('advancedSettings');
});

it('renders the page', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function ({ getService, getPageObjects, loadTestFile }: FtrProvid
);

// TODO: Navigation to Data View Management is different in Serverless
await PageObjects.common.navigateToApp('management');
await PageObjects.svlCommonPage.navigateToApp('management');
await retry.waitFor('data views link', async () => {
if (await testSubjects.exists('app-card-dataViews')) {
await testSubjects.click('app-card-dataViews');
Expand All @@ -56,7 +56,7 @@ export default function ({ getService, getPageObjects, loadTestFile }: FtrProvid
return false;
});
await PageObjects.settings.createIndexPattern('blogs', null);
await PageObjects.common.navigateToApp('dataViewFieldEditorExample');
await PageObjects.svlCommonPage.navigateToApp('dataViewFieldEditorExample');
});

loadTestFile(require.resolve('./data_view_field_editor_example'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default ({ getService, getPageObjects }: FtrProviderContext) => {
await esArchiver.loadIfNeeded('x-pack/test/functional/es_archives/logstash_functional');
await kibanaServer.importExport.load('test/functional/fixtures/kbn_archiver/discover');
await kibanaServer.uiSettings.replace(defaultSettings);
await PageObjects.common.navigateToApp('home');
await PageObjects.svlCommonPage.navigateToApp('home');
const currentUrl = await browser.getCurrentUrl();
const customizationUrl =
currentUrl.substring(0, currentUrl.indexOf('/app/home')) +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
before(async () => {
// TODO: Serverless tests require login first
await PageObjects.svlCommonPage.login();
await PageObjects.common.navigateToApp('fieldFormatsExample');
await PageObjects.svlCommonPage.navigateToApp('fieldFormatsExample');
});

it('renders field formats example 1', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
before(async () => {
// TODO: Serverless tests require login first
await PageObjects.svlCommonPage.login();
await PageObjects.common.navigateToApp('partialResultsExample');
await PageObjects.svlCommonPage.navigateToApp('partialResultsExample');

const element = await testSubjects.find('example-help');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
'timepicker:timeDefaults': '{ "from": "now-1y", "to": "now" }',
});

await PageObjects.common.navigateToApp('searchExamples');
await PageObjects.svlCommonPage.navigateToApp('searchExamples');
});

beforeEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import type { FtrProviderContext } from '../../../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects(['common']);
const PageObjects = getPageObjects(['svlCommonPage']);
const retry = getService('retry');

// FLAKY: https://github.com/elastic/kibana/issues/165763
describe.skip('Partial results example', () => {
describe('Partial results example', () => {
before(async () => {
await PageObjects.common.navigateToApp('searchExamples');
await PageObjects.svlCommonPage.navigateToApp('searchExamples');
await testSubjects.click('/search');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

function testSearchExample() {
before(async function () {
await PageObjects.common.navigateToApp(appId, { insertTimestamp: false });
await PageObjects.svlCommonPage.navigateToApp(appId, { insertTimestamp: false });
await comboBox.setCustom('dataViewSelector', 'logstash-*');
await comboBox.set('searchBucketField', 'geo.src');
await comboBox.set('searchMetricField', 'memory');
Expand Down
Loading