Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] Allow importing of prebuilt rules via the API #190198

Merged
merged 143 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
143 commits
Select commit Hold shift + click to select a range
f18348e
WIP
rylnd Jul 26, 2024
ea65e92
Allow import endpoint to specify the immutable property
rylnd Aug 6, 2024
179c2b4
Assert our requirement of rule_id
rylnd Aug 6, 2024
6360b05
Style: better assertion syntax
rylnd Aug 6, 2024
0900106
I've decided that we don't need this type
rylnd Aug 6, 2024
816fcfe
Test our allowing of the rule_source param
rylnd Aug 6, 2024
70b53c1
Add some explanatory structure to our tests
rylnd Aug 6, 2024
7e531bb
Remove our optional field from the schema entirely
rylnd Aug 6, 2024
41b86b6
Style: removing trailing whitespace
rylnd Aug 6, 2024
aaaf160
Mark our immutable property as optional
rylnd Aug 6, 2024
a34fad5
Update rule schemas per RFC
rylnd Aug 6, 2024
616b8d8
Add an example datetime string to our openAPI schema
rylnd Aug 6, 2024
7a16826
Add our new, optional field to prebuilt asset schema
rylnd Aug 6, 2024
cbeef5c
Reject prebuilt rule import while feature flag is disabled
rylnd Aug 8, 2024
8dd304f
More comprehensive test
rylnd Aug 8, 2024
28fc492
WIP: ensuring prebuilt rules package is installed when importing rules
rylnd Aug 8, 2024
edda029
[CI] Auto-commit changed files from 'yarn openapi:generate'
kibanamachine Aug 8, 2024
5b3042a
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Aug 9, 2024
b5e36aa
Revert making a base rule param (immutable) optional
rylnd Aug 9, 2024
c7fc008
Default immutable to false in our importing path
rylnd Aug 9, 2024
79cbf0e
[CI] Auto-commit changed files from 'yarn openapi:bundle'
kibanamachine Aug 9, 2024
1c5834b
Update mocks and tests to reflect required param rule_source
rylnd Aug 9, 2024
17f68a3
Apply Dmitrii's solution to type incompatibilities
rylnd Aug 9, 2024
8299557
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Aug 13, 2024
d0e7f3e
Add test for added method functionality
rylnd Aug 13, 2024
88d9128
Remove unneeded cast
rylnd Aug 13, 2024
52daf29
Test behavior when prebuilt rules installation fails
rylnd Aug 13, 2024
e5ccf7b
Adding in prebuilt rule assets to our import logic
rylnd Aug 14, 2024
a8b0a6d
WIP: Implementing calculation of rule_source during import
rylnd Aug 14, 2024
aeec16c
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Aug 14, 2024
5ca0ab5
WIP: calculating rule source during import
rylnd Aug 14, 2024
db19214
Add a new type representing the import of a prebuilt rule
rylnd Aug 19, 2024
dc57d51
Fixes type issues when calculating rule source for import
rylnd Aug 19, 2024
7542a40
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Aug 20, 2024
9e887b0
Refactor prebuilt import logic similar to #190447
rylnd Aug 20, 2024
ff01984
Fixes import_rules_utils tests
rylnd Aug 20, 2024
aa1e6f7
Remove TODO
rylnd Aug 22, 2024
b88dac3
Add logic for retrieving installed prebuilt rules by rule_id
rylnd Aug 22, 2024
c433c92
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Sep 4, 2024
554f340
Remove source_updated_at from rule schema
rylnd Sep 5, 2024
49a166d
Remove deprecation placeholder from immutable field
rylnd Sep 5, 2024
31fc00c
Remove `immutable` from our incoming rule type
rylnd Sep 5, 2024
75b0e3e
Remove requirement on immutable for rule creation
rylnd Sep 5, 2024
dba912b
Version is required in rule import
rylnd Sep 5, 2024
91841c6
Clarify method logic in comments
rylnd Sep 5, 2024
7fab108
Add missing await
rylnd Sep 5, 2024
b471532
Update rule_source calculation
rylnd Sep 5, 2024
7a839ff
Update import error message to include rule_id
rylnd Sep 5, 2024
74cc5e8
Calculate `immutable` field for importing rules
rylnd Sep 5, 2024
62554d9
Simplify interface of rule_source calculation
rylnd Sep 5, 2024
c48b20e
Revert simplification of createRule function
rylnd Sep 10, 2024
9926964
Add note from investigation
rylnd Sep 10, 2024
1853d74
Add new function for importing rules, both prebuilt and custom
rylnd Sep 10, 2024
5a8d7fb
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Sep 10, 2024
899c318
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 10, 2024
c9ba72b
Revert to version field being optional on import
rylnd Sep 10, 2024
49f7068
Update schema tests following making of 'version' optional
rylnd Sep 11, 2024
318da50
Rename both our helper class and its methods
rylnd Sep 11, 2024
937ecc9
Move importRules interface into DetectionRulesClient
rylnd Sep 11, 2024
9f3b9e5
WIP: Adding secondary code paths for new 'withSource' implementations
rylnd Sep 11, 2024
ba8d74a
Undo use of quotations
rylnd Sep 11, 2024
e49b4b2
Revert mock changes
rylnd Sep 11, 2024
9834263
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Sep 12, 2024
de28ac9
Define our new "validated" RuleToImport
rylnd Sep 12, 2024
2305508
Add new methods to our test mocks
rylnd Sep 12, 2024
d5091dc
Add missing test
rylnd Sep 13, 2024
47350da
More wrangling of types
rylnd Sep 13, 2024
538620c
Define DiffableRuleInput as type used for calculating rule_source
rylnd Sep 13, 2024
2d56f12
Fixing existing tests and types
rylnd Sep 13, 2024
9ffed87
Update comment since this bug was already caught
rylnd Sep 13, 2024
ee66654
Satisfy types by manually setting properties in new object argument
rylnd Sep 13, 2024
7b0b794
Revert making rule_source required in RuleResponse
rylnd Sep 13, 2024
2568e5c
Revert "Update mocks and tests to reflect required param rule_source"
rylnd Sep 13, 2024
6470dbd
Fix type error in converter
rylnd Sep 13, 2024
eb7b6fd
Fixing route unit tests
rylnd Sep 13, 2024
b3944dc
Fix tests resulting from bugfix
rylnd Sep 14, 2024
187030e
Remove immutable from rules stream tests
rylnd Sep 14, 2024
430495d
Fix tests related to swapped implementations
rylnd Sep 14, 2024
18265b9
Remove outdated integration test
rylnd Sep 14, 2024
289e621
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Sep 16, 2024
52e879e
Attempt to fix (or at least change) the cypress failure
rylnd Sep 17, 2024
3ba18d4
Fix test failing due to copy change
rylnd Sep 17, 2024
d89759c
Move our FF-dependent tests to the appropriate test suite
rylnd Sep 17, 2024
8923f24
Remove unnecessary field overrides in import logic
rylnd Sep 17, 2024
73e1268
Fix another test failing due to copy changes
rylnd Sep 18, 2024
14cdb0e
Change order of export fields causing test failure
rylnd Sep 18, 2024
6824775
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Sep 19, 2024
1053da5
Define a new Error representing failures during rule import
rylnd Sep 19, 2024
5c5e637
WIP: Separating route-specific logic from general importing
rylnd Sep 19, 2024
df456f2
Clean up some interfaces by combining two helper utilities
rylnd Sep 19, 2024
ac1a691
Cleaning up interfaces, adding tests
rylnd Sep 19, 2024
8f1015a
PrebuiltRulesImportHelper -> RuleSourceImporter
rylnd Sep 20, 2024
79767e2
Fix some unit tests related to the route/client error refactor
rylnd Sep 20, 2024
4396c2b
Remove needless _with_source suffix on filename
rylnd Sep 20, 2024
bae25b6
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Sep 20, 2024
3102745
Fix handling of versionless rules in RuleSourceImporter
rylnd Sep 20, 2024
5c275ac
Add integration tests around new import functionality
rylnd Sep 20, 2024
60cfeda
Move calculateRuleSourceFromAsset to more appropriate location
rylnd Sep 20, 2024
46e641d
Remove new method of PrebuiltRuleAssetsClient in favor of extending e…
rylnd Sep 20, 2024
c798d0e
Aligning importRule implementations, part 1
rylnd Sep 20, 2024
cfb709c
Remove legacyImportRule method in favor of extensible importRule method
rylnd Sep 20, 2024
7be7f7c
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Sep 26, 2024
2b497da
Reverts some previous changes to `internalRuleToAPIResponse`
rylnd Sep 27, 2024
41bcee3
Move parser error handling to the import route level
rylnd Sep 27, 2024
1256947
Make importRules functions more pure
rylnd Sep 27, 2024
5a685e8
Mark old importRules function as legacy
rylnd Sep 27, 2024
dc7bfee
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Sep 27, 2024
b3f1c3d
Move RuleSourceImporter to logic/import
rylnd Sep 27, 2024
82355a5
Simplify RuleSourceImporter interface/logic
rylnd Sep 27, 2024
30bf977
Prevent unnecessary looping during import calculations
rylnd Sep 27, 2024
6f7d10c
Revert changes to our RuleResponse ordering
rylnd Sep 27, 2024
b410a42
Update test descriptions for clarity
rylnd Sep 28, 2024
cd4bc54
style: More accurate variable name
rylnd Sep 28, 2024
3cdbd3b
Fix outstanding TODO/skipped test
rylnd Sep 28, 2024
d06a1e3
Test cleanup
rylnd Sep 28, 2024
c8ab8e8
Fix linter warning about floating promise
rylnd Sep 28, 2024
3c4e312
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Sep 30, 2024
2170462
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Sep 30, 2024
aa751ee
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Oct 3, 2024
62c3bf3
Remove outdated comment
rylnd Oct 4, 2024
f9b1406
Revert "Define DiffableRuleInput as type used for calculating rule_so…
rylnd Oct 4, 2024
677ca33
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Oct 4, 2024
fdc2eec
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Oct 8, 2024
0878638
style: replace mutative while loop with for..of loop
rylnd Oct 8, 2024
6fdcf4a
Adds explicit return type as a best practice
rylnd Oct 8, 2024
0d876c1
Remove unhelpful comment(s)
rylnd Oct 8, 2024
6f4f770
Add test demonstrating that `version` is not required
rylnd Oct 8, 2024
f17fb84
Save some unnecessary looping through prebuilt assets
rylnd Oct 8, 2024
b236c84
More descriptive parameter name
rylnd Oct 8, 2024
2838173
Update x-pack/plugins/security_solution/server/lib/detection_engine/r…
rylnd Oct 10, 2024
86bee40
Add additional test case for preserving multiple errors per rule
rylnd Oct 10, 2024
6f570fa
Removing general types.ts in favor of a declarative interface file
rylnd Oct 10, 2024
52e1117
Simplify interface of RuleSourceImporter
rylnd Oct 10, 2024
e926f4a
Inline our utils.ts functions
rylnd Oct 10, 2024
4f52f6e
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Oct 10, 2024
6062161
Add proper defaults to rule during import
rylnd Oct 10, 2024
3feb693
Define RuleToImport mocks with minimal fields
rylnd Oct 10, 2024
4ef7a39
Fix bug converting a prebuilt rule asset to a rule response
rylnd Oct 10, 2024
02fb54f
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Oct 11, 2024
ca09b52
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Oct 11, 2024
c7872c5
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Oct 15, 2024
52b2081
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Oct 15, 2024
87c6001
Merge branch 'main' into rylnd/prebuilt_rule_import
rylnd Oct 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { RuleToImport } from './rule_to_import';
import type { RuleToImport, ValidatedRuleToImport } from './rule_to_import';

