[7.x] Fix role mappings test for ESS (#80604) (#80722)

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

Co-authored-by: Joe Portner <5295965+jportner@users.noreply.github.com>
This commit is contained in:
Larry Gregory 2020-10-15 20:29:37 -04:00 committed by GitHub
parent e88ac42fb3
commit 0981beb9ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View file

@ -23,10 +23,24 @@ import { KbnClient, ToolingLog } from '@kbn/dev-utils';
export class RoleMappings {
constructor(private log: ToolingLog, private kbnClient: KbnClient) {}
public async getAll() {
this.log.debug(`Getting role mappings`);
const { data, status, statusText } = await this.kbnClient.request<Array<{ name: string }>>({
path: `/internal/security/role_mapping`,
method: 'GET',
});
if (status !== 200) {
throw new Error(
`Expected status code of 200, received ${status} ${statusText}: ${util.inspect(data)}`
);
}
return data;
}
public async create(name: string, roleMapping: Record<string, any>) {
this.log.debug(`creating role mapping ${name}`);
const { data, status, statusText } = await this.kbnClient.request({
path: `/internal/security/role_mapping/${name}`,
path: `/internal/security/role_mapping/${encodeURIComponent(name)}`,
method: 'POST',
body: roleMapping,
});
@ -41,7 +55,7 @@ export class RoleMappings {
public async delete(name: string) {
this.log.debug(`deleting role mapping ${name}`);
const { data, status, statusText } = await this.kbnClient.request({
path: `/internal/security/role_mapping/${name}`,
path: `/internal/security/role_mapping/${encodeURIComponent(name)}`,
method: 'DELETE',
});
if (status !== 200 && status !== 404) {

View file

@ -17,6 +17,10 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
describe('Role Mappings', function () {
before(async () => {
// Delete any existing role mappings. ESS commonly sets up a role mapping automatically.
const existingMappings = await security.roleMappings.getAll();
await Promise.all(existingMappings.map((m) => security.roleMappings.delete(m.name)));
await pageObjects.common.navigateToApp('roleMappings');
});