Skip to content

Commit

Permalink
[APM] Fix certificate issue with serverless tests (#165682)
Browse files Browse the repository at this point in the history
## Summary

Resolves skipped APM serverless tests.
tests were failing due to certificate issue.

#165138
  • Loading branch information
achyutjhunjhunwala authored Sep 5, 2023
1 parent 0f927b8 commit 212a4a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { ApmUsername } from '@kbn/apm-plugin/server/test_helpers/create_apm_users/authentication';
import { format, UrlObject } from 'url';
import { format } from 'url';
import supertest from 'supertest';
import request from 'superagent';
import type {
APIReturnType,
APIClientRequestParamsOf,
} from '@kbn/apm-plugin/public/services/rest/create_call_apm_api';
import { kbnTestConfig } from '@kbn/test';
import { Config, kbnTestConfig, kibanaTestSuperuserServerless } from '@kbn/test';
import type { APIEndpoint } from '@kbn/apm-plugin/server';
import { formatRequest } from '@kbn/server-route-repository';
import { InheritedFtrProviderContext } from '../../../../services';
Expand Down Expand Up @@ -93,19 +92,19 @@ Body: ${JSON.stringify(res.body)}`
}
}

async function getApmApiClient({
kibanaServer,
username,
}: {
kibanaServer: UrlObject;
username: ApmUsername | 'elastic';
}) {
async function getApmApiClient({ svlSharedConfig }: { svlSharedConfig: Config }) {
const kibanaServer = svlSharedConfig.get('servers.kibana');
const cAuthorities = svlSharedConfig.get('servers.kibana.certificateAuthorities');

const username = kbnTestConfig.getUrlParts(kibanaTestSuperuserServerless).username;
const password = kbnTestConfig.getUrlParts(kibanaTestSuperuserServerless).password;

const url = format({
...kibanaServer,
auth: `${username}:${kbnTestConfig.getUrlParts().password}`,
auth: `${username}:${password}`,
});

return createApmApiClient(supertest(url));
return createApmApiClient(supertest.agent(url, { ca: cAuthorities }));
}

export interface SupertestReturnType<TEndpoint extends APIEndpoint> {
Expand All @@ -120,12 +119,10 @@ export async function getApmApiClientService({
getService,
}: InheritedFtrProviderContext): Promise<ApmApiClient> {
const svlSharedConfig = getService('config');
const kibanaServer = svlSharedConfig.get('servers.kibana');

return {
slsUser: await getApmApiClient({
kibanaServer,
username: 'elastic',
svlSharedConfig,
}),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import expect from 'expect';
import { APMFtrContextProvider } from './common/services';
import { ApmApiClient } from './common/apm_api_supertest';

const fleetMigrationResponse = {
statusCode: 404,
Expand Down Expand Up @@ -48,7 +49,7 @@ const SAMPLE_SOURCEMAP = {
mappings: 'A,AAAB;;ABCDE;',
};

async function uploadSourcemap(apmApiClient: any) {
async function uploadSourcemap(apmApiClient: ApmApiClient) {
const response = await apmApiClient.slsUser({
endpoint: 'POST /api/apm/sourcemaps 2023-10-31',
type: 'form-data',
Expand All @@ -67,8 +68,7 @@ async function uploadSourcemap(apmApiClient: any) {
export default function ({ getService }: APMFtrContextProvider) {
const apmApiClient = getService('apmApiClient');

// Issue: https://github.com/elastic/kibana/issues/165138
describe.skip('apm feature flags', () => {
describe('apm feature flags', () => {
describe('fleet migrations', () => {
it('rejects requests to save apm server schema', async () => {
try {
Expand Down

0 comments on commit 212a4a0

Please sign in to comment.