forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] [Attack discovery] Additional Attack discovery te…
…sts (elastic#199659) ### [Security Solution] [Attack discovery] Additional Attack discovery tests This PR adds additional unit test coverage to Attack discovery.
- Loading branch information
1 parent
55da11e
commit 53d4580
Showing
33 changed files
with
2,195 additions
and
29 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'); | ||
}); | ||
}); |
106 changes: 106 additions & 0 deletions
106
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.