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

[SecuritySolution] Remove duplicated serverless tests #188855

Merged
merged 28 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f723bd5
remove duplicated serverless tests
angorayc Jul 22, 2024
d617931
remove console
angorayc Jul 22, 2024
ee11041
types
angorayc Jul 22, 2024
40dbf62
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jul 23, 2024
aed7547
Merge branch 'main' of github.com:elastic/kibana into api-tests-enhan…
angorayc Jul 23, 2024
d259935
fix type error
angorayc Jul 23, 2024
c2b1c0b
update tests dependency
angorayc Jul 24, 2024
7c8f9c8
Merge branch 'main' into api-tests-enhancement
angorayc Jul 24, 2024
620e7e7
Merge branch 'main' into api-tests-enhancement
angorayc Jul 24, 2024
04f910b
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jul 24, 2024
be0b2c3
Merge branch 'main' of github.com:elastic/kibana into api-tests-enhan…
angorayc Jul 25, 2024
253fc6b
update createBsearch
angorayc Jul 25, 2024
df908c3
types
angorayc Jul 26, 2024
9826370
createBsearch
angorayc Jul 26, 2024
70bb80d
createSupertest in tests
angorayc Jul 29, 2024
f7ad85d
Merge branch 'main' into api-tests-enhancement
angorayc Jul 29, 2024
e49fa32
use bsearch from utils
angorayc Jul 29, 2024
0a15315
types
angorayc Jul 29, 2024
6b65b0e
Merge branch 'main' of github.com:elastic/kibana into api-tests-enhan…
angorayc Jul 30, 2024
41ac8fd
Merge branch 'main' into api-tests-enhancement
angorayc Jul 30, 2024
c2466bd
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jul 30, 2024
078d7a2
Merge branch 'main' into api-tests-enhancement
angorayc Jul 30, 2024
9826756
Merge branch 'main' into api-tests-enhancement
angorayc Aug 1, 2024
869f3fb
Merge branch 'main' of github.com:elastic/kibana into api-tests-enhan…
angorayc Aug 5, 2024
95db550
types
angorayc Aug 5, 2024
d9ecb36
import
angorayc Aug 5, 2024
3b34691
Merge branch 'main' of github.com:elastic/kibana into api-tests-enhan…
angorayc Aug 6, 2024
972c308
Merge branch 'main' of github.com:elastic/kibana into api-tests-enhan…
angorayc Aug 6, 2024
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: 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 @@ -5,18 +5,20 @@
* 2.0.
*/

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

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

return {
getUsername: (_role?: string) =>
Promise.resolve(config.get('servers.kibana.username') as string),
createSuperTest: (_role?: string) => Promise.resolve(supertest),
createBsearch: (_role?: string) => Promise.resolve(bsearch),
};
}
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 @@ -48,6 +52,13 @@ export function SecuritySolutionServerlessUtils({
});
});

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

return {
getUsername: async (role = 'admin') => {
const { username } = await svlUserManager.getUserData(role);
Expand All @@ -57,12 +68,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);
};

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>;
createSuperTest: (role?: string) => Promise<TestAgent<any>>;
createBsearch: (role?: string) => Promise<BsearchService>;
}
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