Skip to content

Commit

Permalink
[APM] Run API tests as restricted user
Browse files Browse the repository at this point in the history
Run API tests as a user that has the apm_user role and the kibana_admin role. These are (roughly) the minimum requirements for using APM.
  • Loading branch information
dgieselaar committed Jun 26, 2020
1 parent 2b72de5 commit c56debf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
12 changes: 12 additions & 0 deletions x-pack/test/apm_api_integration/common/authentication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export const APM_READ_USER = {
name: 'apm_read_user',
roles: ['apm_read_user', 'superuser'],
};

export const APM_TEST_PASSWORD = 'changeme';
38 changes: 35 additions & 3 deletions x-pack/test/apm_api_integration/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
*/

import { FtrConfigProviderContext } from '@kbn/test/types/ftr';
import { FtrProviderContext } from 'test/functional/ftr_provider_context';
import supertestAsPromised from 'supertest-as-promised';
import { format } from 'url';
import { APM_READ_USER, APM_TEST_PASSWORD } from './authentication';

interface Settings {
license: 'basic' | 'trial';
Expand All @@ -20,14 +24,42 @@ export function createTestConfig(settings: Settings) {
require.resolve('../../api_integration/config.ts')
);

const services = xPackAPITestsConfig.get('services');
const servers = xPackAPITestsConfig.get('servers');

servers.kibana = {
...servers.kibana,
};

return {
testFiles,
servers: xPackAPITestsConfig.get('servers'),
services: xPackAPITestsConfig.get('services'),
servers,
services: {
...services,
supertest: async (context: FtrProviderContext) => {
const security = context.getService('security');

await security.init();

await security.user.create(APM_READ_USER.name, {
password: APM_TEST_PASSWORD,
full_name: APM_READ_USER.name,
roles: APM_READ_USER.roles,
});

const url = format({
...servers.kibana,
auth: `${APM_READ_USER.name}:${APM_TEST_PASSWORD}`,
username: APM_READ_USER.name,
password: APM_TEST_PASSWORD,
});

return supertestAsPromised(url);
},
},
junit: {
reportName: name,
},

esTestCluster: {
...xPackAPITestsConfig.get('esTestCluster'),
license,
Expand Down

0 comments on commit c56debf

Please sign in to comment.