Skip to content

Commit

Permalink
Add FTR test for new API
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Jan 26, 2023
1 parent 0ec638a commit 0e17eaf
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
92 changes: 92 additions & 0 deletions x-pack/test/ftr_apis/security_and_spaces/apis/clean.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';
import { USERS, User, ExpectedResponse } from '../../common/lib';
import { FtrProviderContext } from '../services';
import { createData, createTestSpaces, deleteData, deleteTestSpaces } from './test_utils';

// eslint-disable-next-line import/no-default-export
export default function (ftrContext: FtrProviderContext) {
const supertest = ftrContext.getService('supertestWithoutAuth');

describe('POST /internal/ftr/kbn_client_so/_clean', () => {
before(async () => {
await createTestSpaces(ftrContext);
});

after(async () => {
await deleteTestSpaces(ftrContext);
});

beforeEach(async () => {
await createData(ftrContext);
});

afterEach(async () => {
await deleteData(ftrContext);
});

const responses: Record<string, ExpectedResponse> = {
authorized: {
httpCode: 200,
expectResponse: ({ body }) => {
expect(body.deleted).to.be.greaterThan(0);
},
},
unauthorized: {
httpCode: 403,
expectResponse: ({ body }) => {
expect(body).to.eql({
error: 'Forbidden',
message: 'Forbidden',
statusCode: 403,
});
},
},
};
const expectedResults: Record<string, User[]> = {
authorized: [USERS.SUPERUSER],
unauthorized: [
USERS.DEFAULT_SPACE_READ_USER,
USERS.DEFAULT_SPACE_SO_MANAGEMENT_WRITE_USER,
USERS.DEFAULT_SPACE_SO_TAGGING_READ_USER,
USERS.DEFAULT_SPACE_SO_TAGGING_WRITE_USER,
USERS.DEFAULT_SPACE_DASHBOARD_READ_USER,
USERS.DEFAULT_SPACE_VISUALIZE_READ_USER,
USERS.DEFAULT_SPACE_MAPS_READ_USER,
USERS.DEFAULT_SPACE_ADVANCED_SETTINGS_READ_USER,
USERS.NOT_A_KIBANA_USER,
],
};

const createUserTest = (
{ username, password, description }: User,
{ httpCode, expectResponse }: ExpectedResponse
) => {
it(`returns expected ${httpCode} response for ${description ?? username}`, async () => {
await supertest
.post(`/internal/ftr/kbn_client_so/_find`)
.send({ types: ['tag', 'dashboard', 'visualization'] })
.auth(username, password)
.expect(httpCode)
.then(expectResponse);
});
};

const createTestSuite = () => {
Object.entries(expectedResults).forEach(([responseId, users]) => {
const response: ExpectedResponse = responses[responseId];
users.forEach((user) => {
createUserTest(user, response);
});
});
};

createTestSuite();
});
}
1 change: 1 addition & 0 deletions x-pack/test/ftr_apis/security_and_spaces/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./delete'));
loadTestFile(require.resolve('./find'));
loadTestFile(require.resolve('./bulk_delete'));
loadTestFile(require.resolve('./clean'));
});
}

0 comments on commit 0e17eaf

Please sign in to comment.