-
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.
[Security Solution] Add analyzer to expandable flyout (#153709)
## Summary This PR build on previously merged PR (#152150), and adds analyzer to the left section of expandable flyout under `Visualize`->`Analyzer Graph`. ![image](https://user-images.githubusercontent.com/18648970/227638025-293c2b56-3b40-460d-92e7-0ccbfdbfecf9.png) **How to test** - add `xpack.securitySolution.enableExperimental: ['securityFlyoutEnabled']` to the `kibana.dev.json` file - go to the Alerts page, and click on the expand detail button on any row of the table - then click on the expand details button in the flyout's header - click `Visualize`, then `Analyzer Graph` ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: PhilippeOberti <[email protected]>
- Loading branch information
1 parent
9517d06
commit d210aff
Showing
11 changed files
with
290 additions
and
19 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
.../e2e/detection_alerts/expandable_flyout/alert_details_left_panel_analyzer_graph_tab.cy.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,44 @@ | ||
/* | ||
* 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 { ANALYZER_NODE } from '../../../screens/alerts'; | ||
import { DOCUMENT_DETAILS_FLYOUT_VISUALIZE_TAB_GRAPH_ANALYZER_CONTENT } from '../../../screens/document_expandable_flyout'; | ||
import { | ||
expandFirstAlertExpandableFlyout, | ||
openGraphAnalyzer, | ||
expandDocumentDetailsExpandableFlyoutLeftSection, | ||
} from '../../../tasks/document_expandable_flyout'; | ||
import { cleanKibana } from '../../../tasks/common'; | ||
import { login, visit } from '../../../tasks/login'; | ||
import { createRule } from '../../../tasks/api_calls/rules'; | ||
import { getNewRule } from '../../../objects/rule'; | ||
import { ALERTS_URL } from '../../../urls/navigation'; | ||
import { waitForAlertsToPopulate } from '../../../tasks/create_new_rule'; | ||
|
||
// Skipping these for now as the feature is protected behind a feature flag set to false by default | ||
// To run the tests locally, add 'securityFlyoutEnabled' in the Cypress config.ts here https://github.com/elastic/kibana/blob/main/x-pack/test/security_solution_cypress/config.ts#L50 | ||
describe.skip( | ||
'Alert details expandable flyout left panel analyzer graph', | ||
{ testIsolation: false }, | ||
() => { | ||
before(() => { | ||
cleanKibana(); | ||
login(); | ||
createRule(getNewRule()); | ||
visit(ALERTS_URL); | ||
waitForAlertsToPopulate(); | ||
expandFirstAlertExpandableFlyout(); | ||
expandDocumentDetailsExpandableFlyoutLeftSection(); | ||
openGraphAnalyzer(); | ||
}); | ||
|
||
it('should display analyzer graph and node list', () => { | ||
cy.get(DOCUMENT_DETAILS_FLYOUT_VISUALIZE_TAB_GRAPH_ANALYZER_CONTENT).should('be.visible'); | ||
cy.get(ANALYZER_NODE).first().should('be.visible'); | ||
}); | ||
} | ||
); |
76 changes: 76 additions & 0 deletions
76
x-pack/plugins/security_solution/public/flyout/left/components/analyze.stories.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,76 @@ | ||
/* | ||
* 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 type { Story } from '@storybook/react'; | ||
import { Provider as ReduxStoreProvider } from 'react-redux'; | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { createKibanaReactContext } from '@kbn/kibana-react-plugin/public'; | ||
import type { CoreStart } from '@kbn/core/public'; | ||
import { sourcererReducer } from '../../../common/store/sourcerer'; | ||
import { inputsReducer } from '../../../common/store/inputs'; | ||
import type { LeftPanelContext } from '../context'; | ||
import { LeftFlyoutContext } from '../context'; | ||
import { AnalyzeGraph } from './analyze_graph'; | ||
|
||
export default { | ||
component: AnalyzeGraph, | ||
title: 'Flyout/AnalyzeGraph', | ||
}; | ||
|
||
// TODO to get this working, we need to spent some time getting all the foundation items for storybook | ||
// (ReduxStoreProvider, CellActionsProvider...) similarly to how it was done for the TestProvidersComponent | ||
// see ticket https://github.com/elastic/security-team/issues/6223 | ||
// export const Default: Story<void> = () => { | ||
// const contextValue = { | ||
// eventId: 'some_id', | ||
// } as unknown as LeftPanelContext; | ||
// | ||
// return ( | ||
// <LeftFlyoutContext.Provider value={contextValue}> | ||
// <AnalyzeGraph /> | ||
// </LeftFlyoutContext.Provider> | ||
// ); | ||
// }; | ||
|
||
export const Error: Story<void> = () => { | ||
const store = configureStore({ | ||
reducer: { | ||
inputs: inputsReducer, | ||
sourcerer: sourcererReducer, | ||
}, | ||
}); | ||
const services = { | ||
data: {}, | ||
notifications: { | ||
toasts: { | ||
addError: () => {}, | ||
addSuccess: () => {}, | ||
addWarning: () => {}, | ||
remove: () => {}, | ||
}, | ||
}, | ||
} as unknown as CoreStart; | ||
const KibanaReactContext = createKibanaReactContext({ ...services }); | ||
|
||
const contextValue = { | ||
eventId: null, | ||
} as unknown as LeftPanelContext; | ||
|
||
return ( | ||
<MemoryRouter> | ||
<ReduxStoreProvider store={store}> | ||
<KibanaReactContext.Provider> | ||
<LeftFlyoutContext.Provider value={contextValue}> | ||
<AnalyzeGraph /> | ||
</LeftFlyoutContext.Provider> | ||
</KibanaReactContext.Provider> | ||
</ReduxStoreProvider> | ||
</MemoryRouter> | ||
); | ||
}; |
66 changes: 66 additions & 0 deletions
66
x-pack/plugins/security_solution/public/flyout/left/components/analyze_graph.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,66 @@ | ||
/* | ||
* 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 { render } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
import type { LeftPanelContext } from '../context'; | ||
import { LeftFlyoutContext } from '../context'; | ||
import { TestProviders } from '../../../common/mock'; | ||
import { AnalyzeGraph } from './analyze_graph'; | ||
import { ANALYZE_GRAPH_ERROR_TEST_ID, ANALYZER_GRAPH_TEST_ID } from './test_ids'; | ||
|
||
jest.mock('react-router-dom', () => { | ||
const actual = jest.requireActual('react-router-dom'); | ||
return { ...actual, useLocation: jest.fn().mockReturnValue({ pathname: '' }) }; | ||
}); | ||
|
||
jest.mock('../../../resolver/view/use_resolver_query_params_cleaner'); | ||
|
||
const mockDispatch = jest.fn(); | ||
jest.mock('react-redux', () => { | ||
const original = jest.requireActual('react-redux'); | ||
|
||
return { | ||
...original, | ||
useDispatch: () => mockDispatch, | ||
}; | ||
}); | ||
|
||
describe('<AnalyzeGraph />', () => { | ||
it('renders analyzer graph correctly', () => { | ||
const contextValue = { | ||
eventId: 'eventId', | ||
} as unknown as LeftPanelContext; | ||
|
||
const wrapper = render( | ||
<TestProviders> | ||
<LeftFlyoutContext.Provider value={contextValue}> | ||
<AnalyzeGraph /> | ||
</LeftFlyoutContext.Provider> | ||
</TestProviders> | ||
); | ||
expect(wrapper.getByTestId(ANALYZER_GRAPH_TEST_ID)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render error message on null eventId', () => { | ||
const contextValue = { | ||
eventId: null, | ||
} as unknown as LeftPanelContext; | ||
|
||
const wrapper = render( | ||
<TestProviders> | ||
<LeftFlyoutContext.Provider value={contextValue}> | ||
<AnalyzeGraph /> | ||
</LeftFlyoutContext.Provider> | ||
</TestProviders> | ||
); | ||
expect(wrapper.getByTestId(ANALYZE_GRAPH_ERROR_TEST_ID)).toBeInTheDocument(); | ||
expect(wrapper.getByText('Unable to display analyzer')).toBeInTheDocument(); | ||
expect(wrapper.getByText('There was an error displaying analyzer')).toBeInTheDocument(); | ||
}); | ||
}); |
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
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
15 changes: 15 additions & 0 deletions
15
x-pack/plugins/security_solution/public/flyout/left/components/translations.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,15 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
export const ANALYZER_ERROR_MESSAGE = i18n.translate( | ||
'xpack.securitySolution.flyout.analyzerErrorTitle', | ||
{ | ||
defaultMessage: 'analyzer', | ||
} | ||
); |
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
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
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
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
20 changes: 20 additions & 0 deletions
20
x-pack/plugins/security_solution/public/flyout/shared/translations.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,20 @@ | ||
/* | ||
* 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 { i18n } from '@kbn/i18n'; | ||
|
||
export const ERROR_TITLE = (title: string) => | ||
i18n.translate('xpack.securitySolution.flyout.errorTitle', { | ||
values: { title }, | ||
defaultMessage: 'Unable to display {title}', | ||
}); | ||
|
||
export const ERROR_MESSAGE = (message: string) => | ||
i18n.translate('xpack.securitySolution.flyout.errorMessage', { | ||
values: { message }, | ||
defaultMessage: 'There was an error displaying {message}', | ||
}); |