Skip to content
/ kibana Public
forked from elastic/kibana

Commit

Permalink
[7.10] Fix role mappings test for ESS (elastic#80604) (elastic#80723)
Browse files Browse the repository at this point in the history
Co-authored-by: Joe Portner <[email protected]>

Co-authored-by: Joe Portner <[email protected]>
  • Loading branch information
legrego and jportner authored Oct 16, 2020
1 parent e5af64e commit 06c9a44
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
18 changes: 16 additions & 2 deletions test/common/services/security/role_mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions x-pack/test/functional/apps/security/role_mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down

0 comments on commit 06c9a44

Please sign in to comment.