-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.7] [Security Solution] Support rule id in wait for rule status hel…
…per (#153410) (#154328) # Backport This will backport the following commits from `main` to `8.7`: - [[Security Solution] Support rule id in wait for rule status helper (#153410)](#153410) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Maxim Palenov","email":"maxim.palenov@elastic.co"},"sourceCommit":{"committedDate":"2023-03-27T09:03:15Z","message":"[Security Solution] Support rule id in wait for rule status helper (#153410)\n\n**Relates to:** https://github.com/elastic/kibana/pull/152900\r\n\r\n## Summary\r\n\r\nThis PR adds an ability to wait for rule status by its rule id in functional tests. It is a result of splitting of #150553 into isolated parts.\r\n\r\n## Details\r\n\r\nBased on what kind of id is used (SO id or rule id) it leads to different behaviour under the hood. SO id related functionality consumes ES Get API while rule id related functionality consumes ES Search API. This way it may require to add some delay to let ES to refresh the data if the testing logic consumes ES Search API while rule status was awaited via SO id so that handled by ES Get API. This PR removes such a delay at rule exporting functional tests.","sha":"519185ffa88aeea05626f71b303a7daf1ce9d14b","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["refactoring","technical debt","release_note:skip","test-api-integration","Team:Detections and Resp","Team: SecuritySolution","Team:Detection Rules","backport:prev-minor","v8.8.0"],"number":153410,"url":"https://github.com/elastic/kibana/pull/153410","mergeCommit":{"message":"[Security Solution] Support rule id in wait for rule status helper (#153410)\n\n**Relates to:** https://github.com/elastic/kibana/pull/152900\r\n\r\n## Summary\r\n\r\nThis PR adds an ability to wait for rule status by its rule id in functional tests. It is a result of splitting of #150553 into isolated parts.\r\n\r\n## Details\r\n\r\nBased on what kind of id is used (SO id or rule id) it leads to different behaviour under the hood. SO id related functionality consumes ES Get API while rule id related functionality consumes ES Search API. This way it may require to add some delay to let ES to refresh the data if the testing logic consumes ES Search API while rule status was awaited via SO id so that handled by ES Get API. This PR removes such a delay at rule exporting functional tests.","sha":"519185ffa88aeea05626f71b303a7daf1ce9d14b"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/153410","number":153410,"mergeCommit":{"message":"[Security Solution] Support rule id in wait for rule status helper (#153410)\n\n**Relates to:** https://github.com/elastic/kibana/pull/152900\r\n\r\n## Summary\r\n\r\nThis PR adds an ability to wait for rule status by its rule id in functional tests. It is a result of splitting of #150553 into isolated parts.\r\n\r\n## Details\r\n\r\nBased on what kind of id is used (SO id or rule id) it leads to different behaviour under the hood. SO id related functionality consumes ES Get API while rule id related functionality consumes ES Search API. This way it may require to add some delay to let ES to refresh the data if the testing logic consumes ES Search API while rule status was awaited via SO id so that handled by ES Get API. This PR removes such a delay at rule exporting functional tests.","sha":"519185ffa88aeea05626f71b303a7daf1ce9d14b"}}]}] BACKPORT-->
- Loading branch information
Showing
41 changed files
with
649 additions
and
598 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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 * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
import { ToolingLog } from '@kbn/tooling-log'; | ||
import { DETECTION_ENGINE_QUERY_SIGNALS_URL } from '@kbn/security-solution-plugin/common/constants'; | ||
import { DetectionAlert } from '@kbn/security-solution-plugin/common/detection_engine/schemas/alerts'; | ||
import { RiskEnrichmentFields } from '@kbn/security-solution-plugin/server/lib/detection_engine/signals/enrichments/types'; | ||
import { | ||
getRuleForSignalTesting, | ||
createRule, | ||
waitForRuleSuccess, | ||
waitForSignalsToBePresent, | ||
getSignalsByIds, | ||
getQuerySignalIds, | ||
} from '../../../detection_engine_api_integration/utils'; | ||
import { superUser } from './authentication/users'; | ||
import { User } from './authentication/types'; | ||
import { getSpaceUrlPrefix } from './api/helpers'; | ||
|
||
export const createSecuritySolutionAlerts = async ( | ||
supertest: SuperTest.SuperTest<SuperTest.Test>, | ||
log: ToolingLog | ||
): Promise<estypes.SearchResponse<DetectionAlert & RiskEnrichmentFields>> => { | ||
const rule = getRuleForSignalTesting(['auditbeat-*']); | ||
const { id } = await createRule(supertest, log, rule); | ||
await waitForRuleSuccess({ supertest, log, id }); | ||
await waitForSignalsToBePresent(supertest, log, 1, [id]); | ||
const signals = await getSignalsByIds(supertest, log, [id]); | ||
|
||
return signals; | ||
}; | ||
|
||
export const getSecuritySolutionAlerts = async ( | ||
supertest: SuperTest.SuperTest<SuperTest.Test>, | ||
alertIds: string[] | ||
): Promise<estypes.SearchResponse<DetectionAlert & RiskEnrichmentFields>> => { | ||
const { body: updatedAlert } = await supertest | ||
.post(DETECTION_ENGINE_QUERY_SIGNALS_URL) | ||
.set('kbn-xsrf', 'true') | ||
.send(getQuerySignalIds(alertIds)) | ||
.expect(200); | ||
|
||
return updatedAlert; | ||
}; | ||
|
||
interface AlertResponse { | ||
'kibana.alert.case_ids'?: string[]; | ||
} | ||
|
||
export const getAlertById = async ({ | ||
supertest, | ||
id, | ||
index, | ||
expectedHttpCode = 200, | ||
auth = { user: superUser, space: null }, | ||
}: { | ||
supertest: SuperTest.SuperTest<SuperTest.Test>; | ||
id: string; | ||
index: string; | ||
expectedHttpCode?: number; | ||
auth?: { user: User; space: string | null }; | ||
}): Promise<AlertResponse> => { | ||
const { body: alert } = await supertest | ||
.get(`${getSpaceUrlPrefix(auth?.space)}/internal/rac/alerts?id=${id}&index=${index}`) | ||
.auth(auth.user.username, auth.user.password) | ||
.set('kbn-xsrf', 'true') | ||
.expect(expectedHttpCode); | ||
|
||
return alert; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.