[7.x] Resolve security cloud test failures (#68935) (#69300)

Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Larry Gregory 2020-06-16 15:06:37 -04:00 committed by GitHub
parent 65679d3842
commit a202e49f52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
}
})
await this.clickNewRole();
// 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();
// 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);
const spaceSelector = await testSubjects.find('spaceSelectorComboBox');
await spaceSelector.click();
for (const indexName of roleObj.elasticsearch.indices[0].names) {
await comboBox.setCustom('indicesInput0', indexName);
}
const globalSpaceOption = await find.byCssSelector(`#spaceOption_\\*`);
await globalSpaceOption.click();
if (roleObj.elasticsearch.indices[0].query) {
await testSubjects.click('restrictDocumentsQuery0');
await testSubjects.setValue('queryInput0', roleObj.elasticsearch.indices[0].query);
}
const basePrivilegeSelector = await testSubjects.find('basePrivilegeComboBox');
await basePrivilegeSelector.click();
const globalPrivileges = (roleObj.kibana as any).global;
if (globalPrivileges) {
for (const privilegeName of globalPrivileges) {
await testSubjects.click('addSpacePrivilegeButton');
const privilegeOption = await find.byCssSelector(`#basePrivilege_${privilegeName}`);
await privilegeOption.click();
await testSubjects.click('spaceSelectorComboBox');
const createPrivilegeButton = await testSubjects.find('createSpacePrivilegeButton');
await createPrivilegeButton.click();
}
}
})
const globalSpaceOption = await find.byCssSelector(`#spaceOption_\\*`);
await globalSpaceOption.click();
.then(function () {
function addPrivilege(privileges: string[]) {
return privileges.reduce(function (promise: Promise<any>, 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<any>, 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());
}
await testSubjects.click('basePrivilegeComboBox');
if (roleObj.elasticsearch.indices[0].field_security) {
// Toggle FLS switch
await testSubjects.click('restrictFieldsQuery0');
const privilegeOption = await find.byCssSelector(`#basePrivilege_${privilegeName}`);
await privilegeOption.click();
// 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 testSubjects.click('createSpacePrivilegeButton');
}
}
function addPrivilege(privileges: string[]) {
return privileges.reduce(function (promise: Promise<any>, 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) {