-
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.
[Security Solution] Unskip tests for the prebuilt rules bootstrap end…
…point (#205106) **Fixes: #197108 **Fixes: #202037 **Fixes: #203632 ## Summary Builds on top of #203799 and: - simplifies the package deletion code (1 [API call](https://www.elastic.co/docs/api/doc/kibana/operation/operation-delete-fleet-epm-packages-pkgname-pkgversion) instead of 2, per package) - adds retry logic - refactors the testing utils a bit Flaky test runs: - [ESS](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7632) - 190 runs - [Serverless](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7633) - 100 runs ## Details Here's how the test logs look like: ``` info Starting tests └-: Rules Management - Prebuilt Rules - Prebuilt Rules Management └-> "before all" hook: beforeTestSuite.trigger in "Rules Management - Prebuilt Rules - Prebuilt Rules Management" └-: @ess @serverless @skipInServerlessMKI Bootstrap Prebuilt Rules └-> "before all" hook: beforeTestSuite.trigger for "should install fleet packages required for detection engine to function" └-> should install fleet packages required for detection engine to function └-> "before each" hook: global before each for "should install fleet packages required for detection engine to function" └-> "before each" hook for "should install fleet packages required for detection engine to function" │ debg Deleting security_detection_engine package │ debg Deleted security_detection_engine package (was not installed) { │ statusCode: 400, │ error: 'Bad Request', │ message: 'security_detection_engine is not installed' │ } │ debg Deleting endpoint package │ debg Deleted endpoint package (was not installed) { │ statusCode: 400, │ error: 'Bad Request', │ message: 'endpoint is not installed' │ } └- ✓ pass (21.6s) └-> should skip installing fleet packages if they are already installed └-> "before each" hook: global before each for "should skip installing fleet packages if they are already installed" └-> "before each" hook for "should skip installing fleet packages if they are already installed" │ debg Deleting security_detection_engine package │ debg Deleted security_detection_engine package (was installed) │ debg Deleting endpoint package │ debg Deleted endpoint package (was installed) └- ✓ pass (22.4s) └-> "after all" hook: afterTestSuite.trigger for "should skip installing fleet packages if they are already installed" └-> "after all" hook: afterTestSuite.trigger in "Rules Management - Prebuilt Rules - Prebuilt Rules Management" 2 passing (1.0m) ``` ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed
- Loading branch information
Showing
7 changed files
with
107 additions
and
74 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
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
30 changes: 0 additions & 30 deletions
30
...st_suites/detections_response/utils/rules/prebuilt_rules/delete_endpoint_fleet_package.ts
This file was deleted.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
...ation/test_suites/detections_response/utils/rules/prebuilt_rules/delete_fleet_packages.ts
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,87 @@ | ||
/* | ||
* 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 { epmRouteService } from '@kbn/fleet-plugin/common'; | ||
import { RetryService } from '@kbn/ftr-common-functional-services'; | ||
import { | ||
ENDPOINT_PACKAGE_NAME, | ||
PREBUILT_RULES_PACKAGE_NAME, | ||
} from '@kbn/security-solution-plugin/common/detection_engine/constants'; | ||
import { ToolingLog } from '@kbn/tooling-log'; | ||
import type SuperTest from 'supertest'; | ||
import { refreshSavedObjectIndices } from '../../refresh_index'; | ||
|
||
interface DeleteFleetPackageDeps { | ||
supertest: SuperTest.Agent; | ||
retryService: RetryService; | ||
log: ToolingLog; | ||
es: Client; | ||
} | ||
|
||
interface DeleteFleetPackageArgs { | ||
packageName: string; | ||
dependencies: DeleteFleetPackageDeps; | ||
} | ||
|
||
/** | ||
* Delete the security_detection_engine package using fleet API. | ||
*/ | ||
export async function deletePrebuiltRulesFleetPackage(params: DeleteFleetPackageDeps) { | ||
await deleteFleetPackage({ | ||
packageName: PREBUILT_RULES_PACKAGE_NAME, | ||
dependencies: params, | ||
}); | ||
} | ||
|
||
/** | ||
* Delete the endpoint package using fleet API. | ||
*/ | ||
export async function deleteEndpointFleetPackage(params: DeleteFleetPackageDeps) { | ||
await deleteFleetPackage({ | ||
packageName: ENDPOINT_PACKAGE_NAME, | ||
dependencies: params, | ||
}); | ||
} | ||
|
||
async function deleteFleetPackage(params: DeleteFleetPackageArgs): Promise<void> { | ||
const { packageName, dependencies } = params; | ||
const { supertest, retryService, log, es } = dependencies; | ||
|
||
await retryService.tryWithRetries( | ||
'deleteFleetPackage', | ||
async () => { | ||
log.debug(`Deleting ${packageName} package`); | ||
|
||
const response = await supertest | ||
.delete(epmRouteService.getRemovePath(packageName)) | ||
.set('kbn-xsrf', 'true') | ||
.set('elastic-api-version', '2023-10-31') | ||
.send({ force: true }); | ||
|
||
if (response.status === 200) { | ||
log.debug(`Deleted ${packageName} package (was installed)`); | ||
return; | ||
} else if ( | ||
response.status === 400 && | ||
response.body.message === `${packageName} is not installed` | ||
) { | ||
log.debug(`Deleted ${packageName} package (was not installed)`, response.body); | ||
return; | ||
} else { | ||
log.warning(`Error deleting ${packageName} package`, response.body); | ||
throw response.error; | ||
} | ||
}, | ||
{ | ||
retryCount: 2, // overall max 3 attempts | ||
timeout: 3 * 60000, // total timeout applied to all attempts altogether | ||
} | ||
); | ||
|
||
await refreshSavedObjectIndices(es); | ||
} |
30 changes: 0 additions & 30 deletions
30
...tes/detections_response/utils/rules/prebuilt_rules/delete_prebuilt_rules_fleet_package.ts
This file was deleted.
Oops, something went wrong.
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