diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 1399afae90540..0579e510ba2fb 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1987,7 +1987,6 @@ x-pack/platform/plugins/shared/ml/server/models/data_recognizer/modules/security /x-pack/platform/test/serverless/functional/services/ @elastic/appex-qa # temporarily due to SKA tests relocation /x-pack/platform/test/serverless/functional/config* @elastic/appex-qa /x-pack/platform/test/serverless/functional/ftr_provider_context.d.ts @elastic/appex-qa -/x-pack/solutions/security/test/common/utils/detections_response/ @elastic/appex-qa # Core /src/platform/test/api_integration/fixtures/kbn_archiver/management/saved_objects/relationships.json @elastic/kibana-core @elastic/kibana-data-discovery diff --git a/x-pack/solutions/security/test/cases_api_integration/common/lib/alerts.ts b/x-pack/solutions/security/test/cases_api_integration/common/lib/alerts.ts index 783e0f94389bc..847037b772cee 100644 --- a/x-pack/solutions/security/test/cases_api_integration/common/lib/alerts.ts +++ b/x-pack/solutions/security/test/cases_api_integration/common/lib/alerts.ts @@ -18,7 +18,7 @@ import { waitForAlertsToBePresent, getAlertsByIds, getQueryAlertIds, -} from '../../../common/utils/detections_response'; +} from '../../../security_solution_api_integration/config/services/detections_response'; export const createSecuritySolutionAlerts = async ( supertest: SuperTest.Agent, diff --git a/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/cases/delete_cases.ts b/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/cases/delete_cases.ts index 85a067d2d8e07..ca95993fc6c5f 100644 --- a/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/cases/delete_cases.ts +++ b/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/cases/delete_cases.ts @@ -68,7 +68,7 @@ import { createAlertsIndex, deleteAllRules, deleteAllAlerts, -} from '../../../../../common/utils/detections_response'; +} from '../../../../../security_solution_api_integration/config/services/detections_response'; import { createSecuritySolutionAlerts, getSecuritySolutionAlerts, diff --git a/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/cases/patch_cases.ts b/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/cases/patch_cases.ts index 82fc3e345c95a..b7854f282e0c3 100644 --- a/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/cases/patch_cases.ts +++ b/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/cases/patch_cases.ts @@ -61,7 +61,7 @@ import { getAlertsByIds, createRule, getQueryAlertIds, -} from '../../../../../common/utils/detections_response'; +} from '../../../../../security_solution_api_integration/config/services/detections_response'; import { getSignalsWithES } from '../../../../common/lib/api'; export default ({ getService }: FtrProviderContext): void => { diff --git a/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/comments/delete_comment.ts b/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/comments/delete_comment.ts index a4fd72c05e4f0..d0f57902269ca 100644 --- a/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/comments/delete_comment.ts +++ b/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/comments/delete_comment.ts @@ -50,7 +50,7 @@ import { createAlertsIndex, deleteAllAlerts, deleteAllRules, -} from '../../../../../common/utils/detections_response'; +} from '../../../../../security_solution_api_integration/config/services/detections_response'; import { createSecuritySolutionAlerts, getSecuritySolutionAlerts, diff --git a/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/comments/delete_comments.ts b/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/comments/delete_comments.ts index e1d6fbf4f6dc6..952a85930bc36 100644 --- a/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/comments/delete_comments.ts +++ b/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/comments/delete_comments.ts @@ -55,7 +55,7 @@ import { createAlertsIndex, deleteAllAlerts, deleteAllRules, -} from '../../../../../common/utils/detections_response'; +} from '../../../../../security_solution_api_integration/config/services/detections_response'; import { createSecuritySolutionAlerts, getSecuritySolutionAlerts, diff --git a/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/comments/post_comment.ts b/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/comments/post_comment.ts index a470f81c11c8f..bdb8721c84682 100644 --- a/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/comments/post_comment.ts +++ b/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/comments/post_comment.ts @@ -69,7 +69,7 @@ import { createAlertsIndex, deleteAllAlerts, deleteAllRules, -} from '../../../../../common/utils/detections_response'; +} from '../../../../../security_solution_api_integration/config/services/detections_response'; import { getSecuritySolutionAlerts, createSecuritySolutionAlerts, diff --git a/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_create_attachments.ts b/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_create_attachments.ts index 0881ad534de8b..42c4d4bedb7ad 100644 --- a/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_create_attachments.ts +++ b/x-pack/solutions/security/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_create_attachments.ts @@ -66,7 +66,7 @@ import { createAlertsIndex, deleteAllAlerts, deleteAllRules, -} from '../../../../../common/utils/detections_response'; +} from '../../../../../security_solution_api_integration/config/services/detections_response'; import { getSecuritySolutionAlerts, createSecuritySolutionAlerts, diff --git a/x-pack/solutions/security/test/common/utils/detections_response/alerts/create_alerts_index.ts b/x-pack/solutions/security/test/common/utils/detections_response/alerts/create_alerts_index.ts deleted file mode 100644 index 7865d5cd5ffee..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/alerts/create_alerts_index.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 type SuperTest from 'supertest'; -import type { ToolingLog } from '@kbn/tooling-log'; - -import { DETECTION_ENGINE_INDEX_URL } from '@kbn/security-solution-plugin/common/constants'; -import { countDownTest } from '../count_down_test'; - -/** - * Creates the alerts index for use inside of beforeEach blocks of tests - * This will retry 50 times before giving up and hopefully still not interfere with other tests - * @param supertest The supertest client library - */ -export const createAlertsIndex = async ( - supertest: SuperTest.Agent, - log: ToolingLog -): Promise => { - await countDownTest( - async () => { - await supertest - .post(DETECTION_ENGINE_INDEX_URL) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '2023-10-31') - .send(); - return { - passed: true, - }; - }, - 'createAlertsIndex', - log - ); -}; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/alerts/delete_all_alerts.ts b/x-pack/solutions/security/test/common/utils/detections_response/alerts/delete_all_alerts.ts deleted file mode 100644 index 5c26820feda7d..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/alerts/delete_all_alerts.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 type SuperTest from 'supertest'; -import type { ToolingLog } from '@kbn/tooling-log'; -import type { Client } from '@elastic/elasticsearch'; -import { DETECTION_ENGINE_INDEX_URL } from '@kbn/security-solution-plugin/common/constants'; -import { countDownTest } from '../count_down_test'; - -/** - * Deletes all alerts from a given index or indices, defaults to `.alerts-security.alerts-*` - * For use inside of afterEach blocks of tests - */ -export const deleteAllAlerts = async ( - supertest: SuperTest.Agent, - log: ToolingLog, - es: Client, - index: Array<'.alerts-security.alerts-*' | '.preview.alerts-security.alerts-*'> = [ - '.alerts-security.alerts-*', - ] -): Promise => { - await countDownTest( - async () => { - await supertest - .delete(DETECTION_ENGINE_INDEX_URL) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '2023-10-31') - .send(); - await es.deleteByQuery({ - index, - query: { - match_all: {}, - }, - refresh: true, - }); - return { - passed: true, - }; - }, - 'deleteAllAlerts', - log - ); -}; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/alerts/get_alerts_by_id.ts b/x-pack/solutions/security/test/common/utils/detections_response/alerts/get_alerts_by_id.ts deleted file mode 100644 index 7417cf05065c1..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/alerts/get_alerts_by_id.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 type { ToolingLog } from '@kbn/tooling-log'; -import type SuperTest from 'supertest'; -import type { SearchResponse } from '@elastic/elasticsearch/lib/api/types'; -import type { DetectionAlert } from '@kbn/security-solution-plugin/common/api/detection_engine'; - -import { DETECTION_ENGINE_QUERY_SIGNALS_URL as DETECTION_ENGINE_QUERY_ALERTS_URL } from '@kbn/security-solution-plugin/common/constants'; -import { countDownTest } from '../count_down_test'; -import { getQueryAlertsId } from './get_query_alerts_ids'; - -/** - * Given a single rule id this will return only alerts based on that rule id. - * @param supertest agent - * @param ids Rule id - */ -export const getAlertsById = async ( - supertest: SuperTest.Agent, - log: ToolingLog, - id: string -): Promise> => { - const alertsOpen = await countDownTest>( - async () => { - const response = await supertest - .post(DETECTION_ENGINE_QUERY_ALERTS_URL) - .set('kbn-xsrf', 'true') - .send(getQueryAlertsId([id])); - if (response.status !== 200) { - return { - passed: false, - returnValue: undefined, - }; - } else { - return { - passed: true, - returnValue: response.body, - }; - } - }, - 'getAlertsById', - log - ); - if (alertsOpen == null) { - throw new Error('Alerts not defined after countdown, cannot continue'); - } else { - return alertsOpen; - } -}; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/alerts/get_alerts_by_ids.ts b/x-pack/solutions/security/test/common/utils/detections_response/alerts/get_alerts_by_ids.ts deleted file mode 100644 index 218de0144d87a..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/alerts/get_alerts_by_ids.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 type { SearchResponse } from '@elastic/elasticsearch/lib/api/types'; -import type { ToolingLog } from '@kbn/tooling-log'; -import type SuperTest from 'supertest'; -import type { DetectionAlert } from '@kbn/security-solution-plugin/common/api/detection_engine'; -import type { RiskEnrichmentFields } from '@kbn/security-solution-plugin/server/lib/detection_engine/rule_types/utils/enrichments/types'; - -import { DETECTION_ENGINE_QUERY_SIGNALS_URL as DETECTION_ENGINE_QUERY_ALERTS_URL } from '@kbn/security-solution-plugin/common/constants'; -import { countDownTest } from '../count_down_test'; -import { getQueryAlertsId } from './get_query_alerts_ids'; -import { routeWithNamespace } from '../route_with_namespace'; - -/** - * Given an array of rule ids this will return only alerts based on that rule id both - * open and closed - * @param supertest agent - * @param ids Array of the rule ids - */ -export const getAlertsByIds = async ( - supertest: SuperTest.Agent, - log: ToolingLog, - ids: string[], - size?: number, - namespace?: string -): Promise> => { - const alertsOpen = await countDownTest>( - async () => { - const route = routeWithNamespace(DETECTION_ENGINE_QUERY_ALERTS_URL, namespace); - const response = await supertest - .post(route) - .set('kbn-xsrf', 'true') - .send(getQueryAlertsId(ids, size)); - if (response.status !== 200) { - return { - passed: false, - errorMessage: `Status is not 200 as expected, it is: ${response.status}`, - }; - } else { - return { - passed: true, - returnValue: response.body, - }; - } - }, - 'getAlertsByIds', - log - ); - if (alertsOpen == null) { - throw new Error('Alerts not defined after countdown, cannot continue'); - } else { - return alertsOpen; - } -}; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/alerts/get_query_alert_ids.ts b/x-pack/solutions/security/test/common/utils/detections_response/alerts/get_query_alert_ids.ts deleted file mode 100644 index 1e5eafa119e8e..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/alerts/get_query_alert_ids.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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 type { SignalIds as AlertIds } from '@kbn/security-solution-plugin/common/api/detection_engine'; - -export const getQueryAlertIds = (alertIds: AlertIds) => ({ - query: { - terms: { - _id: alertIds, - }, - }, -}); diff --git a/x-pack/solutions/security/test/common/utils/detections_response/alerts/get_query_alerts_ids.ts b/x-pack/solutions/security/test/common/utils/detections_response/alerts/get_query_alerts_ids.ts deleted file mode 100644 index d40b28d74ef39..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/alerts/get_query_alerts_ids.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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 { ALERT_RULE_UUID } from '@kbn/rule-data-utils'; - -/** - * Given an array of ids for a test this will get the alerts - * created from that rule's regular id. - * @param ids The rule_id to search for alerts - */ -export const getQueryAlertsId = (ids: string[], size = 10) => ({ - size, - sort: ['@timestamp'], - query: { - terms: { - [ALERT_RULE_UUID]: ids, - }, - }, -}); diff --git a/x-pack/solutions/security/test/common/utils/detections_response/alerts/index.ts b/x-pack/solutions/security/test/common/utils/detections_response/alerts/index.ts deleted file mode 100644 index 160f2cc322675..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/alerts/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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. - */ - -export * from './create_alerts_index'; -export * from './delete_all_alerts'; -export * from './get_query_alert_ids'; -export * from './get_query_alerts_ids'; -export * from './get_alerts_by_ids'; -export * from './get_alerts_by_id'; -export * from './wait_for_alerts_to_be_present'; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/alerts/search_alerts.ts b/x-pack/solutions/security/test/common/utils/detections_response/alerts/search_alerts.ts deleted file mode 100644 index 7d383fa329c23..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/alerts/search_alerts.ts +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 type { ToolingLog } from '@kbn/tooling-log'; -import type SuperTest from 'supertest'; -import type { SearchResponse } from '@elastic/elasticsearch/lib/api/types'; -import type { DetectionAlert } from '@kbn/security-solution-plugin/common/api/detection_engine'; - -import { DETECTION_ENGINE_QUERY_SIGNALS_URL as DETECTION_ENGINE_QUERY_ALERTS_URL } from '@kbn/security-solution-plugin/common/constants'; -import { countDownTest } from '../count_down_test'; - -/** - * This function invokes the detection engine query alerts API to search for alerts. - * It will retry until the alerts are returned or a timeout occurs. - * @param supertest agent - * @param log ToolingLog instance for logging - * @param searchBody The body of the search request, which should conform to the {@link SearchAlertsRequestBody} schema - */ -export const searchAlerts = async ( - supertest: SuperTest.Agent, - log: ToolingLog, - searchBody: object -): Promise> => { - const alertsOpen = await countDownTest>( - async () => { - const response = await supertest - .post(DETECTION_ENGINE_QUERY_ALERTS_URL) - .set('kbn-xsrf', 'true') - .send(searchBody); - if (response.status !== 200) { - return { - passed: false, - returnValue: undefined, - }; - } else { - return { - passed: true, - returnValue: response.body, - }; - } - }, - 'searchAlerts', - log - ); - if (alertsOpen == null) { - throw new Error('Alerts were not found in alotted time'); - } else { - return alertsOpen; - } -}; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/alerts/wait_for_alerts_to_be_present.ts b/x-pack/solutions/security/test/common/utils/detections_response/alerts/wait_for_alerts_to_be_present.ts deleted file mode 100644 index 5772861f6e636..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/alerts/wait_for_alerts_to_be_present.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 type { ToolingLog } from '@kbn/tooling-log'; -import type SuperTest from 'supertest'; - -import { getAlertsByIds } from './get_alerts_by_ids'; -import { waitFor } from '../wait_for'; - -/** - * Waits for the signal hits to be greater than the supplied number - * before continuing with a default of at least one signal - * @param supertest Deps - * @param numberOfAlerts The number of alerts to wait for, default is 1 - */ -export const waitForAlertsToBePresent = async ( - supertest: SuperTest.Agent, - log: ToolingLog, - numberOfAlerts = 1, - alertIds: string[], - namespace?: string -): Promise => { - await waitFor( - async () => { - const alertsOpen = await getAlertsByIds(supertest, log, alertIds, numberOfAlerts, namespace); - return alertsOpen.hits.hits.length >= numberOfAlerts; - }, - 'waitForAlertsToBePresent', - log - ); -}; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/count_down_test.ts b/x-pack/solutions/security/test/common/utils/detections_response/count_down_test.ts deleted file mode 100644 index 39292a9cbbbb7..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/count_down_test.ts +++ /dev/null @@ -1,78 +0,0 @@ -/* - * 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 type { ToolingLog } from '@kbn/tooling-log'; - -/** - * Does a plain countdown and checks against a boolean to determine if to wait and try again. - * This is useful for over the wire things that can cause issues such as conflict or timeouts - * for testing resiliency. - * @param functionToTest The function to test against - * @param name The name of the function to print if we encounter errors - * @param log The tooling logger - * @param retryCount The number of times to retry before giving up (has default) - * @param timeoutWait Time to wait before trying again (has default) - */ -export const countDownTest = async ( - functionToTest: () => Promise<{ - passed: boolean; - returnValue?: T | undefined; - errorMessage?: string; - }>, - name: string, - log: ToolingLog, - retryCount: number = 50, - timeoutWait = 250, - ignoreThrow: boolean = false -): Promise => { - if (retryCount > 0) { - try { - const testReturn = await functionToTest(); - if (!testReturn.passed) { - const error = testReturn.errorMessage != null ? ` error: ${testReturn.errorMessage},` : ''; - log.error(`Failure trying to ${name},${error} retries left are: ${retryCount - 1}`); - // retry, counting down, and delay a bit before - await new Promise((resolve) => setTimeout(resolve, timeoutWait)); - const returnValue = await countDownTest( - functionToTest, - name, - log, - retryCount - 1, - timeoutWait, - ignoreThrow - ); - return returnValue; - } else { - return testReturn.returnValue; - } - } catch (err) { - if (ignoreThrow) { - throw err; - } else { - log.error( - `Failure trying to ${name}, with exception message of: ${ - err.message - }, retries left are: ${retryCount - 1}` - ); - // retry, counting down, and delay a bit before - await new Promise((resolve) => setTimeout(resolve, timeoutWait)); - const returnValue = await countDownTest( - functionToTest, - name, - log, - retryCount - 1, - timeoutWait, - ignoreThrow - ); - return returnValue; - } - } - } else { - log.error(`Could not ${name}, no retries are left`); - return undefined; - } -}; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/delete_all_anomalies.ts b/x-pack/solutions/security/test/common/utils/detections_response/delete_all_anomalies.ts deleted file mode 100644 index bb7a35dd2fd8c..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/delete_all_anomalies.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 type { ToolingLog } from '@kbn/tooling-log'; -import type { Client } from '@elastic/elasticsearch'; - -import { countDownTest } from './count_down_test'; - -export const deleteAllAnomalies = async ( - log: ToolingLog, - es: Client, - index: string[] = ['.ml-anomalies-*'] -): Promise => { - await countDownTest( - async () => { - await es.deleteByQuery({ - index, - query: { - match_all: {}, - }, - refresh: true, - }); - return { - passed: true, - }; - }, - 'deleteAllAnomalies', - log - ); -}; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/index.ts b/x-pack/solutions/security/test/common/utils/detections_response/index.ts deleted file mode 100644 index 45efc2cee3b4c..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/index.ts +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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. - */ - -export * from './alerts'; -export * from './count_down_test'; -export * from './delete_all_anomalies'; -export * from './route_with_namespace'; -export * from './rules'; -export * from './tasks'; -export * from './wait_for'; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/route_with_namespace.ts b/x-pack/solutions/security/test/common/utils/detections_response/route_with_namespace.ts deleted file mode 100644 index 07e5c4a8049e2..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/route_with_namespace.ts +++ /dev/null @@ -1,14 +0,0 @@ -/* - * 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. - */ - -/** - * Generates a route string with an optional namespace. - * @param route the route string - * @param namespace [optional] the namespace to account for in the route - */ -export const routeWithNamespace = (route: string, namespace?: string) => - namespace ? `/s/${namespace}${route}` : route; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/rules/create_rule.ts b/x-pack/solutions/security/test/common/utils/detections_response/rules/create_rule.ts deleted file mode 100644 index b1fe58770abfd..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/rules/create_rule.ts +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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 { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common'; -import type { ToolingLog } from '@kbn/tooling-log'; -import type SuperTest from 'supertest'; -import type { - RuleCreateProps, - RuleResponse, -} from '@kbn/security-solution-plugin/common/api/detection_engine'; - -import { DETECTION_ENGINE_RULES_URL } from '@kbn/security-solution-plugin/common/constants'; -import { deleteRule } from './delete_rule'; -import { routeWithNamespace } from '../route_with_namespace'; - -/** - * Helper to cut down on the noise in some of the tests. If this detects - * a conflict it will try to manually remove the rule before re-adding the rule one time and log - * and error about the race condition. - * rule a second attempt. It only re-tries adding the rule if it encounters a conflict once. - * @param supertest The supertest deps - * @param log The tooling logger - * @param rule The rule to create - */ -export const createRule = async ( - supertest: SuperTest.Agent, - log: ToolingLog, - rule: RuleCreateProps, - namespace?: string -): Promise => { - const route = routeWithNamespace(DETECTION_ENGINE_RULES_URL, namespace); - const response = await supertest - .post(route) - .set('kbn-xsrf', 'true') - .set(ELASTIC_HTTP_VERSION_HEADER, '2023-10-31') - .send(rule); - if (response.status === 409) { - if (rule.rule_id != null) { - log.debug( - `Did not get an expected 200 "ok" when creating a rule (createRule). CI issues could happen. Suspect this line if you are seeing CI issues. body: ${JSON.stringify( - response.body - )}, status: ${JSON.stringify(response.status)}` - ); - await deleteRule(supertest, rule.rule_id); - const secondResponseTry = await supertest - .post(DETECTION_ENGINE_RULES_URL) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '2023-10-31') - .send(rule); - if (secondResponseTry.status !== 200) { - throw new Error( - `Unexpected non 200 ok when attempting to create a rule (second try): ${JSON.stringify( - response.body - )}` - ); - } else { - return secondResponseTry.body; - } - } else { - throw new Error('When creating a rule found an unexpected conflict (404)'); - } - } else if (response.status !== 200) { - throw new Error( - `Unexpected non 200 ok when attempting to create a rule: ${JSON.stringify( - response.status - )},${JSON.stringify(response, null, 4)}` - ); - } else { - return response.body; - } -}; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/rules/delete_all_rules.ts b/x-pack/solutions/security/test/common/utils/detections_response/rules/delete_all_rules.ts deleted file mode 100644 index 66bf65ccfbc20..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/rules/delete_all_rules.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 type { ToolingLog } from '@kbn/tooling-log'; -import type SuperTest from 'supertest'; - -import { - DETECTION_ENGINE_RULES_BULK_ACTION, - DETECTION_ENGINE_RULES_URL, -} from '@kbn/security-solution-plugin/common/constants'; -import { countDownTest } from '../count_down_test'; - -/** - * Removes all rules by looping over any found and removing them from REST. - * @param supertest The supertest agent. - */ -export const deleteAllRules = async ( - supertest: SuperTest.Agent, - log: ToolingLog -): Promise => { - await countDownTest( - async () => { - await supertest - .post(DETECTION_ENGINE_RULES_BULK_ACTION) - .send({ action: 'delete', query: '' }) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '2023-10-31'); - - const { body: finalCheck } = await supertest - .get(`${DETECTION_ENGINE_RULES_URL}/_find`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '2023-10-31') - .send(); - return { - passed: finalCheck.data.length === 0, - }; - }, - 'deleteAllRules', - log, - 50, - 1000 - ); -}; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/rules/delete_rule.ts b/x-pack/solutions/security/test/common/utils/detections_response/rules/delete_rule.ts deleted file mode 100644 index 5b3e28f05e093..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/rules/delete_rule.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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 type SuperTest from 'supertest'; -import type { RuleResponse } from '@kbn/security-solution-plugin/common/api/detection_engine'; - -import { DETECTION_ENGINE_RULES_URL } from '@kbn/security-solution-plugin/common/constants'; - -/** - * Helper to cut down on the noise in some of the tests. Does a delete of a rule. - * It does not check for a 200 "ok" on this. - * @param supertest The supertest deps - * @param ruleId The rule id to delete - */ -export const deleteRule = async ( - supertest: SuperTest.Agent, - ruleId: string -): Promise => { - const response = await supertest - .delete(`${DETECTION_ENGINE_RULES_URL}?rule_id=${ruleId}`) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '2023-10-31') - .expect(200); - - return response.body; -}; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/rules/get_gaps_by_rule_id.ts b/x-pack/solutions/security/test/common/utils/detections_response/rules/get_gaps_by_rule_id.ts deleted file mode 100644 index bbcb5b4b0d933..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/rules/get_gaps_by_rule_id.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* - * 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 type SuperTest from 'supertest'; -import type { FindGapsResponse } from '@kbn/alerting-plugin/common/routes/gaps/apis/find'; -import { routeWithNamespace } from '../route_with_namespace'; - -export const getGapsByRuleId = async ( - supertest: SuperTest.Agent, - ruleId: string, - { start, end }: { start: string; end: string }, - perPage: number, - namespace: string = 'default' -) => { - const response = (await supertest - .post(routeWithNamespace(`/internal/alerting/rules/gaps/_find`, namespace)) - .set('kbn-xsrf', 'foo') - .send({ - rule_id: ruleId, - start, - end, - per_page: perPage, - })) as FindGapsResponse; - - return response.body.data; -}; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/rules/get_rule_for_alert_testing.ts b/x-pack/solutions/security/test/common/utils/detections_response/rules/get_rule_for_alert_testing.ts deleted file mode 100644 index 5c0500f89ef51..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/rules/get_rule_for_alert_testing.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 type { QueryRuleCreateProps } from '@kbn/security-solution-plugin/common/api/detection_engine'; - -/** - * This is a typical signal testing rule that is easy for most basic testing of output of alerts. - * It starts out in an enabled true state. The 'from' is set very far back to test the basics of signal - * creation and testing by getting all the alerts at once. - * @param ruleId The optional ruleId which is rule-1 by default. - * @param enabled Enables the rule on creation or not. Defaulted to true. - */ -export const getRuleForAlertTesting = ( - index: string[], - ruleId = 'rule-1', - enabled = true -): QueryRuleCreateProps => ({ - name: 'Alert Testing Query', - description: 'Tests a simple query', - enabled, - risk_score: 1, - rule_id: ruleId, - severity: 'high', - index, - type: 'query', - query: '*:*', - from: '1900-01-01T00:00:00.000Z', -}); - -export const getLuceneRuleForTesting = (): QueryRuleCreateProps => ({ - rule_id: 'lucene-rule-1', - enabled: true, - name: 'Incident 496 test rule', - description: 'Ensures lucene rules generate alerts', - risk_score: 1, - severity: 'high', - type: 'query', - index: ['auditbeat-*'], - query: - '((event.category: (network OR network_traffic) AND type: (tls OR http)) OR event.dataset: (network_traffic.tls OR network_traffic.http)) AND destination.domain:/[a-z]{3}.stage.[0-9]{8}..*/', - language: 'lucene', - from: '1900-01-01T00:00:00.000Z', -}); diff --git a/x-pack/solutions/security/test/common/utils/detections_response/rules/index.ts b/x-pack/solutions/security/test/common/utils/detections_response/rules/index.ts deleted file mode 100644 index 0f757b0a8d6a7..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/rules/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -/* - * 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. - */ - -export * from './create_rule'; -export * from './delete_all_rules'; -export * from './delete_rule'; -export * from './get_rule_for_alert_testing'; -export * from './wait_for_rule_status'; -export * from './manual_run'; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/rules/manual_run.ts b/x-pack/solutions/security/test/common/utils/detections_response/rules/manual_run.ts deleted file mode 100644 index 4f3ebc64bb6ec..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/rules/manual_run.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 type SuperTest from 'supertest'; -import { INTERNAL_BASE_ALERTING_API_PATH } from '@kbn/alerting-plugin/common'; -import type { ScheduleBackfillResponse } from '@kbn/alerting-plugin/common/routes/backfill/apis/schedule'; -import { routeWithNamespace } from '../route_with_namespace'; - -const BACKFILL_RULE_URL = `${INTERNAL_BASE_ALERTING_API_PATH}/rules/backfill`; -const BACKFILL_RULE_URL_SCHEDULE = `${BACKFILL_RULE_URL}/_schedule`; - -export const manualRuleRun = async ({ - supertest, - ruleId, - start, - end, - namespace, -}: { - ruleId: string; - start: string; - end: string; - namespace?: string; - supertest: SuperTest.Agent; -}): Promise => { - const route = routeWithNamespace(BACKFILL_RULE_URL_SCHEDULE, namespace); - const response = await supertest - .post(route) - .set('kbn-xsrf', 'true') - .set('x-elastic-internal-origin', 'Kibana') - .send([ - { - rule_id: ruleId, - start, - end, - }, - ]); - - return response; -}; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/rules/wait_for_rule_status.ts b/x-pack/solutions/security/test/common/utils/detections_response/rules/wait_for_rule_status.ts deleted file mode 100644 index c48070a3fa528..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/rules/wait_for_rule_status.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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 type { ToolingLog } from '@kbn/tooling-log'; -import type SuperTest from 'supertest'; -import { DETECTION_ENGINE_RULES_URL } from '@kbn/security-solution-plugin/common/constants'; -import type { RuleExecutionStatus } from '@kbn/security-solution-plugin/common/api/detection_engine/rule_monitoring'; -import { RuleExecutionStatusEnum } from '@kbn/security-solution-plugin/common/api/detection_engine/rule_monitoring'; -import { waitFor } from '../wait_for'; -import { routeWithNamespace } from '../route_with_namespace'; - -interface WaitForRuleStatusBaseParams { - supertest: SuperTest.Agent; - log: ToolingLog; - afterDate?: Date; - namespace?: string; -} - -interface WaitForRuleStatusWithId extends WaitForRuleStatusBaseParams { - id: string; - ruleId?: never; -} - -interface WaitForRuleStatusWithRuleId extends WaitForRuleStatusBaseParams { - ruleId: string; - id?: never; -} - -export type WaitForRuleStatusParams = WaitForRuleStatusWithId | WaitForRuleStatusWithRuleId; - -/** - * Waits for rule to settle in a provided status. - * Depending on wether `id` or `ruleId` provided it may impact the behavior. - * - `id` leads to fetching a rule via ES Get API (rulesClient.resolve -> SOClient.resolve -> ES Get API) - * - `ruleId` leads to fetching a rule via ES Search API (rulesClient.find -> SOClient.find -> ES Search API) - * ES Search API may return outdated data while ES Get API always returns fresh data - */ -export const waitForRuleStatus = async ( - expectedStatus: RuleExecutionStatus, - { supertest, log, afterDate, namespace, ...idOrRuleId }: WaitForRuleStatusParams -): Promise => { - await waitFor( - async () => { - const query = 'id' in idOrRuleId ? { id: idOrRuleId.id } : { rule_id: idOrRuleId.ruleId }; - const route = routeWithNamespace(DETECTION_ENGINE_RULES_URL, namespace); - const response = await supertest - .get(route) - .set('kbn-xsrf', 'true') - .set('elastic-api-version', '2023-10-31') - .query(query) - .expect(200); - - // TODO: https://github.com/elastic/kibana/pull/121644 clean up, make type-safe - const rule = response.body; - const ruleStatus = rule?.execution_summary?.last_execution.status; - const ruleStatusDate = rule?.execution_summary?.last_execution.date; - - return ( - rule != null && - ruleStatus === expectedStatus && - (afterDate ? new Date(ruleStatusDate) > afterDate : true) - ); - }, - 'waitForRuleStatus', - log - ); -}; - -export const waitForRuleSuccess = (params: WaitForRuleStatusParams): Promise => - waitForRuleStatus(RuleExecutionStatusEnum.succeeded, params); - -export const waitForRulePartialFailure = (params: WaitForRuleStatusParams): Promise => - waitForRuleStatus(RuleExecutionStatusEnum['partial failure'], params); - -export const waitForRuleFailure = (params: WaitForRuleStatusParams): Promise => - waitForRuleStatus(RuleExecutionStatusEnum.failed, params); diff --git a/x-pack/solutions/security/test/common/utils/detections_response/tasks/index.ts b/x-pack/solutions/security/test/common/utils/detections_response/tasks/index.ts deleted file mode 100644 index 128f0cfe9b93a..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/tasks/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -/* - * 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. - */ - -export * from './indices_metadata'; -export * from './task_manager'; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/tasks/indices_metadata.ts b/x-pack/solutions/security/test/common/utils/detections_response/tasks/indices_metadata.ts deleted file mode 100644 index bca07d56b12fa..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/tasks/indices_metadata.ts +++ /dev/null @@ -1,167 +0,0 @@ -/* - * 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 type { Client } from '@elastic/elasticsearch'; -import type { IndicesPutIndexTemplateRequest } from '@elastic/elasticsearch/lib/api/types'; - -const INGEST_PIPELINE_PREFIX = 'testing-ingest-pipeline'; -const DS_PREFIX = 'testing-datastream'; -const ILM_PREFIX = 'testing-ilm'; - -export const indexRandomData = async (es: Client, dsName: string, ingestPipeline: string) => { - await es.index({ - index: dsName, - pipeline: ingestPipeline, - document: { - '@timestamp': new Date(), - key: `value-${Date.now()}`, - }, - }); -}; - -export const randomDatastream = async ( - es: Client, - opts: { policyName?: string; defaultPipeline?: string; finalPipeline?: string } = {} -): Promise => { - const name = `${DS_PREFIX}-${Date.now()}`; - - const indexTemplateBody: IndicesPutIndexTemplateRequest = { - name: DS_PREFIX, - index_patterns: [`${DS_PREFIX}-*`], - data_stream: {}, - template: { - settings: { - index: { - mode: 'standard', - mapping: { - source: { - mode: 'stored', - }, - }, - }, - }, - }, - }; - - if (opts.policyName && indexTemplateBody.template?.settings !== undefined) { - indexTemplateBody.template.settings.index = { - ...indexTemplateBody.template.settings.index, - lifecycle: { - name: opts.policyName, - }, - }; - } - - if (opts.defaultPipeline && indexTemplateBody.template?.settings !== undefined) { - indexTemplateBody.template.settings.index = { - ...indexTemplateBody.template.settings.index, - default_pipeline: opts.defaultPipeline, - }; - } - - if (opts.finalPipeline && indexTemplateBody.template?.settings !== undefined) { - indexTemplateBody.template.settings.index = { - ...indexTemplateBody.template.settings.index, - final_pipeline: opts.finalPipeline, - }; - } - - await es.indices.putIndexTemplate(indexTemplateBody); - - await es.indices.createDataStream({ name }); - - return name; -}; - -export const randomIngestPipeline = async (es: Client): Promise => { - const id = `${INGEST_PIPELINE_PREFIX}-${Date.now()}`; - - await es.ingest.putPipeline({ - id, - processors: [ - { - set: { - field: `message-${performance.now()}`, - value: `changed-${Date.now()}`, - }, - }, - ], - }); - - return id; -}; - -export const randomIlmPolicy = async (es: Client): Promise => { - const name = `${ILM_PREFIX}-${Date.now()}`; - - const policy = { - phases: { - hot: { - actions: { - rollover: { - max_size: '50gb', - max_age: '30d', - }, - }, - }, - warm: { - min_age: '30d', - actions: { - forcemerge: { - max_num_segments: 1, - }, - shrink: { - number_of_shards: 1, - }, - allocate: { - number_of_replicas: 1, - }, - }, - }, - delete: { - min_age: '90d', - actions: { - delete: {}, - }, - }, - }, - }; - - await es.ilm.putLifecycle({ name, policy }); - - return name; -}; - -export const ensureBackingIndices = async (dsName: string, count: number, es: Client) => { - const stats = await es.indices.dataStreamsStats({ name: dsName }); - if (stats.data_streams.length !== 1) { - throw new Error('Data stream not found'); - } - const current = stats.data_streams[0].backing_indices; - - if (current < count) { - for (let i = current; i < count; i++) { - await es.indices.rollover({ alias: dsName }); - } - } else if (current > count) { - throw new Error('Cannot reduce the number of backing indices'); - } -}; - -export const cleanupDatastreams = async (es: Client) => { - await es.indices.deleteDataStream({ name: `${DS_PREFIX}*` }); -}; - -export const cleanupIngestPipelines = async (es: Client) => { - es.ingest.deletePipeline({ id: `${INGEST_PIPELINE_PREFIX}*` }); -}; - -export const cleanupPolicies = async (es: Client) => { - const policies = await es.ilm.getLifecycle({ name: `${ILM_PREFIX}*` }); - - await Promise.all(Object.entries(policies).map(([name, _]) => es.ilm.deleteLifecycle({ name }))); -}; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/tasks/task_manager.ts b/x-pack/solutions/security/test/common/utils/detections_response/tasks/task_manager.ts deleted file mode 100644 index e9f056b89b7cd..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/tasks/task_manager.ts +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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 { TaskStatus } from '@kbn/task-manager-plugin/server'; -import type { KbnClient } from '@kbn/test'; -import type { ToolingLog } from '@kbn/tooling-log'; - -export const taskHasRun = async (taskId: string, kbn: KbnClient, after: Date): Promise => { - const task = await kbn.savedObjects.get({ - type: 'task', - id: taskId, - }); - - const runAt = new Date(task.attributes.runAt); - const status = task.attributes.status; - - return runAt > after && status === TaskStatus.Idle; -}; - -export const launchTask = async ( - taskId: string, - kbn: KbnClient, - logger: ToolingLog, - delayMillis: number = 1_000 -): Promise => { - logger.info(`Launching task ${taskId}`); - const task = await kbn.savedObjects.get({ - type: 'task', - id: taskId, - }); - - const runAt = new Date(Date.now() + delayMillis).toISOString(); - - await kbn.savedObjects.update({ - type: 'task', - id: taskId, - attributes: { - ...task.attributes, - runAt, - scheduledAt: runAt, - status: TaskStatus.Idle, - }, - }); - - logger.info(`Task ${taskId} launched`); - - return new Date(runAt); -}; diff --git a/x-pack/solutions/security/test/common/utils/detections_response/wait_for.ts b/x-pack/solutions/security/test/common/utils/detections_response/wait_for.ts deleted file mode 100644 index dfa20bd7019d8..0000000000000 --- a/x-pack/solutions/security/test/common/utils/detections_response/wait_for.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 type { ToolingLog } from '@kbn/tooling-log'; - -// Similar to ReactJs's waitFor from here: https://testing-library.com/docs/dom-testing-library/api-async#waitfor -export const waitFor = async ( - functionToTest: () => Promise, - functionName: string, - log: ToolingLog, - maxTimeout: number = 400000, - timeoutWait: number = 250 -): Promise => { - let found = false; - let numberOfTries = 0; - const maxTries = Math.floor(maxTimeout / timeoutWait); - while (!found && numberOfTries < maxTries) { - if (await functionToTest()) { - found = true; - } else { - log.debug(`Try number ${numberOfTries} out of ${maxTries} for function ${functionName}`); - numberOfTries++; - } - - await new Promise((resolveTimeout) => setTimeout(resolveTimeout, timeoutWait)); - } - - if (!found) { - throw new Error(`timed out waiting for function condition to be true within ${functionName}`); - } -}; diff --git a/x-pack/solutions/security/test/security_solution_api_integration/config/services/detections_response/rules/delete_all_rules.ts b/x-pack/solutions/security/test/security_solution_api_integration/config/services/detections_response/rules/delete_all_rules.ts index ef0bc0ec1c9a0..7164c322f1c7f 100644 --- a/x-pack/solutions/security/test/security_solution_api_integration/config/services/detections_response/rules/delete_all_rules.ts +++ b/x-pack/solutions/security/test/security_solution_api_integration/config/services/detections_response/rules/delete_all_rules.ts @@ -12,7 +12,7 @@ import { DETECTION_ENGINE_RULES_BULK_ACTION, DETECTION_ENGINE_RULES_URL, } from '@kbn/security-solution-plugin/common/constants'; -import { withSpaceUrl } from '../../spaces'; +import { withSpaceUrl } from '../spaces'; import { countDownTest } from '../count_down_test'; /** diff --git a/x-pack/solutions/security/test/security_solution_api_integration/config/services/detections_response/tsconfig.json b/x-pack/solutions/security/test/security_solution_api_integration/config/services/detections_response/tsconfig.json new file mode 100644 index 0000000000000..bbc3918e30037 --- /dev/null +++ b/x-pack/solutions/security/test/security_solution_api_integration/config/services/detections_response/tsconfig.json @@ -0,0 +1,24 @@ +{ + "extends": "../../../../../../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types", + "types": [ + "node" + ], + }, + "include": [ + "**/*" + ], + "exclude": [ + "target/**/*" + ], + "kbn_references": [ + "@kbn/tooling-log", + "@kbn/security-solution-plugin", + "@kbn/rule-data-utils", + "@kbn/core-http-common", + "@kbn/alerting-plugin", + "@kbn/task-manager-plugin", + "@kbn/test" + ] +} diff --git a/x-pack/solutions/security/test/security_solution_api_integration/config/services/spaces.ts b/x-pack/solutions/security/test/security_solution_api_integration/config/services/spaces.ts deleted file mode 100644 index 655760d4f4c76..0000000000000 --- a/x-pack/solutions/security/test/security_solution_api_integration/config/services/spaces.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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. - */ - -/** - * Wraps a provided URL with the space ID if it is not the default space. - * - * Examples: - * - `withSpaceUrl('/api/some_endpoint')` returns `/api/some_endpoint` - * - `withSpaceUrl('/api/some_endpoint', 'default')` returns `/api/some_endpoint` - * - `withSpaceUrl('/api/some_endpoint', 'my_space') returns `/s/my_space/api/some_endpoint` - */ -export function withSpaceUrl(url: string, spaceId = 'default'): string { - return spaceId === 'default' ? url : `/s/${spaceId}${url}`; -} diff --git a/x-pack/solutions/security/test/security_solution_api_integration/tsconfig.json b/x-pack/solutions/security/test/security_solution_api_integration/tsconfig.json index a9a3b56886e8d..40839c8cf1f00 100644 --- a/x-pack/solutions/security/test/security_solution_api_integration/tsconfig.json +++ b/x-pack/solutions/security/test/security_solution_api_integration/tsconfig.json @@ -14,12 +14,16 @@ "../../../../../src/platform/packages/shared/kbn-test/types/ftr_globals/**/*" ], "exclude": [ - "target/**/*" + "target/**/*", + "config/services/detections_response/**/*" ], "kbn_references": [ { "path": "../security_solution_endpoint/tsconfig.json" }, + { + "path": "config/services/detections_response/tsconfig.json" + }, "@kbn/dev-utils", "@kbn/test", "@kbn/expect", diff --git a/x-pack/solutions/security/test/tsconfig.json b/x-pack/solutions/security/test/tsconfig.json index 906871fe90b06..be369d02237b0 100644 --- a/x-pack/solutions/security/test/tsconfig.json +++ b/x-pack/solutions/security/test/tsconfig.json @@ -27,6 +27,9 @@ "*/*/packages/**/*", ], "kbn_references": [ + { + "path": "security_solution_api_integration/config/services/detections_response/tsconfig.json" + }, "@kbn/security-solution-test-api-clients", "@kbn/test", "@kbn/expect", @@ -58,7 +61,6 @@ "@kbn/session-view-plugin", "@kbn/repo-info", "@kbn/es-archiver", - "@kbn/task-manager-plugin", "@kbn/serverless-security-settings", "@kbn/rison", "@kbn/core-chrome-browser",