[APM] Fix 401 issue with Serverless tests for APM (#164162)

## Summary

Fix credential issues for running serverless tests for APM against MKI
This commit is contained in:
Achyut Jhunjhunwala 2023-08-17 16:47:27 +02:00 committed by GitHub
parent 276cf86858
commit b7e009a6fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 27 deletions

View file

@ -138,5 +138,3 @@ export const users: Record<
customRoleNames: [ApmCustomRolename.apmManageServiceAccount],
},
};
export const APM_TEST_PASSWORD = 'changeme';

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import { APM_TEST_PASSWORD } from '@kbn/apm-plugin/server/test_helpers/create_apm_users/authentication';
import {
ApmSynthtraceEsClient,
ApmSynthtraceKibanaClient,
@ -14,7 +13,7 @@ import {
InfraSynthtraceEsClient,
LogLevel,
} from '@kbn/apm-synthtrace';
import { FtrConfigProviderContext } from '@kbn/test';
import { FtrConfigProviderContext, kbnTestConfig } from '@kbn/test';
import url from 'url';
import { FtrProviderContext as InheritedFtrProviderContext } from '../../ftr_provider_context';
import { InheritedServices } from './types';
@ -64,7 +63,7 @@ export default async function createTestConfig({
const kibanaServerUrlWithAuth = url
.format({
...url.parse(kibanaServerUrl),
auth: `elastic:${APM_TEST_PASSWORD}`,
auth: `elastic:${kbnTestConfig.getUrlParts().password}`,
})
.slice(0, -1);

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import { APM_TEST_PASSWORD } from '@kbn/apm-plugin/server/test_helpers/create_apm_users/authentication';
import {
ApmSynthtraceEsClient,
ApmSynthtraceKibanaClient,
@ -14,7 +13,7 @@ import {
InfraSynthtraceEsClient,
LogLevel,
} from '@kbn/apm-synthtrace';
import { FtrConfigProviderContext } from '@kbn/test';
import { FtrConfigProviderContext, kbnTestConfig } from '@kbn/test';
import url from 'url';
import { FtrProviderContext as InheritedFtrProviderContext } from '../../ftr_provider_context';
import { InheritedServices } from './types';
@ -64,7 +63,7 @@ export default async function createTestConfig({
const kibanaServerUrlWithAuth = url
.format({
...url.parse(kibanaServerUrl),
auth: `elastic:${APM_TEST_PASSWORD}`,
auth: `elastic:${kbnTestConfig.getUrlParts().password}`,
})
.slice(0, -1);

View file

@ -4,7 +4,6 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { APM_TEST_PASSWORD } from '@kbn/apm-plugin/server/test_helpers/create_apm_users/authentication';
import {
ApmSynthtraceEsClient,
ApmSynthtraceKibanaClient,
@ -12,6 +11,7 @@ import {
LogLevel,
} from '@kbn/apm-synthtrace';
import url from 'url';
import { kbnTestConfig } from '@kbn/test';
import { InheritedFtrProviderContext } from './ftr_provider_context';
export async function bootstrapApmSynthtrace(
@ -37,7 +37,7 @@ export function getApmSynthtraceKibanaClient(kibanaServerUrl: string) {
const kibanaServerUrlWithAuth = url
.format({
...url.parse(kibanaServerUrl),
auth: `elastic:${APM_TEST_PASSWORD}`,
auth: `elastic:${kbnTestConfig.getUrlParts().password}`,
})
.slice(0, -1);

View file

@ -5,13 +5,10 @@
* 2.0.
*/
import {
ApmUsername,
APM_TEST_PASSWORD,
} from '@kbn/apm-plugin/server/test_helpers/create_apm_users/authentication';
import { ApmUsername } from '@kbn/apm-plugin/server/test_helpers/create_apm_users/authentication';
import { createApmUsers } from '@kbn/apm-plugin/server/test_helpers/create_apm_users/create_apm_users';
import { ApmSynthtraceEsClient, ApmSynthtraceKibanaClient } from '@kbn/apm-synthtrace';
import { FtrConfigProviderContext } from '@kbn/test';
import { FtrConfigProviderContext, kbnTestConfig } from '@kbn/test';
import supertest from 'supertest';
import { format, UrlObject } from 'url';
import { MachineLearningAPIProvider } from '../../functional/services/ml/api';
@ -40,7 +37,7 @@ async function getApmApiClient({
}) {
const url = format({
...kibanaServer,
auth: `${username}:${APM_TEST_PASSWORD}`,
auth: `${username}:${kbnTestConfig.getUrlParts().password}`,
});
return createApmApiClient(supertest(url));

View file

@ -10,10 +10,8 @@ import { castArray, groupBy } from 'lodash';
import callsites from 'callsites';
import { maybe } from '@kbn/apm-plugin/common/utils/maybe';
import { joinByKey } from '@kbn/apm-plugin/common/utils/join_by_key';
import {
ApmUsername,
APM_TEST_PASSWORD,
} from '@kbn/apm-plugin/server/test_helpers/create_apm_users/authentication';
import { ApmUsername } from '@kbn/apm-plugin/server/test_helpers/create_apm_users/authentication';
import { kbnTestConfig } from '@kbn/test';
import { APMFtrConfigName } from '../configs';
import { FtrProviderContext } from './ftr_provider_context';
@ -155,7 +153,7 @@ export function RegistryProvider({ getService }: FtrProviderContext) {
await supertest
.get('/api/ml/saved_objects/sync')
.set('kbn-xsrf', 'foo')
.auth(ApmUsername.editorUser, APM_TEST_PASSWORD);
.auth(ApmUsername.editorUser, kbnTestConfig.getUrlParts().password);
}
if (condition.archives.length) {
log('Loaded all archives');

View file

@ -4,11 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import {
ApmUsername,
APM_TEST_PASSWORD,
// eslint-disable-next-line @kbn/imports/no_boundary_crossing
} from '@kbn/apm-plugin/server/test_helpers/create_apm_users/authentication';
import type { ApmUsername } from '@kbn/apm-plugin/server/test_helpers/create_apm_users/authentication';
import { format, UrlObject } from 'url';
import supertest from 'supertest';
import request from 'superagent';
@ -16,6 +12,7 @@ import type {
APIReturnType,
APIClientRequestParamsOf,
} from '@kbn/apm-plugin/public/services/rest/create_call_apm_api';
import { kbnTestConfig } from '@kbn/test';
import type { APIEndpoint } from '@kbn/apm-plugin/server';
import { formatRequest } from '@kbn/server-route-repository';
import { InheritedFtrProviderContext } from '../../../../services';
@ -105,7 +102,7 @@ async function getApmApiClient({
}) {
const url = format({
...kibanaServer,
auth: `${username}:${APM_TEST_PASSWORD}`,
auth: `${username}:${kbnTestConfig.getUrlParts().password}`,
});
return createApmApiClient(supertest(url));