From db74ea25ed1cc941aabf83eceffecbc6b43a6ba1 Mon Sep 17 00:00:00 2001 From: Lee Drengenberg Date: Tue, 11 Sep 2018 15:15:18 -0500 Subject: [PATCH] Fix rbac test (#22912) (#22935) * conditionalize Monitoring tests for Cloud testing * make security_page/login wait * revert these files from another PR * revert these files from another PR --- test/functional/page_objects/common_page.js | 11 +++++++++-- x-pack/test/functional/apps/security/management.js | 2 +- x-pack/test/functional/apps/security/rbac_phase1.js | 4 ++-- x-pack/test/functional/apps/security/security.js | 2 +- x-pack/test/functional/page_objects/security_page.js | 7 ++++++- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/test/functional/page_objects/common_page.js b/test/functional/page_objects/common_page.js index f6417438e5137c..fe1894828e21ec 100644 --- a/test/functional/page_objects/common_page.js +++ b/test/functional/page_objects/common_page.js @@ -56,8 +56,14 @@ export function CommonPageProvider({ getService, getPageObjects }) { }; const appUrl = getUrl.noAuth(config.get('servers.kibana'), appConfig); - await remote.get(appUrl); - await this.loginIfPrompted(appUrl); + await retry.try(async () => { + log.debug(`navigateToUrl ${appUrl}`); + await remote.get(appUrl); + const currentUrl = await this.loginIfPrompted(appUrl); + if (!currentUrl.includes(appUrl)) { + throw new Error(`expected ${currentUrl}.includes(${appUrl})`); + } + }); } @@ -75,6 +81,7 @@ export function CommonPageProvider({ getService, getPageObjects }) { config.get('servers.kibana.password') ); await remote.setFindTimeout(20000).findByCssSelector('[data-test-subj="kibanaChrome"] nav:not(.ng-hide)'); + await remote.get(appUrl); currentUrl = await remote.getCurrentUrl(); log.debug(`Finished login process currentUrl = ${currentUrl}`); } diff --git a/x-pack/test/functional/apps/security/management.js b/x-pack/test/functional/apps/security/management.js index ccd4cdbc6f27a2..73c1b348f50940 100644 --- a/x-pack/test/functional/apps/security/management.js +++ b/x-pack/test/functional/apps/security/management.js @@ -21,7 +21,7 @@ export default function ({ getService, getPageObjects }) { describe('Management', () => { before(async () => { - await PageObjects.security.login('elastic', 'changeme'); + // await PageObjects.security.login('elastic', 'changeme'); await PageObjects.security.initTests(); await kibanaServer.uiSettings.update({ 'dateFormat:tz': 'UTC', diff --git a/x-pack/test/functional/apps/security/rbac_phase1.js b/x-pack/test/functional/apps/security/rbac_phase1.js index 4b444cfbb79dd5..3f1dcb162b5109 100644 --- a/x-pack/test/functional/apps/security/rbac_phase1.js +++ b/x-pack/test/functional/apps/security/rbac_phase1.js @@ -77,7 +77,7 @@ export default function ({ getService, getPageObjects }) { const toTime = '2015-09-23 18:31:44.000'; const vizName1 = 'Visualization VerticalBarChart'; - log.debug('navigateToApp visualize'); + log.debug('log in as kibanauser with rbac_all role'); await PageObjects.security.login('kibanauser', 'changeme'); await PageObjects.common.navigateToUrl('visualize', 'new'); log.debug('clickVerticalBarChart'); @@ -99,7 +99,7 @@ export default function ({ getService, getPageObjects }) { const toTime = '2015-09-23 18:31:44.000'; const vizName1 = 'Viz VerticalBarChart'; - log.debug('navigateToApp visualize'); + log.debug('log in as kibanareadonly with rbac_read role'); await PageObjects.security.login('kibanareadonly', 'changeme'); await PageObjects.common.navigateToUrl('visualize', 'new'); log.debug('clickVerticalBarChart'); diff --git a/x-pack/test/functional/apps/security/security.js b/x-pack/test/functional/apps/security/security.js index fef30cd573fa7c..3cb09a3adf8a46 100644 --- a/x-pack/test/functional/apps/security/security.js +++ b/x-pack/test/functional/apps/security/security.js @@ -29,7 +29,7 @@ export default function ({ getService, getPageObjects }) { }); it('displays message if login fails', async () => { - await PageObjects.security.loginPage.login('wrong-user', 'wrong-password'); + await PageObjects.security.loginPage.login('wrong-user', 'wrong-password', false); const errorMessage = await PageObjects.security.loginPage.getErrorMessage(); expect(errorMessage).to.be('Oops! Error. Try again.'); }); diff --git a/x-pack/test/functional/page_objects/security_page.js b/x-pack/test/functional/page_objects/security_page.js index 4c17eb7437e884..6c1912fd3f6cf9 100644 --- a/x-pack/test/functional/page_objects/security_page.js +++ b/x-pack/test/functional/page_objects/security_page.js @@ -19,7 +19,7 @@ export function SecurityPageProvider({ getService, getPageObjects }) { const PageObjects = getPageObjects(['common', 'header', 'settings']); class LoginPage { - async login(username, password) { + async login(username, password, expectSuccess = true) { const [superUsername, superPassword] = config.get('servers.elasticsearch.auth').split(':'); username = username || superUsername; @@ -29,6 +29,11 @@ export function SecurityPageProvider({ getService, getPageObjects }) { await testSubjects.setValue('loginUsername', username); await testSubjects.setValue('loginPassword', password); await testSubjects.click('loginSubmit'); + // wait for either kibanaChrome or loginErrorMessage + if (expectSuccess) { + await remote.setFindTimeout(20000).findByCssSelector('[data-test-subj="kibanaChrome"] nav:not(.ng-hide)'); + log.debug(`Finished login process currentUrl = ${await remote.getCurrentUrl()}`); + } } async getErrorMessage() {