|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +import expect from 'expect'; |
| 9 | +import { |
| 10 | + ELASTIC_HTTP_VERSION_HEADER, |
| 11 | + X_ELASTIC_INTERNAL_ORIGIN_REQUEST, |
| 12 | +} from '@kbn/core-http-common'; |
| 13 | +import { |
| 14 | + ENDPOINT_PACKAGE_NAME, |
| 15 | + PREBUILT_RULES_PACKAGE_NAME, |
| 16 | +} from '@kbn/security-solution-plugin/common/detection_engine/constants'; |
| 17 | +import { |
| 18 | + GET_PREBUILT_RULES_STATUS_URL, |
| 19 | + PERFORM_RULE_INSTALLATION_URL, |
| 20 | + REVIEW_RULE_INSTALLATION_URL, |
| 21 | +} from '@kbn/security-solution-plugin/common/api/detection_engine'; |
| 22 | +import type { FtrProviderContext } from '../../../../../../ftr_provider_context'; |
| 23 | +import { |
| 24 | + deleteEndpointFleetPackage, |
| 25 | + deletePrebuiltRulesFleetPackage, |
| 26 | +} from '../../../../utils/rules/prebuilt_rules/delete_fleet_packages'; |
| 27 | +import { deleteAllRules, waitFor } from '../../../../../../config/services/detections_response'; |
| 28 | + |
| 29 | +export default ({ getService }: FtrProviderContext): void => { |
| 30 | + const es = getService('es'); |
| 31 | + const supertest = getService('supertest'); |
| 32 | + const log = getService('log'); |
| 33 | + const retryService = getService('retry'); |
| 34 | + const detectionsApi = getService('detectionsApi'); |
| 35 | + |
| 36 | + describe('@ess @serverless @skipInServerlessMKI Install from mocked prebuilt rule assets', () => { |
| 37 | + beforeEach(async () => { |
| 38 | + await deleteAllRules(supertest, log); |
| 39 | + |
| 40 | + await deletePrebuiltRulesFleetPackage({ supertest, es, log, retryService }); |
| 41 | + await deleteEndpointFleetPackage({ supertest, es, log, retryService }); |
| 42 | + |
| 43 | + await waitFor( |
| 44 | + async () => { |
| 45 | + const { body: prebuiltRulesStatus } = await supertest |
| 46 | + .get(GET_PREBUILT_RULES_STATUS_URL) |
| 47 | + .set(ELASTIC_HTTP_VERSION_HEADER, '1') |
| 48 | + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') |
| 49 | + .expect(200); |
| 50 | + |
| 51 | + return ( |
| 52 | + prebuiltRulesStatus.stats.num_prebuilt_rules_installed === 0 && |
| 53 | + prebuiltRulesStatus.stats.num_prebuilt_rules_to_install === 0 |
| 54 | + ); |
| 55 | + }, |
| 56 | + 'waitForIndexesRefreshAfterPackagesDeletion', |
| 57 | + log |
| 58 | + ); |
| 59 | + }); |
| 60 | + |
| 61 | + it('install prebuilt rules from a package', async () => { |
| 62 | + const { body: bootstrapPrebuiltRulesResponse } = await detectionsApi |
| 63 | + .bootstrapPrebuiltRules() |
| 64 | + .expect(200); |
| 65 | + |
| 66 | + expect(bootstrapPrebuiltRulesResponse).toMatchObject({ |
| 67 | + packages: expect.arrayContaining([ |
| 68 | + expect.objectContaining({ |
| 69 | + name: PREBUILT_RULES_PACKAGE_NAME, |
| 70 | + }), |
| 71 | + expect.objectContaining({ |
| 72 | + name: ENDPOINT_PACKAGE_NAME, |
| 73 | + }), |
| 74 | + ]), |
| 75 | + }); |
| 76 | + |
| 77 | + const { body: reviewPrebuiltRulesForInstallationResponse } = await supertest |
| 78 | + .post(REVIEW_RULE_INSTALLATION_URL) |
| 79 | + .set('kbn-xsrf', 'true') |
| 80 | + .set(ELASTIC_HTTP_VERSION_HEADER, '1') |
| 81 | + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') |
| 82 | + .send() |
| 83 | + .expect(200); |
| 84 | + |
| 85 | + expect(reviewPrebuiltRulesForInstallationResponse.rules.length).toBeGreaterThan(0); |
| 86 | + |
| 87 | + const { body: installPrebuiltRulesResponse } = await supertest |
| 88 | + .post(PERFORM_RULE_INSTALLATION_URL) |
| 89 | + .set('kbn-xsrf', 'true') |
| 90 | + .set(ELASTIC_HTTP_VERSION_HEADER, '1') |
| 91 | + .set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana') |
| 92 | + .send({ mode: 'ALL_RULES' }) |
| 93 | + .expect(200); |
| 94 | + |
| 95 | + expect(installPrebuiltRulesResponse.summary.succeeded).toBeGreaterThan(0); |
| 96 | + }); |
| 97 | + }); |
| 98 | +}; |
0 commit comments