Skip to content

Commit

Permalink
[7.8] Resolve security cloud test failures (#68935) (#69301)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
3 people authored Jun 16, 2020
1 parent 5d55b9f commit 04db5b3
Showing 1 changed file with 72 additions and 101 deletions.
173 changes: 72 additions & 101 deletions x-pack/test/functional/page_objects/security_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<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());
}

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<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) {
Expand Down

0 comments on commit 04db5b3

Please sign in to comment.