-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.16] [Security Solution] [Attack discovery] Additional Attack disco…
…very tests (#199659) (#200066) # Backport This will backport the following commits from `main` to `8.16`: - [[Security Solution] [Attack discovery] Additional Attack discovery tests (#199659)](#199659) <!--- Backport version: 8.9.8 --> ### 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"],"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.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^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","labelRegex":"^v8.17.0$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/200061","number":200061,"state":"OPEN"},{"branch":"8.16","label":"v8.16.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
- Loading branch information
1 parent
ecfb386
commit 58dd087
Showing
33 changed files
with
2,182 additions
and
40 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
x-pack/packages/kbn-elastic-assistant/impl/knowledge_base/alerts_range.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* 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 { fireEvent, render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { AlertsRange } from './alerts_range'; | ||
import { | ||
MAX_LATEST_ALERTS, | ||
MIN_LATEST_ALERTS, | ||
} from '../assistant/settings/alerts_settings/alerts_settings'; | ||
import { KnowledgeBaseConfig } from '../assistant/types'; | ||
|
||
const nonDefaultMin = MIN_LATEST_ALERTS + 5000; | ||
const nonDefaultMax = nonDefaultMin + 5000; | ||
|
||
describe('AlertsRange', () => { | ||
beforeEach(() => jest.clearAllMocks()); | ||
|
||
it('renders the expected default min alerts', () => { | ||
render(<AlertsRange value={200} />); | ||
|
||
expect(screen.getByText(`${MIN_LATEST_ALERTS}`)).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders the expected NON-default min alerts', () => { | ||
render( | ||
<AlertsRange maxAlerts={nonDefaultMax} minAlerts={nonDefaultMin} value={nonDefaultMin} /> | ||
); | ||
|
||
expect(screen.getByText(`${nonDefaultMin}`)).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders the expected default max alerts', () => { | ||
render(<AlertsRange value={200} />); | ||
|
||
expect(screen.getByText(`${MAX_LATEST_ALERTS}`)).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders the expected NON-default max alerts', () => { | ||
render( | ||
<AlertsRange maxAlerts={nonDefaultMax} minAlerts={nonDefaultMin} value={nonDefaultMax} /> | ||
); | ||
|
||
expect(screen.getByText(`${nonDefaultMax}`)).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls onChange when the range value changes', () => { | ||
const mockOnChange = jest.fn(); | ||
render(<AlertsRange onChange={mockOnChange} value={MIN_LATEST_ALERTS} />); | ||
|
||
fireEvent.click(screen.getByText(`${MAX_LATEST_ALERTS}`)); | ||
|
||
expect(mockOnChange).toHaveBeenCalled(); | ||
}); | ||
|
||
it('calls setUpdatedKnowledgeBaseSettings with the expected arguments', () => { | ||
const mockSetUpdatedKnowledgeBaseSettings = jest.fn(); | ||
const knowledgeBase: KnowledgeBaseConfig = { latestAlerts: 150 }; | ||
|
||
render( | ||
<AlertsRange | ||
knowledgeBase={knowledgeBase} | ||
setUpdatedKnowledgeBaseSettings={mockSetUpdatedKnowledgeBaseSettings} | ||
value={MIN_LATEST_ALERTS} | ||
/> | ||
); | ||
|
||
fireEvent.click(screen.getByText(`${MAX_LATEST_ALERTS}`)); | ||
|
||
expect(mockSetUpdatedKnowledgeBaseSettings).toHaveBeenCalledWith({ | ||
...knowledgeBase, | ||
latestAlerts: MAX_LATEST_ALERTS, | ||
}); | ||
}); | ||
|
||
it('renders with the correct initial value', () => { | ||
render(<AlertsRange value={250} />); | ||
|
||
expect(screen.getByTestId('alertsRange')).toHaveValue('250'); | ||
}); | ||
}); |
104 changes: 93 additions & 11 deletions
104
x-pack/plugins/elastic_assistant/server/__mocks__/raw_attack_discoveries.ts
Large diffs are not rendered by default.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
...c_assistant/server/lib/attack_discovery/evaluation/__mocks__/mock_anonymization_fields.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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 { AnonymizationFieldResponse } from '@kbn/elastic-assistant-common/impl/schemas/anonymization_fields/bulk_crud_anonymization_fields_route.gen'; | ||
|
||
export const getMockAnonymizationFieldResponse = (): AnonymizationFieldResponse[] => [ | ||
{ | ||
id: '6UDO45IBoEQSo_rIK1EW', | ||
timestamp: '2024-10-31T18:19:52.468Z', | ||
field: '_id', | ||
allowed: true, | ||
anonymized: false, | ||
createdAt: '2024-10-31T18:19:52.468Z', | ||
namespace: 'default', | ||
}, | ||
{ | ||
id: '6kDO45IBoEQSo_rIK1EW', | ||
timestamp: '2024-10-31T18:19:52.468Z', | ||
field: '@timestamp', | ||
allowed: true, | ||
anonymized: false, | ||
createdAt: '2024-10-31T18:19:52.468Z', | ||
namespace: 'default', | ||
}, | ||
{ | ||
id: '60DO45IBoEQSo_rIK1EW', | ||
timestamp: '2024-10-31T18:19:52.468Z', | ||
field: 'cloud.availability_zone', | ||
allowed: true, | ||
anonymized: false, | ||
createdAt: '2024-10-31T18:19:52.468Z', | ||
namespace: 'default', | ||
}, | ||
{ | ||
id: '_EDO45IBoEQSo_rIK1EW', | ||
timestamp: '2024-10-31T18:19:52.468Z', | ||
field: 'host.name', | ||
allowed: true, | ||
anonymized: true, | ||
createdAt: '2024-10-31T18:19:52.468Z', | ||
namespace: 'default', | ||
}, | ||
{ | ||
id: 'SkDO45IBoEQSo_rIK1IW', | ||
timestamp: '2024-10-31T18:19:52.468Z', | ||
field: 'user.name', | ||
allowed: true, | ||
anonymized: true, | ||
createdAt: '2024-10-31T18:19:52.468Z', | ||
namespace: 'default', | ||
}, | ||
{ | ||
id: 'TUDO45IBoEQSo_rIK1IW', | ||
timestamp: '2024-10-31T18:19:52.468Z', | ||
field: 'user.target.name', | ||
allowed: true, | ||
anonymized: true, | ||
createdAt: '2024-10-31T18:19:52.468Z', | ||
namespace: 'default', | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.