Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 2 additions & 8 deletions x-pack/plugins/security_solution/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,12 @@ export const UPDATE_OR_CREATE_LEGACY_ACTIONS = '/internal/api/detection/legacy/n
* Detection engine routes
*/
export const DETECTION_ENGINE_URL = '/api/detection_engine' as const;
export const DETECTION_ENGINE_RULES_URL = `${DETECTION_ENGINE_URL}/rules` as const;
export const DETECTION_ENGINE_PREPACKAGED_URL =
`${DETECTION_ENGINE_RULES_URL}/prepackaged` as const;
export const DETECTION_ENGINE_PRIVILEGES_URL = `${DETECTION_ENGINE_URL}/privileges` as const;
export const DETECTION_ENGINE_INDEX_URL = `${DETECTION_ENGINE_URL}/index` as const;

export const DETECTION_ENGINE_RULES_URL = `${DETECTION_ENGINE_URL}/rules` as const;
export const DETECTION_ENGINE_RULES_URL_FIND = `${DETECTION_ENGINE_RULES_URL}/_find` as const;
export const DETECTION_ENGINE_TAGS_URL = `${DETECTION_ENGINE_URL}/tags` as const;
export const DETECTION_ENGINE_PREPACKAGED_RULES_STATUS_URL =
`${DETECTION_ENGINE_RULES_URL}/prepackaged/_status` as const;
export const DETECTION_ENGINE_RULES_BULK_ACTION =
`${DETECTION_ENGINE_RULES_URL}/_bulk_action` as const;
export const DETECTION_ENGINE_RULES_PREVIEW = `${DETECTION_ENGINE_RULES_URL}/preview` as const;
Expand Down Expand Up @@ -300,11 +296,9 @@ export const RISK_SCORE_DELETE_STORED_SCRIPT = `${INTERNAL_RISK_SCORE_URL}/store
* Internal detection engine routes
*/
export const INTERNAL_DETECTION_ENGINE_URL = '/internal/detection_engine' as const;
export const INTERNAL_DETECTION_ENGINE_RULES_URL = '/internal/detection_engine/rules' as const;
export const DETECTION_ENGINE_ALERTS_INDEX_URL =
`${INTERNAL_DETECTION_ENGINE_URL}/signal/index` as const;
export const DETECTION_ENGINE_RULES_EXCEPTIONS_REFERENCE_URL =
`${INTERNAL_DETECTION_ENGINE_RULES_URL}/exceptions/_find_references` as const;

/**
* Telemetry detection endpoint for any previews requested of what data we are
* providing through UI/UX and for e2e tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
* 2.0.
*/

import { pipe } from 'fp-ts/lib/pipeable';
import { left } from 'fp-ts/lib/Either';
import type { PrePackagedRulesAndTimelinesStatusSchema } from './prepackaged_rules_status_schema';
import { prePackagedRulesAndTimelinesStatusSchema } from './prepackaged_rules_status_schema';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';

describe('prepackaged_rules_schema', () => {
import { GetPrebuiltRulesAndTimelinesStatusResponse } from './response_schema';

describe('Get prebuilt rules and timelines status response schema', () => {
test('it should validate an empty prepackaged response with defaults', () => {
const payload: PrePackagedRulesAndTimelinesStatusSchema = {
const payload: GetPrebuiltRulesAndTimelinesStatusResponse = {
rules_installed: 0,
rules_not_installed: 0,
rules_not_updated: 0,
Expand All @@ -22,7 +22,7 @@ describe('prepackaged_rules_schema', () => {
timelines_not_installed: 0,
timelines_not_updated: 0,
};
const decoded = prePackagedRulesAndTimelinesStatusSchema.decode(payload);
const decoded = GetPrebuiltRulesAndTimelinesStatusResponse.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

Expand All @@ -31,7 +31,7 @@ describe('prepackaged_rules_schema', () => {
});

test('it should not validate an extra invalid field added', () => {
const payload: PrePackagedRulesAndTimelinesStatusSchema & { invalid_field: string } = {
const payload: GetPrebuiltRulesAndTimelinesStatusResponse & { invalid_field: string } = {
rules_installed: 0,
rules_not_installed: 0,
rules_not_updated: 0,
Expand All @@ -41,7 +41,7 @@ describe('prepackaged_rules_schema', () => {
timelines_not_installed: 0,
timelines_not_updated: 0,
};
const decoded = prePackagedRulesAndTimelinesStatusSchema.decode(payload);
const decoded = GetPrebuiltRulesAndTimelinesStatusResponse.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

Expand All @@ -50,7 +50,7 @@ describe('prepackaged_rules_schema', () => {
});

test('it should NOT validate an empty prepackaged response with a negative "rules_installed" number', () => {
const payload: PrePackagedRulesAndTimelinesStatusSchema = {
const payload: GetPrebuiltRulesAndTimelinesStatusResponse = {
rules_installed: -1,
rules_not_installed: 0,
rules_not_updated: 0,
Expand All @@ -59,7 +59,7 @@ describe('prepackaged_rules_schema', () => {
timelines_not_installed: 0,
timelines_not_updated: 0,
};
const decoded = prePackagedRulesAndTimelinesStatusSchema.decode(payload);
const decoded = GetPrebuiltRulesAndTimelinesStatusResponse.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

Expand All @@ -70,7 +70,7 @@ describe('prepackaged_rules_schema', () => {
});

test('it should NOT validate an empty prepackaged response with a negative "rules_not_installed"', () => {
const payload: PrePackagedRulesAndTimelinesStatusSchema = {
const payload: GetPrebuiltRulesAndTimelinesStatusResponse = {
rules_installed: 0,
rules_not_installed: -1,
rules_not_updated: 0,
Expand All @@ -79,7 +79,7 @@ describe('prepackaged_rules_schema', () => {
timelines_not_installed: 0,
timelines_not_updated: 0,
};
const decoded = prePackagedRulesAndTimelinesStatusSchema.decode(payload);
const decoded = GetPrebuiltRulesAndTimelinesStatusResponse.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

Expand All @@ -90,7 +90,7 @@ describe('prepackaged_rules_schema', () => {
});

test('it should NOT validate an empty prepackaged response with a negative "rules_not_updated"', () => {
const payload: PrePackagedRulesAndTimelinesStatusSchema = {
const payload: GetPrebuiltRulesAndTimelinesStatusResponse = {
rules_installed: 0,
rules_not_installed: 0,
rules_not_updated: -1,
Expand All @@ -99,7 +99,7 @@ describe('prepackaged_rules_schema', () => {
timelines_not_installed: 0,
timelines_not_updated: 0,
};
const decoded = prePackagedRulesAndTimelinesStatusSchema.decode(payload);
const decoded = GetPrebuiltRulesAndTimelinesStatusResponse.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

Expand All @@ -110,7 +110,7 @@ describe('prepackaged_rules_schema', () => {
});

test('it should NOT validate an empty prepackaged response with a negative "rules_custom_installed"', () => {
const payload: PrePackagedRulesAndTimelinesStatusSchema = {
const payload: GetPrebuiltRulesAndTimelinesStatusResponse = {
rules_installed: 0,
rules_not_installed: 0,
rules_not_updated: 0,
Expand All @@ -119,7 +119,7 @@ describe('prepackaged_rules_schema', () => {
timelines_not_installed: 0,
timelines_not_updated: 0,
};
const decoded = prePackagedRulesAndTimelinesStatusSchema.decode(payload);
const decoded = GetPrebuiltRulesAndTimelinesStatusResponse.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

Expand All @@ -130,7 +130,7 @@ describe('prepackaged_rules_schema', () => {
});

test('it should NOT validate an empty prepackaged response if "rules_installed" is not there', () => {
const payload: PrePackagedRulesAndTimelinesStatusSchema = {
const payload: GetPrebuiltRulesAndTimelinesStatusResponse = {
rules_installed: 0,
rules_not_installed: 0,
rules_not_updated: 0,
Expand All @@ -141,7 +141,7 @@ describe('prepackaged_rules_schema', () => {
};
// @ts-expect-error
delete payload.rules_installed;
const decoded = prePackagedRulesAndTimelinesStatusSchema.decode(payload);
const decoded = GetPrebuiltRulesAndTimelinesStatusResponse.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 * as t from 'io-ts';
import { PositiveInteger } from '@kbn/securitysolution-io-ts-types';

export type GetPrebuiltRulesAndTimelinesStatusResponse = t.TypeOf<
typeof GetPrebuiltRulesAndTimelinesStatusResponse
>;
export const GetPrebuiltRulesAndTimelinesStatusResponse = t.exact(
t.type({
rules_custom_installed: PositiveInteger,
rules_installed: PositiveInteger,
rules_not_installed: PositiveInteger,
rules_not_updated: PositiveInteger,

timelines_installed: PositiveInteger,
timelines_not_installed: PositiveInteger,
timelines_not_updated: PositiveInteger,
})
);
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
* 2.0.
*/

import { pipe } from 'fp-ts/lib/pipeable';
import { left } from 'fp-ts/lib/Either';
import type { PrePackagedRulesAndTimelinesSchema } from './prepackaged_rules_schema';
import { prePackagedRulesAndTimelinesSchema } from './prepackaged_rules_schema';
import { pipe } from 'fp-ts/lib/pipeable';
import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';

describe('prepackaged_rules_schema', () => {
import { InstallPrebuiltRulesAndTimelinesResponse } from './response_schema';

describe('Install prebuilt rules and timelines response schema', () => {
test('it should validate an empty prepackaged response with defaults', () => {
const payload: PrePackagedRulesAndTimelinesSchema = {
const payload: InstallPrebuiltRulesAndTimelinesResponse = {
rules_installed: 0,
rules_updated: 0,
timelines_installed: 0,
timelines_updated: 0,
};
const decoded = prePackagedRulesAndTimelinesSchema.decode(payload);
const decoded = InstallPrebuiltRulesAndTimelinesResponse.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

Expand All @@ -28,14 +28,14 @@ describe('prepackaged_rules_schema', () => {
});

test('it should not validate an extra invalid field added', () => {
const payload: PrePackagedRulesAndTimelinesSchema & { invalid_field: string } = {
const payload: InstallPrebuiltRulesAndTimelinesResponse & { invalid_field: string } = {
rules_installed: 0,
rules_updated: 0,
invalid_field: 'invalid',
timelines_installed: 0,
timelines_updated: 0,
};
const decoded = prePackagedRulesAndTimelinesSchema.decode(payload);
const decoded = InstallPrebuiltRulesAndTimelinesResponse.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

Expand All @@ -44,13 +44,13 @@ describe('prepackaged_rules_schema', () => {
});

test('it should NOT validate an empty prepackaged response with a negative "rules_installed" number', () => {
const payload: PrePackagedRulesAndTimelinesSchema = {
const payload: InstallPrebuiltRulesAndTimelinesResponse = {
rules_installed: -1,
rules_updated: 0,
timelines_installed: 0,
timelines_updated: 0,
};
const decoded = prePackagedRulesAndTimelinesSchema.decode(payload);
const decoded = InstallPrebuiltRulesAndTimelinesResponse.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

Expand All @@ -61,13 +61,13 @@ describe('prepackaged_rules_schema', () => {
});

test('it should NOT validate an empty prepackaged response with a negative "rules_updated"', () => {
const payload: PrePackagedRulesAndTimelinesSchema = {
const payload: InstallPrebuiltRulesAndTimelinesResponse = {
rules_installed: 0,
rules_updated: -1,
timelines_installed: 0,
timelines_updated: 0,
};
const decoded = prePackagedRulesAndTimelinesSchema.decode(payload);
const decoded = InstallPrebuiltRulesAndTimelinesResponse.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

Expand All @@ -78,15 +78,15 @@ describe('prepackaged_rules_schema', () => {
});

test('it should NOT validate an empty prepackaged response if "rules_installed" is not there', () => {
const payload: PrePackagedRulesAndTimelinesSchema = {
const payload: InstallPrebuiltRulesAndTimelinesResponse = {
rules_installed: 0,
rules_updated: 0,
timelines_installed: 0,
timelines_updated: 0,
};
// @ts-expect-error
delete payload.rules_installed;
const decoded = prePackagedRulesAndTimelinesSchema.decode(payload);
const decoded = InstallPrebuiltRulesAndTimelinesResponse.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

Expand All @@ -97,15 +97,15 @@ describe('prepackaged_rules_schema', () => {
});

test('it should NOT validate an empty prepackaged response if "rules_updated" is not there', () => {
const payload: PrePackagedRulesAndTimelinesSchema = {
const payload: InstallPrebuiltRulesAndTimelinesResponse = {
rules_installed: 0,
rules_updated: 0,
timelines_installed: 0,
timelines_updated: 0,
};
// @ts-expect-error
delete payload.rules_updated;
const decoded = prePackagedRulesAndTimelinesSchema.decode(payload);
const decoded = InstallPrebuiltRulesAndTimelinesResponse.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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 * as t from 'io-ts';
import { PositiveInteger } from '@kbn/securitysolution-io-ts-types';

export type InstallPrebuiltRulesAndTimelinesResponse = t.TypeOf<
typeof InstallPrebuiltRulesAndTimelinesResponse
>;
export const InstallPrebuiltRulesAndTimelinesResponse = t.exact(
t.type({
rules_installed: PositiveInteger,
rules_updated: PositiveInteger,

timelines_installed: PositiveInteger,
timelines_updated: PositiveInteger,
})
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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 { DETECTION_ENGINE_RULES_URL as RULES } from '../../../constants';

export const PREBUILT_RULES_URL = `${RULES}/prepackaged` as const;
export const PREBUILT_RULES_STATUS_URL = `${RULES}/prepackaged/_status` as const;
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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.
*/

export * from './api/get_prebuilt_rules_and_timelines_status/response_schema';
export * from './api/install_prebuilt_rules_and_timelines/response_schema';
export * from './api/urls';

export * from './model/prebuilt_rule';
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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.
*/

export * from './model/prebuilt_rule.mock';
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 2.0.
*/

import type { AddPrepackagedRulesSchema } from './add_prepackaged_rules_schema';
import type { PrebuiltRuleToInstall } from './prebuilt_rule';

export const getAddPrepackagedRulesSchemaMock = (): AddPrepackagedRulesSchema => ({
export const getPrebuiltRuleMock = (): PrebuiltRuleToInstall => ({
description: 'some description',
name: 'Query with a rule id',
query: 'user.name: root or user.name: admin',
Expand All @@ -19,7 +19,7 @@ export const getAddPrepackagedRulesSchemaMock = (): AddPrepackagedRulesSchema =>
version: 1,
});

export const getAddPrepackagedThreatMatchRulesSchemaMock = (): AddPrepackagedRulesSchema => ({
export const getPrebuiltThreatMatchRuleMock = (): PrebuiltRuleToInstall => ({
description: 'some description',
name: 'Query with a rule id',
query: 'user.name: root or user.name: admin',
Expand Down
Loading