Skip to content

Commit 3151dbf

Browse files
[8.x] [Security Solution] [Attack discovery] Additional Attack discovery tests (#199659) (#200061)
# Backport This will backport the following commits from `main` to `8.x`: - [[Security Solution] [Attack discovery] Additional Attack discovery tests (#199659)](#199659) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Andrew Macri","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-13T17:37:54Z","message":"[Security Solution] [Attack discovery] Additional Attack discovery tests (#199659)\n\n### [Security Solution] [Attack discovery] Additional Attack discovery tests\r\n\r\nThis PR adds additional unit test coverage to Attack discovery.","sha":"53d4580a8959a9e4b166df4e4a4cc83de61f7928","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team: SecuritySolution","Team:Security Generative AI","backport:version","v8.17.0","v8.16.1"],"title":"[Security Solution] [Attack discovery] Additional Attack discovery tests","number":199659,"url":"https://github.com/elastic/kibana/pull/199659","mergeCommit":{"message":"[Security Solution] [Attack discovery] Additional Attack discovery tests (#199659)\n\n### [Security Solution] [Attack discovery] Additional Attack discovery tests\r\n\r\nThis PR adds additional unit test coverage to Attack discovery.","sha":"53d4580a8959a9e4b166df4e4a4cc83de61f7928"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199659","number":199659,"mergeCommit":{"message":"[Security Solution] [Attack discovery] Additional Attack discovery tests (#199659)\n\n### [Security Solution] [Attack discovery] Additional Attack discovery tests\r\n\r\nThis PR adds additional unit test coverage to Attack discovery.","sha":"53d4580a8959a9e4b166df4e4a4cc83de61f7928"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Andrew Macri <[email protected]>
1 parent 654c06f commit 3151dbf

File tree

33 files changed

+2195
-29
lines changed

33 files changed

+2195
-29
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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 { fireEvent, render, screen } from '@testing-library/react';
9+
import React from 'react';
10+
11+
import { AlertsRange } from './alerts_range';
12+
import {
13+
MAX_LATEST_ALERTS,
14+
MIN_LATEST_ALERTS,
15+
} from '../assistant/settings/alerts_settings/alerts_settings';
16+
import { KnowledgeBaseConfig } from '../assistant/types';
17+
18+
const nonDefaultMin = MIN_LATEST_ALERTS + 5000;
19+
const nonDefaultMax = nonDefaultMin + 5000;
20+
21+
describe('AlertsRange', () => {
22+
beforeEach(() => jest.clearAllMocks());
23+
24+
it('renders the expected default min alerts', () => {
25+
render(<AlertsRange value={200} />);
26+
27+
expect(screen.getByText(`${MIN_LATEST_ALERTS}`)).toBeInTheDocument();
28+
});
29+
30+
it('renders the expected NON-default min alerts', () => {
31+
render(
32+
<AlertsRange maxAlerts={nonDefaultMax} minAlerts={nonDefaultMin} value={nonDefaultMin} />
33+
);
34+
35+
expect(screen.getByText(`${nonDefaultMin}`)).toBeInTheDocument();
36+
});
37+
38+
it('renders the expected default max alerts', () => {
39+
render(<AlertsRange value={200} />);
40+
41+
expect(screen.getByText(`${MAX_LATEST_ALERTS}`)).toBeInTheDocument();
42+
});
43+
44+
it('renders the expected NON-default max alerts', () => {
45+
render(
46+
<AlertsRange maxAlerts={nonDefaultMax} minAlerts={nonDefaultMin} value={nonDefaultMax} />
47+
);
48+
49+
expect(screen.getByText(`${nonDefaultMax}`)).toBeInTheDocument();
50+
});
51+
52+
it('calls onChange when the range value changes', () => {
53+
const mockOnChange = jest.fn();
54+
render(<AlertsRange onChange={mockOnChange} value={MIN_LATEST_ALERTS} />);
55+
56+
fireEvent.click(screen.getByText(`${MAX_LATEST_ALERTS}`));
57+
58+
expect(mockOnChange).toHaveBeenCalled();
59+
});
60+
61+
it('calls setUpdatedKnowledgeBaseSettings with the expected arguments', () => {
62+
const mockSetUpdatedKnowledgeBaseSettings = jest.fn();
63+
const knowledgeBase: KnowledgeBaseConfig = { latestAlerts: 150 };
64+
65+
render(
66+
<AlertsRange
67+
knowledgeBase={knowledgeBase}
68+
setUpdatedKnowledgeBaseSettings={mockSetUpdatedKnowledgeBaseSettings}
69+
value={MIN_LATEST_ALERTS}
70+
/>
71+
);
72+
73+
fireEvent.click(screen.getByText(`${MAX_LATEST_ALERTS}`));
74+
75+
expect(mockSetUpdatedKnowledgeBaseSettings).toHaveBeenCalledWith({
76+
...knowledgeBase,
77+
latestAlerts: MAX_LATEST_ALERTS,
78+
});
79+
});
80+
81+
it('renders with the correct initial value', () => {
82+
render(<AlertsRange value={250} />);
83+
84+
expect(screen.getByTestId('alertsRange')).toHaveValue('250');
85+
});
86+
});

x-pack/plugins/elastic_assistant/server/__mocks__/raw_attack_discoveries.ts

Lines changed: 106 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 { AnonymizationFieldResponse } from '@kbn/elastic-assistant-common/impl/schemas/anonymization_fields/bulk_crud_anonymization_fields_route.gen';
9+
10+
export const getMockAnonymizationFieldResponse = (): AnonymizationFieldResponse[] => [
11+
{
12+
id: '6UDO45IBoEQSo_rIK1EW',
13+
timestamp: '2024-10-31T18:19:52.468Z',
14+
field: '_id',
15+
allowed: true,
16+
anonymized: false,
17+
createdAt: '2024-10-31T18:19:52.468Z',
18+
namespace: 'default',
19+
},
20+
{
21+
id: '6kDO45IBoEQSo_rIK1EW',
22+
timestamp: '2024-10-31T18:19:52.468Z',
23+
field: '@timestamp',
24+
allowed: true,
25+
anonymized: false,
26+
createdAt: '2024-10-31T18:19:52.468Z',
27+
namespace: 'default',
28+
},
29+
{
30+
id: '60DO45IBoEQSo_rIK1EW',
31+
timestamp: '2024-10-31T18:19:52.468Z',
32+
field: 'cloud.availability_zone',
33+
allowed: true,
34+
anonymized: false,
35+
createdAt: '2024-10-31T18:19:52.468Z',
36+
namespace: 'default',
37+
},
38+
{
39+
id: '_EDO45IBoEQSo_rIK1EW',
40+
timestamp: '2024-10-31T18:19:52.468Z',
41+
field: 'host.name',
42+
allowed: true,
43+
anonymized: true,
44+
createdAt: '2024-10-31T18:19:52.468Z',
45+
namespace: 'default',
46+
},
47+
{
48+
id: 'SkDO45IBoEQSo_rIK1IW',
49+
timestamp: '2024-10-31T18:19:52.468Z',
50+
field: 'user.name',
51+
allowed: true,
52+
anonymized: true,
53+
createdAt: '2024-10-31T18:19:52.468Z',
54+
namespace: 'default',
55+
},
56+
{
57+
id: 'TUDO45IBoEQSo_rIK1IW',
58+
timestamp: '2024-10-31T18:19:52.468Z',
59+
field: 'user.target.name',
60+
allowed: true,
61+
anonymized: true,
62+
createdAt: '2024-10-31T18:19:52.468Z',
63+
namespace: 'default',
64+
},
65+
];

x-pack/plugins/elastic_assistant/server/lib/attack_discovery/graphs/default_attack_discovery_graph/nodes/generate/helpers/get_alerts_context_prompt/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('getAlertsContextPrompt', () => {
1212
it('generates the correct prompt', () => {
1313
const anonymizedAlerts = ['Alert 1', 'Alert 2', 'Alert 3'];
1414

15-
const expected = `You are a cyber security analyst tasked with analyzing security events from Elastic Security to identify and report on potential cyber attacks or progressions. Your report should focus on high-risk incidents that could severely impact the organization, rather than isolated alerts. Present your findings in a way that can be easily understood by anyone, regardless of their technical expertise, as if you were briefing the CISO. Break down your response into sections based on timing, hosts, and users involved. When correlating alerts, use kibana.alert.original_time when it's available, otherwise use @timestamp. Include appropriate context about the affected hosts and users. Describe how the attack progression might have occurred and, if feasible, attribute it to known threat groups. Prioritize high and critical alerts, but include lower-severity alerts if desired. In the description field, provide as much detail as possible, in a bulleted list explaining any attack progressions. Accuracy is of utmost importance. You MUST escape all JSON special characters (i.e. backslashes, double quotes, newlines, tabs, carriage returns, backspaces, and form feeds).
15+
const expected = `${getDefaultAttackDiscoveryPrompt()}
1616
1717
Use context from the following alerts to provide insights:
1818

0 commit comments

Comments
 (0)