Skip to content

Commit

Permalink
[SecuritySolution] Remove duplicated serverless tests (#188855)
Browse files Browse the repository at this point in the history
## Summary

1. Apply #185870 for Security
Solution Explore and Investigation tests.
2. Remove duplicated tests.
3. Investigation/timeline/serverless tests are skipped atm.

How to run the api integration tests (Use Investigation Timeline ESS as
an example)
```
cd x-pack

node scripts/functional_tests_server.js --config ./test/security_solution_api_integration/test_suites/investigation/timeline/trial_license_complete_tier/configs/ess.config.ts

// After server is started, open another terminal

cd x-pack

node ../scripts/functional_test_runner --config=test/security_solution_api_integration/test_suites/investigation/timeline/trial_license_complete_tier/configs/ess.config.ts
```

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
angorayc and kibanamachine authored Aug 6, 2024
1 parent 0eea85e commit 644e818
Show file tree
Hide file tree
Showing 63 changed files with 244 additions and 1,826 deletions.
2 changes: 1 addition & 1 deletion test/common/services/bsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const getSpaceUrlPrefix = (spaceId?: string): string => {
/**
* Options for the send method
*/
interface SendOptions {
export interface SendOptions {
supertest: SuperTest.Agent;
options: object;
strategy: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@

import { format as formatUrl } from 'url';
import supertest from 'supertest';
import { FtrProviderContext } from '../../ftr_provider_context';
import { SecuritySolutionUtils } from './types';
import { FtrProviderContextWithSpaces } from '../../ftr_provider_context_with_spaces';
import { SecuritySolutionESSUtilsInterface } from './types';

export function SecuritySolutionESSUtils({
getService,
}: FtrProviderContext): SecuritySolutionUtils {
}: FtrProviderContextWithSpaces): SecuritySolutionESSUtilsInterface {
const config = getService('config');
const bsearch = getService('bsearch');
const supertestWithoutAuth = getService('supertest');

return {
getUsername: (_role?: string) =>
Promise.resolve(config.get('servers.kibana.username') as string),
createBsearch: (_role?: string) => Promise.resolve(bsearch),
createSuperTest: async (role?: string, password: string = 'changeme') => {
if (!role) {
return supertestWithoutAuth;
Expand Down
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 async function SecuritySolutionServerlessBsearchCreator({ getService }: FtrProviderContext) {
const { createBsearch } = getService('securitySolutionUtils');

return await createBsearch('admin');
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@

import supertest from 'supertest';
import { format as formatUrl } from 'url';
import { IEsSearchResponse } from '@kbn/search-types';
import { RoleCredentials } from '@kbn/test-suites-serverless/shared/services';
import { FtrProviderContext } from '../../ftr_provider_context';
import { SecuritySolutionUtils } from './types';
import type { SendOptions } from '@kbn/test-suites-src/common/services/bsearch';
import type { SendOptions as SecureBsearchSendOptions } from '@kbn/test-suites-serverless/shared/services/bsearch_secure';
import type { FtrProviderContext } from '../../ftr_provider_context';
import type { SecuritySolutionUtilsInterface } from './types';

export function SecuritySolutionServerlessUtils({
getService,
}: FtrProviderContext): SecuritySolutionUtils {
}: FtrProviderContext): SecuritySolutionUtilsInterface {
const svlUserManager = getService('svlUserManager');
const lifecycle = getService('lifecycle');
const svlCommonApi = getService('svlCommonApi');
const config = getService('config');
const log = getService('log');
const SecureBsearch = getService('secureBsearch');

const rolesCredentials = new Map<string, RoleCredentials>();
const commonRequestHeader = svlCommonApi.getCommonRequestHeader();
Expand Down Expand Up @@ -47,6 +51,15 @@ export function SecuritySolutionServerlessUtils({
});
});

const createSuperTest = async (role = 'admin') => {
cleanCredentials(role);
const credentials = await svlUserManager.createM2mApiKeyWithRoleScope(role);
rolesCredentials.set(role, credentials);

const agentWithCommonHeaders = supertest.agent(kbnUrl).set(commonRequestHeader);
return agentWithCommonHeaders.set(credentials.apiKeyHeader);
};

return {
getUsername: async (role = 'admin') => {
const { username } = await svlUserManager.getUserData(role);
Expand All @@ -56,13 +69,32 @@ export function SecuritySolutionServerlessUtils({
/**
* Only one API key for each role can be active at a time.
*/
createSuperTest: async (role = 'admin') => {
cleanCredentials(role);
const credentials = await svlUserManager.createM2mApiKeyWithRoleScope(role);
rolesCredentials.set(role, credentials);
createSuperTest,

createBsearch: async (role = 'admin') => {
const apiKeyHeader = rolesCredentials.get(role)?.apiKeyHeader;

if (!apiKeyHeader) {
log.error(`API key for role [${role}] is not available, SecureBsearch cannot be created`);
}

const send = <T extends IEsSearchResponse>(sendOptions: SendOptions): Promise<T> => {
const { supertest: _, ...rest } = sendOptions;
const serverlessSendOptions: SecureBsearchSendOptions = {
...rest,
// We need super test WITHOUT auth to make the request here, as we are setting the auth header in bsearch `apiKeyHeader`
supertestWithoutAuth: supertest.agent(kbnUrl),
apiKeyHeader: apiKeyHeader ?? { Authorization: '' },
internalOrigin: 'Kibana',
};

log.debug(
`Sending request to SecureBsearch with options: ${JSON.stringify(serverlessSendOptions)}`
);
return SecureBsearch.send(serverlessSendOptions);
};

const agentWithCommonHeaders = supertest.agent(kbnUrl).set(commonRequestHeader);
return agentWithCommonHeaders.set(credentials.apiKeyHeader);
return { ...SecureBsearch, send };
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,23 @@
*/

import TestAgent from 'supertest/lib/agent';
import type { IEsSearchResponse } from '@kbn/search-types';

export interface SecuritySolutionUtils {
import type { BsearchSecureService } from '@kbn/test-suites-serverless/shared/services/bsearch_secure';
import type { BsearchService, SendOptions } from '@kbn/test-suites-src/common/services/bsearch';

export interface SecuritySolutionServerlessBsearch extends Omit<BsearchSecureService, 'send'> {
send: <T extends IEsSearchResponse>(options: SendOptions) => Promise<T>;
}

export interface SecuritySolutionUtilsInterface {
getUsername: (role?: string) => Promise<string>;
createSuperTest: (role?: string) => Promise<TestAgent<any>>;
createBsearch: (role?: string) => Promise<SecuritySolutionServerlessBsearch>;
}

export interface SecuritySolutionESSUtilsInterface {
getUsername: (role?: string) => Promise<string>;
createBsearch: (role?: string) => Promise<BsearchService>;
createSuperTest: (role?: string, password?: string) => Promise<TestAgent<any>>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {

return {
...functionalConfig.getAll(),
testFiles: [require.resolve('../ess')],
testFiles: [require.resolve('../tests')],
junit: {
reportName: 'Explore - Hosts Integration Tests - ESS Env - Trial License',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default createTestConfig({
{ product_line: 'cloud', product_tier: 'complete' },
])}`,
],
testFiles: [require.resolve('../serverless')],
testFiles: [require.resolve('../tests')],
junit: {
reportName: 'Explore - Hosts Integration Tests - Serverless Env - Complete Tier',
},
Expand Down

This file was deleted.

Loading

0 comments on commit 644e818

Please sign in to comment.