Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reporting Test Serverless structure: api_integration #7

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .buildkite/ftr_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,10 @@ disabled:
- x-pack/test_serverless/api_integration/test_suites/observability/config.ts
- x-pack/test_serverless/api_integration/test_suites/search/config.ts
- x-pack/test_serverless/api_integration/test_suites/security/config.ts
- x-pack/test_serverless/api_integration/test_suites/reporting/config.ts
- x-pack/test_serverless/functional/test_suites/common/config.ts
- x-pack/test_serverless/functional/test_suites/observability/config.ts
- x-pack/test_serverless/functional/test_suites/search/config.ts
- x-pack/test_serverless/functional/test_suites/security/config.ts
- x-pack/test_serverless/functional/test_suites/reporting/config.ts
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By design, the only serverless test suites are: observability, search, security and common. Reporting tests should go under common.


defaultQueue: 'n2-4-spot'
enabled:
Expand Down
5 changes: 3 additions & 2 deletions x-pack/test_serverless/api_integration/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import { services as xpackApiIntegrationServices } from '../../../test/api_integ
import { services as svlSharedServices } from '../../shared/services';

import { SvlCommonApiServiceProvider } from './svl_common_api';
import { SvlReportingServiceProvider } from './svl_reporting';
import { AlertingApiProvider } from './alerting_api';
import { ReportingApiProvider } from './reporting_api';

export const services = {
...xpackApiIntegrationServices,
...svlSharedServices,

svlCommonApi: SvlCommonApiServiceProvider,
svlReportingAPI: SvlReportingServiceProvider,
alertingApi: AlertingApiProvider,
reportingApi: ReportingApiProvider,
};

export type InheritedFtrProviderContext = GenericFtrProviderContext<typeof services, {}>;
Expand Down
22 changes: 0 additions & 22 deletions x-pack/test_serverless/api_integration/services/reporting_api.ts

This file was deleted.

99 changes: 99 additions & 0 deletions x-pack/test_serverless/api_integration/services/svl_reporting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* 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 { FtrProviderContext } from '../ftr_provider_context';

const DATA_ANALYST_PASSWORD = 'data_analyst-password';
const DATA_ANALYST_ROLE = 'data_analyst_role';
const DATA_ANALYST_USERNAME = 'data_analyst';
const REPORTING_ROLE = 'reporting_user_role';
const REPORTING_USER_PASSWORD = 'reporting_user-password';
const REPORTING_USER_USERNAME = 'reporting_user';

export function SvlReportingServiceProvider({ getService }: FtrProviderContext) {
const security = getService('security');

return {
DATA_ANALYST_PASSWORD,
DATA_ANALYST_USERNAME,
REPORTING_USER_PASSWORD,
REPORTING_USER_USERNAME,

/**
* Define a role that DOES NOT grant privileges to create any type of report.
*/
async createDataAnalystRole() {
await security.role.create(DATA_ANALYST_ROLE, {
metadata: {},
elasticsearch: {
cluster: [],
indices: [
{
names: ['ecommerce'],
privileges: ['read', 'view_index_metadata'],
allow_restricted_indices: false,
},
],
run_as: [],
},
kibana: [
{
base: ['read'],
feature: {},
spaces: ['*'],
},
],
});
},

async createDataAnalystUser() {
await security.user.create(DATA_ANALYST_USERNAME, {
password: DATA_ANALYST_PASSWORD,
roles: [DATA_ANALYST_ROLE],
full_name: 'Data Analyst User',
});
},

/**
* Define a role that DOES grant privileges to create certain types of reports.
*/
async createReportingRole() {
await security.role.create(REPORTING_ROLE, {
metadata: {},
elasticsearch: {
cluster: [],
indices: [
{
names: ['ecommerce'],
privileges: ['read', 'view_index_metadata'],
allow_restricted_indices: false,
},
],
run_as: [],
},
kibana: [
{
base: [],
feature: { discover: ['minimal_read', 'generate_report'] },
spaces: ['*'],
},
],
});
},

async createReportingUser(
username = REPORTING_USER_USERNAME,
password = REPORTING_USER_PASSWORD
) {
await security.user.create(username, {
password,
roles: [REPORTING_ROLE],
full_name: 'Reporting User',
});
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./security_users'));
loadTestFile(require.resolve('./spaces'));
loadTestFile(require.resolve('./security_response_headers'));
loadTestFile(require.resolve('./reporting'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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 { FtrProviderContext } from '../../../ftr_provider_context';

export default ({ loadTestFile }: FtrProviderContext) => {
describe('Reporting', function () {
loadTestFile(require.resolve('./management'));
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* 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 { X_ELASTIC_INTERNAL_ORIGIN_REQUEST } from '@kbn/core-http-common/src/constants';
import { INTERNAL_ROUTES } from '@kbn/reporting-plugin/common/constants';
import { FtrProviderContext } from '../../../ftr_provider_context';

// the archived data holds a report created by test_user
const TEST_USERNAME = 'test_user';
const TEST_USER_PASSWORD = 'changeme';
const API_HEADER: [string, string] = ['kbn-xsrf', 'reporting'];
const INTERNAL_HEADER: [string, string] = [X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'Kibana'];

export default ({ getService }: FtrProviderContext) => {
const esArchiver = getService('esArchiver');
const reportingAPI = getService('svlReportingAPI');
const supertest = getService('supertestWithoutAuth');

describe('Reporting Management', function () {
before(async () => {
// NOTE: unused, since we only need test_user for this suite
await reportingAPI.createReportingRole();
await reportingAPI.createReportingUser();
await reportingAPI.createReportingUser(TEST_USERNAME, TEST_USER_PASSWORD);
});

beforeEach(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/reporting/archived_reports');
});

after(async () => {
await esArchiver.unload('x-pack/test/functional/es_archives/reporting/archived_reports');
});

describe('Deletion', () => {
const DELETE_REPORT_ID = 'krazcyw4156m0763b503j7f9';

it(`user can delete a report they've created`, async () => {
const response = await supertest
.delete(`${INTERNAL_ROUTES.JOBS.DELETE_PREFIX}/${DELETE_REPORT_ID}`)
.auth(TEST_USERNAME, TEST_USER_PASSWORD)
.set(...API_HEADER)
.set(...INTERNAL_HEADER);

expect(response.status).to.be(200);
expect(response.body).to.eql({ deleted: true });
});

it(`user can not delete a report they haven't created`, async () => {
const response = await supertest
.delete(`${INTERNAL_ROUTES.JOBS.DELETE_PREFIX}/${DELETE_REPORT_ID}`)
.auth(reportingAPI.REPORTING_USER_USERNAME, reportingAPI.REPORTING_USER_PASSWORD)
.set(...API_HEADER)
.set(...INTERNAL_HEADER);

expect(response.status).to.be(404);
expect(response.body.message).to.be('Not Found');
});
});
});
};

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading