Skip to content

Commit

Permalink
[8.x] [Security Solution] Add data source editable component (#196948) (
Browse files Browse the repository at this point in the history
#197877)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Solution] Add data source editable component
(#196948)](#196948)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Maxim
Palenov","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-25T16:52:27Z","message":"[Security
Solution] Add data source editable component (#196948)\n\n**Partially
addresses:** https://github.com/elastic/kibana/issues/171520\r\n\r\n##
Summary\r\n\r\nThis PR adds is built on top of
#193828 and add a Data Source
editable component for final edit side of Three Way Diff tab of the
upgrade prebuilt rule workflow.\r\n\r\n##
Details\r\n\r\nhttps://github.com//issues/171520 required
adding editable components for each field diffable rule field. It
imposes some difficulties since it's quite problematic to reuse existing
especially complex components like Data Source from Define Rule step
component.\r\n\r\nThis PR make little refactoring to the Define Rule
step component to make it simpler and make it easier to reuse Data
Source related code chunks scattered in Define Rule step component. You
may notice some copy-paste chunks of Data Source editable component in
the PR. At this stage it's the simplest way to proceed to avoid huge
refactoring and potential new bugs. Taking into account deadlines for
the task it looks like a good trade off. There is a plan to work on
improvements for rules creation/editing forms later
on.","sha":"f34802bc6fae7a17e2b75e22ccde3fee380a4dee","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:Detections
and Resp","Team: SecuritySolution","Team:Detection Rule
Management","Feature:Prebuilt Detection
Rules","backport:prev-minor","v8.17.0"],"title":"[Security Solution] Add
data source editable
component","number":196948,"url":"https://github.com/elastic/kibana/pull/196948","mergeCommit":{"message":"[Security
Solution] Add data source editable component (#196948)\n\n**Partially
addresses:** https://github.com/elastic/kibana/issues/171520\r\n\r\n##
Summary\r\n\r\nThis PR adds is built on top of
#193828 and add a Data Source
editable component for final edit side of Three Way Diff tab of the
upgrade prebuilt rule workflow.\r\n\r\n##
Details\r\n\r\nhttps://github.com//issues/171520 required
adding editable components for each field diffable rule field. It
imposes some difficulties since it's quite problematic to reuse existing
especially complex components like Data Source from Define Rule step
component.\r\n\r\nThis PR make little refactoring to the Define Rule
step component to make it simpler and make it easier to reuse Data
Source related code chunks scattered in Define Rule step component. You
may notice some copy-paste chunks of Data Source editable component in
the PR. At this stage it's the simplest way to proceed to avoid huge
refactoring and potential new bugs. Taking into account deadlines for
the task it looks like a good trade off. There is a plan to work on
improvements for rules creation/editing forms later
on.","sha":"f34802bc6fae7a17e2b75e22ccde3fee380a4dee"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196948","number":196948,"mergeCommit":{"message":"[Security
Solution] Add data source editable component (#196948)\n\n**Partially
addresses:** https://github.com/elastic/kibana/issues/171520\r\n\r\n##
Summary\r\n\r\nThis PR adds is built on top of
#193828 and add a Data Source
editable component for final edit side of Three Way Diff tab of the
upgrade prebuilt rule workflow.\r\n\r\n##
Details\r\n\r\nhttps://github.com//issues/171520 required
adding editable components for each field diffable rule field. It
imposes some difficulties since it's quite problematic to reuse existing
especially complex components like Data Source from Define Rule step
component.\r\n\r\nThis PR make little refactoring to the Define Rule
step component to make it simpler and make it easier to reuse Data
Source related code chunks scattered in Define Rule step component. You
may notice some copy-paste chunks of Data Source editable component in
the PR. At this stage it's the simplest way to proceed to avoid huge
refactoring and potential new bugs. Taking into account deadlines for
the task it looks like a good trade off. There is a plan to work on
improvements for rules creation/editing forms later
on.","sha":"f34802bc6fae7a17e2b75e22ccde3fee380a4dee"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Maxim Palenov <[email protected]>
  • Loading branch information
kibanamachine and maximpn authored Oct 25, 2024
1 parent 4695fb5 commit 07c7f72
Show file tree
Hide file tree
Showing 43 changed files with 1,115 additions and 808 deletions.

This file was deleted.

This file was deleted.

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.
*/

export const useDataViews = jest.fn().mockReturnValue({
data: [],
isFetching: false,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* 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 React from 'react';
import { screen, render } from '@testing-library/react';
import { TestProviders, useFormFieldMock } from '../../../../common/mock';
import { DataViewSelectorField } from './data_view_selector_field';
import { useDataViews } from './use_data_views';

jest.mock('../../../../common/lib/kibana');
jest.mock('./use_data_views');

describe('data_view_selector', () => {
it('renders correctly', () => {
(useDataViews as jest.Mock).mockReturnValue({ data: [], isFetching: false });

render(
<DataViewSelectorField
field={useFormFieldMock<string | undefined>({
value: undefined,
})}
/>,
{ wrapper: TestProviders }
);

expect(screen.queryByTestId('pick-rule-data-source')).toBeInTheDocument();
});

it('disables the combobox while data views are fetching', () => {
(useDataViews as jest.Mock).mockReturnValue({ data: [], isFetching: true });

render(
<DataViewSelectorField
field={useFormFieldMock<string | undefined>({
value: undefined,
})}
/>,
{ wrapper: TestProviders }
);

expect(screen.getByRole('combobox')).toBeDisabled();
});

it('displays alerts on alerts warning when default security view selected', () => {
const dataViews = [
{
id: 'security-solution-default',
title:
'-*elastic-cloud-logs-*,.alerts-security.alerts-default,apm-*-transaction*,auditbeat-*,endgame-*,filebeat-*,logs-*,packetbeat-*,traces-apm*,winlogbeat-*',
},
{
id: '1234',
title: 'logs-*',
},
];
(useDataViews as jest.Mock).mockReturnValue({ data: dataViews, isFetching: false });

render(
<DataViewSelectorField
field={useFormFieldMock<string | undefined>({
value: 'security-solution-default',
})}
/>,
{ wrapper: TestProviders }
);

expect(screen.queryByTestId('defaultSecurityDataViewWarning')).toBeInTheDocument();
});

it('does not display alerts on alerts warning when default security view is not selected', () => {
const dataViews = [
{
id: 'security-solution-default',
title:
'-*elastic-cloud-logs-*,.alerts-security.alerts-default,apm-*-transaction*,auditbeat-*,endgame-*,filebeat-*,logs-*,packetbeat-*,traces-apm*,winlogbeat-*',
},
{
id: '1234',
title: 'logs-*',
},
];
(useDataViews as jest.Mock).mockReturnValue({ data: dataViews, isFetching: false });

render(
<DataViewSelectorField
field={useFormFieldMock<string | undefined>({
value: '1234',
})}
/>,
{ wrapper: TestProviders }
);

expect(screen.queryByTestId('defaultSecurityDataViewWarning')).not.toBeInTheDocument();
});

it('displays warning on missing data view', () => {
(useDataViews as jest.Mock).mockReturnValue({ data: [], isFetching: false });

render(
<DataViewSelectorField
field={useFormFieldMock<string | undefined>({
value: 'non-existent-id',
})}
/>,
{ wrapper: TestProviders }
);

expect(screen.queryByTestId('missingDataViewWarning')).toBeInTheDocument();
});
});
Loading

0 comments on commit 07c7f72

Please sign in to comment.