Skip to content

Commit

Permalink
Unskip tests for the prebuilt rules bootstrap endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
banderror committed Dec 23, 2024
1 parent de1064e commit d95ae9a
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default ({ getService }: FtrProviderContext): void => {
const es = getService('es');
const supertest = getService('supertest');
const log = getService('log');
const retry = getService('retry');
const retryService = getService('retry');

/* This test makes use of the mock packages created in the '/fleet_bundled_packages' folder,
/* in order to assert that, in production environments, the latest stable version of the package
Expand All @@ -35,7 +35,7 @@ export default ({ getService }: FtrProviderContext): void => {
beforeEach(async () => {
await deleteAllRules(supertest, log);
await deleteAllPrebuiltRuleAssets(es, log);
await deletePrebuiltRulesFleetPackage(supertest);
await deletePrebuiltRulesFleetPackage({ supertest, es, log, retryService });
});

it('should install latest stable version and ignore prerelease packages', async () => {
Expand All @@ -49,7 +49,7 @@ export default ({ getService }: FtrProviderContext): void => {
const fleetPackageInstallationResponse = await installPrebuiltRulesPackageViaFleetAPI(
es,
supertest,
retry
retryService
);

expect(fleetPackageInstallationResponse.items.length).toBe(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@ import {
} from '@kbn/security-solution-plugin/common/detection_engine/constants';
import expect from 'expect';
import { FtrProviderContext } from '../../../../../../ftr_provider_context';
import { deletePrebuiltRulesFleetPackage } from '../../../../utils';
import { deleteEndpointFleetPackage } from '../../../../utils/rules/prebuilt_rules/delete_endpoint_fleet_package';
import {
deleteAllPrebuiltRuleAssets,
deleteEndpointFleetPackage,
deletePrebuiltRulesFleetPackage,
} from '../../../../utils';

export default ({ getService }: FtrProviderContext): void => {
const es = getService('es');
const log = getService('log');
const supertest = getService('supertest');
const retryService = getService('retry');
const securitySolutionApi = getService('securitySolutionApi');

// FLAKY: https://github.com/elastic/kibana/issues/203632
describe.skip('@ess @serverless @skipInServerlessMKI Bootstrap Prebuilt Rules', () => {
describe('@ess @serverless @skipInServerlessMKI Bootstrap Prebuilt Rules', () => {
beforeEach(async () => {
await deletePrebuiltRulesFleetPackage(supertest);
await deleteEndpointFleetPackage(supertest);
await deleteAllPrebuiltRuleAssets(es, log);
await deletePrebuiltRulesFleetPackage({ supertest, es, log, retryService });
await deleteEndpointFleetPackage({ supertest, es, log, retryService });
});

it('should install fleet packages required for detection engine to function', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import {
import { deleteAllRules } from '../../../../../../../common/utils/security_solution';
import { deleteAllPrebuiltRuleAssets } from '../../../../utils/rules/prebuilt_rules/delete_all_prebuilt_rule_assets';
import { deleteAllTimelines } from '../../../../utils/rules/prebuilt_rules/delete_all_timelines';
import { deletePrebuiltRulesFleetPackage } from '../../../../utils/rules/prebuilt_rules/delete_prebuilt_rules_fleet_package';
import { deletePrebuiltRulesFleetPackage } from '../../../../utils/rules/prebuilt_rules/delete_fleet_packages';
import { installPrebuiltRulesFleetPackage } from '../../../../utils/rules/prebuilt_rules/install_prebuilt_rules_fleet_package';

export default ({ getService }: FtrProviderContext): void => {
const es = getService('es');
const supertest = getService('supertest');
const log = getService('log');
const retry = getService('retry');
const retryService = getService('retry');

describe('@ess @serverless @skipInServerlessMKI install_prebuilt_rules_from_real_package', () => {
beforeEach(async () => {
await deletePrebuiltRulesFleetPackage(supertest);
await deletePrebuiltRulesFleetPackage({ supertest, es, log, retryService });
await deleteAllRules(supertest, log);
await deleteAllTimelines(es, log);
await deleteAllPrebuiltRuleAssets(es, log);
Expand All @@ -48,7 +48,7 @@ export default ({ getService }: FtrProviderContext): void => {
es,
supertest,
overrideExistingPackage: true,
retryService: retry,
retryService,
});

// Verify that status is updated after package installation
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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;

const resp = await retryService.tryWithRetries(
'deleteFleetPackage.check',
async () => {
log.debug(`Checking if ${packageName} package is installed`);

return await supertest
.get(epmRouteService.getInfoPath(packageName))
.set('kbn-xsrf', 'true')
.set('elastic-api-version', '2023-10-31')
.send();
},
{
retryCount: 2,
timeout: 3 * 30000,
}
);

if (resp.status === 200 && resp.body.item.status === 'installed') {
await retryService.tryWithRetries(
'deleteFleetPackage.delete',
async () => {
log.debug(`Deleting ${packageName} package`);

await supertest
.delete(epmRouteService.getRemovePath(packageName, resp.body.item.version))
.set('kbn-xsrf', 'true')
.send({ force: true })
.expect(200);

log.debug(`Deleted ${packageName} package`);
},
{
retryCount: 2,
timeout: 3 * 60000,
}
);

await refreshSavedObjectIndices(es);
}

// log.debug(`Checking if ${packageName} package is installed`);
// const resp = await supertest
// .get(epmRouteService.getInfoPath(packageName))
// .set('kbn-xsrf', 'true')
// .set('elastic-api-version', '2023-10-31')
// .send();

// if (resp.status === 200 && resp.body.item.status === 'installed') {
// log.debug(`Deleting ${packageName} package`);
// await supertest
// .delete(epmRouteService.getRemovePath(packageName, resp.body.item.version))
// .set('kbn-xsrf', 'true')
// .send({ force: true });

// log.debug(`Deleted ${packageName} package`);
// }
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export * from './create_prebuilt_rule_saved_objects';
export * from './delete_all_prebuilt_rule_assets';
export * from './delete_all_timelines';
export * from './delete_prebuilt_rules_fleet_package';
export * from './delete_fleet_packages';
export * from './get_installed_rules';
export * from './get_prebuilt_rules_and_timelines_status';
export * from './get_prebuilt_rules_status';
Expand Down

0 comments on commit d95ae9a

Please sign in to comment.