[Reporting] Increase functional tests on feature priviliges (#117443) (#117896)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Tim Sullivan 2021-11-08 23:24:00 -07:00 committed by GitHub
parent 2ca2788154
commit d801c82276
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,12 +7,12 @@
import expect from '@kbn/expect';
import { SearchSourceFields } from 'src/plugins/data/common';
import supertest from 'supertest';
import { FtrProviderContext } from '../ftr_provider_context';
// eslint-disable-next-line import/no-default-export
export default function ({ getService }: FtrProviderContext) {
const reportingAPI = getService('reportingAPI');
const supertest = getService('supertest');
describe('Security Roles and Privileges for Applications', () => {
before(async () => {
@ -25,7 +25,7 @@ export default function ({ getService }: FtrProviderContext) {
describe('Dashboard: CSV download file', () => {
it('does not allow user that does not have the role-based privilege', async () => {
const res = (await reportingAPI.downloadCsv(
const res = await reportingAPI.downloadCsv(
reportingAPI.DATA_ANALYST_USERNAME,
reportingAPI.DATA_ANALYST_PASSWORD,
{
@ -37,12 +37,12 @@ export default function ({ getService }: FtrProviderContext) {
browserTimezone: 'UTC',
title: 'testfooyu78yt90-',
}
)) as supertest.Response;
);
expect(res.status).to.eql(403);
});
it('does allow user with the role privilege', async () => {
const res = (await reportingAPI.downloadCsv(
const res = await reportingAPI.downloadCsv(
reportingAPI.REPORTING_USER_USERNAME,
reportingAPI.REPORTING_USER_PASSWORD,
{
@ -54,7 +54,7 @@ export default function ({ getService }: FtrProviderContext) {
browserTimezone: 'UTC',
title: 'testfooyu78yt90-',
}
)) as supertest.Response;
);
expect(res.status).to.eql(200);
});
});
@ -197,5 +197,21 @@ export default function ({ getService }: FtrProviderContext) {
expect(res.status).to.eql(200);
});
});
// This tests the same API as x-pack/test/api_integration/apis/security/privileges.ts, but it uses the non-deprecated config
it('should register reporting privileges with the security privileges API', async () => {
await supertest
.get('/api/security/privileges')
.set('kbn-xsrf', 'xxx')
.send()
.expect(200)
.expect((res) => {
expect(res.body.features.canvas).match(/generate_report/);
expect(res.body.features.dashboard).match(/download_csv_report/);
expect(res.body.features.dashboard).match(/generate_report/);
expect(res.body.features.discover).match(/generate_report/);
expect(res.body.features.visualize).match(/generate_report/);
});
});
});
}