export const getImportRulesSchemaMock = (rewrites?: Partial<RuleToImport>): RuleToImport =>
({
Expand All @@ -15,12 +15,18 @@ export const getImportRulesSchemaMock = (rewrites?: Partial<RuleToImport>): Rule
severity: 'high',
type: 'query',
risk_score: 55,
language: 'kuery',
rule_id: 'rule-1',
immutable: false,
...rewrites,
} as RuleToImport);

export const getValidatedRuleToImportMock = (
overrides?: Partial<ValidatedRuleToImport>
): ValidatedRuleToImport => ({
version: 1,
...getImportRulesSchemaMock(overrides),
});

export const getImportRulesWithIdSchemaMock = (ruleId = 'rule-1'): RuleToImport => ({
id: '6afb8ce1-ea94-4790-8653-fd0b021d2113',
description: 'some description',
Expand All @@ -29,7 +35,6 @@ export const getImportRulesWithIdSchemaMock = (ruleId = 'rule-1'): RuleToImport
severity: 'high',
type: 'query',
risk_score: 55,
language: 'kuery',
rule_id: ruleId,
immutable: false,
});
Expand Down Expand Up @@ -63,7 +68,6 @@ export const getImportThreatMatchRulesSchemaMock = (
severity: 'high',
type: 'threat_match',
risk_score: 55,
language: 'kuery',
rule_id: 'rule-1',
threat_index: ['index-123'],
threat_mapping: [{ entries: [{ field: 'host.name', type: 'mapping', value: 'host.name' }] }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ describe('RuleToImport', () => {
);
});

test('You cannot set the immutable to a number when trying to create a rule', () => {
test('You cannot set immutable to a number', () => {
const payload = getImportRulesSchemaMock({
// @ts-expect-error assign unsupported value
immutable: 5,
Expand All @@ -560,11 +560,11 @@ describe('RuleToImport', () => {
expectParseError(result);

expect(stringifyZodError(result.error)).toMatchInlineSnapshot(
`"immutable: Invalid literal value, expected false"`
`"immutable: Expected boolean, received number"`
);
});

test('You can optionally set the immutable to be false', () => {
test('You can optionally set immutable to false', () => {
const payload: RuleToImportInput = getImportRulesSchemaMock({
immutable: false,
});
Expand All @@ -574,32 +574,14 @@ describe('RuleToImport', () => {
expectParseSuccess(result);
});

test('You cannot set the immutable to be true', () => {
test('You can optionally set immutable to true', () => {
const payload = getImportRulesSchemaMock({
// @ts-expect-error assign unsupported value
immutable: true,
});

const result = RuleToImport.safeParse(payload);
expectParseError(result);

expect(stringifyZodError(result.error)).toMatchInlineSnapshot(
`"immutable: Invalid literal value, expected false"`
);
});

test('You cannot set the immutable to be a number', () => {
const payload = getImportRulesSchemaMock({
// @ts-expect-error assign unsupported value
immutable: 5,
});

const result = RuleToImport.safeParse(payload);
expectParseError(result);

expect(stringifyZodError(result.error)).toMatchInlineSnapshot(
`"immutable: Invalid literal value, expected false"`
);
expectParseSuccess(result);
});

test('You cannot set the risk_score to 101', () => {
Expand Down Expand Up @@ -1091,5 +1073,16 @@ describe('RuleToImport', () => {
expectParseSuccess(result);
expect(result.data).toEqual(payload);
});

describe('backwards compatibility', () => {
it('allows version to be absent', () => {
const payload = getImportRulesSchemaMock();
delete payload.version;

const result = RuleToImport.safeParse(payload);
expectParseSuccess(result);
expect(result.data).toEqual(payload);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import {
RequiredFieldInput,
RuleSignatureId,
TypeSpecificCreateProps,
RuleVersion,
} from '../../model/rule_schema';

/**
* Differences from this and the createRulesSchema are
* - rule_id is required
* - id is optional (but ignored in the import code - rule_id is exclusively used for imports)
* - immutable is optional but if it is any value other than false it will be rejected
* - immutable is optional (but ignored in the import code)
* - created_at is optional (but ignored in the import code)
* - updated_at is optional (but ignored in the import code)
* - created_by is optional (but ignored in the import code)
Expand All @@ -29,7 +30,6 @@ export type RuleToImportInput = z.input<typeof RuleToImport>;
export const RuleToImport = BaseCreateProps.and(TypeSpecificCreateProps).and(
ResponseFields.partial().extend({
rule_id: RuleSignatureId,
immutable: z.literal(false).default(false),
/*
Overriding `required_fields` from ResponseFields because
in ResponseFields `required_fields` has the output type,
Expand All @@ -40,3 +40,19 @@ export const RuleToImport = BaseCreateProps.and(TypeSpecificCreateProps).and(
required_fields: z.array(RequiredFieldInput).optional(),
})
);

/**
* This type represents new rules being imported once the prebuilt rule
* customization work is complete. In order to provide backwards compatibility
* with existing rules, and not change behavior, we now validate `version` in
* the route as opposed to the type itself.
*
* It differs from RuleToImport in that it requires a `version` field.
*/
export type ValidatedRuleToImport = z.infer<typeof ValidatedRuleToImport>;
export type ValidatedRuleToImportInput = z.input<typeof ValidatedRuleToImport>;
export const ValidatedRuleToImport = RuleToImport.and(
z.object({
version: RuleVersion,
})
);
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { RuleToImport } from './rule_to_import';
import type { RuleToImport, ValidatedRuleToImport } from './rule_to_import';

/**
* Additional validation that is implemented outside of the schema itself.
Expand Down Expand Up @@ -55,3 +55,6 @@ const validateThreshold = (rule: RuleToImport): string[] => {
}
return errors;
};

export const ruleToImportHasVersion = (rule: RuleToImport): rule is ValidatedRuleToImport =>
!!rule.version;
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const MAX_PREBUILT_RULES_COUNT = 10_000;
export interface IPrebuiltRuleAssetsClient {
fetchLatestAssets: () => Promise<PrebuiltRuleAsset[]>;

fetchLatestVersions(): Promise<RuleVersionSpecifier[]>;
fetchLatestVersions(ruleIds?: string[]): Promise<RuleVersionSpecifier[]>;

fetchAssetsByVersion(versions: RuleVersionSpecifier[]): Promise<PrebuiltRuleAsset[]>;
}
Expand Down Expand Up @@ -72,8 +72,12 @@ export const createPrebuiltRuleAssetsClient = (
});
},

fetchLatestVersions: (): Promise<RuleVersionSpecifier[]> => {
fetchLatestVersions: (ruleIds: string[] = []): Promise<RuleVersionSpecifier[]> => {
return withSecuritySpan('IPrebuiltRuleAssetsClient.fetchLatestVersions', async () => {
const filter = ruleIds
.map((ruleId) => `${PREBUILT_RULE_ASSETS_SO_TYPE}.attributes.rule_id: ${ruleId}`)
.join(' OR ');

const findResult = await savedObjectsClient.find<
PrebuiltRuleAsset,
{
Expand All @@ -83,6 +87,7 @@ export const createPrebuiltRuleAssetsClient = (
}
>({
type: PREBUILT_RULE_ASSETS_SO_TYPE,
filter,
aggs: {
rules: {
terms: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { getRulesSchemaMock } from '../../../../../../../common/api/detection_engine/model/rule_schema/rule_response_schema.mock';

import type { requestMock } from '../../../../routes/__mocks__';
import { createMockConfig, requestContextMock, serverMock } from '../../../../routes/__mocks__';
import { configMock, requestContextMock, serverMock } from '../../../../routes/__mocks__';
import { buildHapiStream } from '../../../../routes/__mocks__/utils';
import {
getImportRulesRequest,
Expand All @@ -26,23 +26,30 @@ import {
getBasicEmptySearchResponse,
} from '../../../../routes/__mocks__/request_responses';

import * as createRulesAndExceptionsStreamFromNdJson from '../../../logic/import/create_rules_stream_from_ndjson';
import * as createPromiseFromRuleImportStream from '../../../logic/import/create_promise_from_rule_import_stream';
import { getQueryRuleParams } from '../../../../rule_schema/mocks';
import { importRulesRoute } from './route';
import { HttpAuthzError } from '../../../../../machine_learning/validation';
import { createPrebuiltRuleAssetsClient as createPrebuiltRuleAssetsClientMock } from '../../../../prebuilt_rules/logic/rule_assets/__mocks__/prebuilt_rule_assets_client';

jest.mock('../../../../../machine_learning/authz');

let mockPrebuiltRuleAssetsClient: ReturnType<typeof createPrebuiltRuleAssetsClientMock>;

jest.mock('../../../../prebuilt_rules/logic/rule_assets/prebuilt_rule_assets_client', () => ({
createPrebuiltRuleAssetsClient: () => mockPrebuiltRuleAssetsClient,
}));

describe('Import rules route', () => {
let config: ReturnType<typeof createMockConfig>;
let config: ReturnType<typeof configMock.createDefault>;
let server: ReturnType<typeof serverMock.create>;
let request: ReturnType<typeof requestMock.create>;
let { clients, context } = requestContextMock.createTools();

beforeEach(() => {
server = serverMock.create();
({ clients, context } = requestContextMock.createTools());
config = createMockConfig();
config = configMock.createDefault();
const hapiStream = buildHapiStream(ruleIdsToNdJsonString(['rule-1']));
request = getImportRulesRequest(hapiStream);

Expand All @@ -54,6 +61,7 @@ describe('Import rules route', () => {
context.core.elasticsearch.client.asCurrentUser.search.mockResolvedValue(
elasticsearchClientMock.createSuccessTransportRequestPromise(getBasicEmptySearchResponse())
);
mockPrebuiltRuleAssetsClient = createPrebuiltRuleAssetsClientMock();
importRulesRoute(server.router, config);
});

Expand Down Expand Up @@ -112,9 +120,9 @@ describe('Import rules route', () => {
});
});

test('returns error if createRulesAndExceptionsStreamFromNdJson throws error', async () => {
test('returns error if createPromiseFromRuleImportStream throws error', async () => {
const transformMock = jest
.spyOn(createRulesAndExceptionsStreamFromNdJson, 'createRulesAndExceptionsStreamFromNdJson')
.spyOn(createPromiseFromRuleImportStream, 'createPromiseFromRuleImportStream')
.mockImplementation(() => {
throw new Error('Test error');
});
Expand All @@ -133,6 +141,30 @@ describe('Import rules route', () => {
expect(response.status).toEqual(400);
expect(response.body).toEqual({ message: 'Invalid file extension .html', status_code: 400 });
});

describe('with prebuilt rules customization enabled', () => {
beforeEach(() => {
clients.detectionRulesClient.importRules.mockResolvedValueOnce([]);
server = serverMock.create(); // old server already registered this route
config = configMock.withExperimentalFeature(config, 'prebuiltRulesCustomizationEnabled');

importRulesRoute(server.router, config);
});

test('returns 500 if importing fails', async () => {
clients.detectionRulesClient.importRules
.mockReset()
.mockRejectedValue(new Error('test error'));

const response = await server.inject(request, requestContextMock.convertContext(context));

expect(response.status).toEqual(500);
expect(response.body).toMatchObject({
message: 'test error',
status_code: 500,
});
});
});
});

describe('single rule import', () => {
Expand Down
Loading