From 04db5b3ec77c8be684e2e76d6f1b37e2e4f67971 Mon Sep 17 00:00:00 2001 From: Larry Gregory Date: Tue, 16 Jun 2020 15:06:56 -0400 Subject: [PATCH] [7.8] Resolve security cloud test failures (#68935) (#69301) Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com> Co-authored-by: Elastic Machine Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com> Co-authored-by: Elastic Machine --- .../functional/page_objects/security_page.ts | 173 ++++++++---------- 1 file changed, 72 insertions(+), 101 deletions(-) diff --git a/x-pack/test/functional/page_objects/security_page.ts b/x-pack/test/functional/page_objects/security_page.ts index 57f62ab33e39a6..395e41a91f53a4 100644 --- a/x-pack/test/functional/page_objects/security_page.ts +++ b/x-pack/test/functional/page_objects/security_page.ts @@ -16,6 +16,7 @@ export function SecurityPageProvider({ getService, getPageObjects }: FtrProvider const testSubjects = getService('testSubjects'); const esArchiver = getService('esArchiver'); const userMenu = getService('userMenu'); + const comboBox = getService('comboBox'); const PageObjects = getPageObjects(['common', 'header', 'settings', 'home', 'error']); interface LoginOptions { @@ -273,11 +274,7 @@ export function SecurityPageProvider({ getService, getPageObjects }: FtrProvider async addIndexToRole(index: string) { log.debug(`Adding index ${index} to role`); - const indexInput = await retry.try(() => - find.byCssSelector('[data-test-subj="indicesInput0"] input') - ); - await indexInput.type(index); - await indexInput.type('\n'); + await comboBox.setCustom('indicesInput0', index); } async addPrivilegeToRole(privilege: string) { @@ -400,104 +397,78 @@ export function SecurityPageProvider({ getService, getPageObjects }: FtrProvider } } - addRole(roleName: string, roleObj: Role) { + async addRole(roleName: string, roleObj: Role) { const self = this; - return ( - this.clickNewRole() - .then(function () { - // We have to use non-test-subject selectors because this markup is generated by ui-select. - log.debug('roleObj.indices[0].names = ' + roleObj.elasticsearch.indices[0].names); - return testSubjects.append('roleFormNameInput', roleName); - }) - .then(function () { - return find.setValue( - '[data-test-subj="indicesInput0"] input', - roleObj.elasticsearch.indices[0].names + '\n' - ); - }) - .then(function () { - return testSubjects.click('restrictDocumentsQuery0'); - }) - .then(function () { - if (roleObj.elasticsearch.indices[0].query) { - return testSubjects.setValue('queryInput0', roleObj.elasticsearch.indices[0].query); - } - }) - - // KibanaPrivilege - .then(async () => { - const globalPrivileges = (roleObj.kibana as any).global; - if (globalPrivileges) { - for (const privilegeName of globalPrivileges) { - const button = await testSubjects.find('addSpacePrivilegeButton'); - await button.click(); - - const spaceSelector = await testSubjects.find('spaceSelectorComboBox'); - await spaceSelector.click(); - - const globalSpaceOption = await find.byCssSelector(`#spaceOption_\\*`); - await globalSpaceOption.click(); - - const basePrivilegeSelector = await testSubjects.find('basePrivilegeComboBox'); - await basePrivilegeSelector.click(); - - const privilegeOption = await find.byCssSelector(`#basePrivilege_${privilegeName}`); - await privilegeOption.click(); - - const createPrivilegeButton = await testSubjects.find('createSpacePrivilegeButton'); - await createPrivilegeButton.click(); - } - } - }) - - .then(function () { - function addPrivilege(privileges: string[]) { - return privileges.reduce(function (promise: Promise, privilegeName: string) { - // We have to use non-test-subject selectors because this markup is generated by ui-select. - return promise - .then(() => self.addPrivilegeToRole(privilegeName)) - .then(() => PageObjects.common.sleep(250)); - }, Promise.resolve()); - } - return addPrivilege(roleObj.elasticsearch.indices[0].privileges); - }) - // clicking the Granted fields and removing the asterix - .then(async function () { - function addGrantedField(field: string[]) { - return field.reduce(function (promise: Promise, fieldName: string) { - return promise - .then(function () { - return find.setValue('[data-test-subj="fieldInput0"] input', fieldName + '\n'); - }) - .then(function () { - return PageObjects.common.sleep(1000); - }); - }, Promise.resolve()); - } - - if (roleObj.elasticsearch.indices[0].field_security) { - // Toggle FLS switch - await testSubjects.click('restrictFieldsQuery0'); - - // have to remove the '*' - return find - .clickByCssSelector( - 'div[data-test-subj="fieldInput0"] [title="Remove * from selection in this group"] svg.euiIcon' - ) - .then(function () { - return addGrantedField(roleObj.elasticsearch.indices[0].field_security!.grant!); - }); - } - }) // clicking save button - .then(async () => { - log.debug('click save button'); - await testSubjects.click('roleFormSaveButton'); - }) - .then(function () { - return PageObjects.common.sleep(5000); - }) - ); + await this.clickNewRole(); + + // We have to use non-test-subject selectors because this markup is generated by ui-select. + log.debug('roleObj.indices[0].names = ' + roleObj.elasticsearch.indices[0].names); + await testSubjects.append('roleFormNameInput', roleName); + + for (const indexName of roleObj.elasticsearch.indices[0].names) { + await comboBox.setCustom('indicesInput0', indexName); + } + + if (roleObj.elasticsearch.indices[0].query) { + await testSubjects.click('restrictDocumentsQuery0'); + await testSubjects.setValue('queryInput0', roleObj.elasticsearch.indices[0].query); + } + + const globalPrivileges = (roleObj.kibana as any).global; + if (globalPrivileges) { + for (const privilegeName of globalPrivileges) { + await testSubjects.click('addSpacePrivilegeButton'); + + await testSubjects.click('spaceSelectorComboBox'); + + const globalSpaceOption = await find.byCssSelector(`#spaceOption_\\*`); + await globalSpaceOption.click(); + + await testSubjects.click('basePrivilegeComboBox'); + + const privilegeOption = await find.byCssSelector(`#basePrivilege_${privilegeName}`); + await privilegeOption.click(); + + await testSubjects.click('createSpacePrivilegeButton'); + } + } + + function addPrivilege(privileges: string[]) { + return privileges.reduce(function (promise: Promise, privilegeName: string) { + return promise + .then(() => self.addPrivilegeToRole(privilegeName)) + .then(() => PageObjects.common.sleep(250)); + }, Promise.resolve()); + } + + await addPrivilege(roleObj.elasticsearch.indices[0].privileges); + + async function addGrantedField(fields: string[]) { + for (const entry of fields) { + await comboBox.setCustom('fieldInput0', entry); + } + } + + // clicking the Granted fields and removing the asterix + if (roleObj.elasticsearch.indices[0].field_security) { + // Toggle FLS switch + await testSubjects.click('restrictFieldsQuery0'); + + // have to remove the '*' + await find.clickByCssSelector( + 'div[data-test-subj="fieldInput0"] [title="Remove * from selection in this group"] svg.euiIcon' + ); + + await addGrantedField(roleObj.elasticsearch.indices[0].field_security!.grant!); + } + + log.debug('click save button'); + await testSubjects.click('roleFormSaveButton'); + + // Signifies that the role management page redirected back to the role grid page, + // and successfully refreshed the grid + await testSubjects.existOrFail('roleRow'); } async selectRole(role: string) {