-
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] expanded flyout - right section - overview tab - …
…mitre attack (#152767)
- Loading branch information
1 parent
526edbd
commit 6e3a34f
Showing
10 changed files
with
285 additions
and
7 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...press/e2e/detection_alerts/expandable_flyout/alert_details_right_panel_overview_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 { | ||
DOCUMENT_DETAILS_FLYOUT_OVERVIEW_TAB_MITRE_ATTACK_DETAILS, | ||
DOCUMENT_DETAILS_FLYOUT_OVERVIEW_TAB_MITRE_ATTACK_TITLE, | ||
} from '../../../screens/document_expandable_flyout'; | ||
import { | ||
expandFirstAlertExpandableFlyout, | ||
openOverviewTab, | ||
} 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 right panel overview tab', | ||
{ testIsolation: false }, | ||
() => { | ||
before(() => { | ||
cleanKibana(); | ||
login(); | ||
createRule(getNewRule()); | ||
visit(ALERTS_URL); | ||
waitForAlertsToPopulate(); | ||
expandFirstAlertExpandableFlyout(); | ||
openOverviewTab(); | ||
}); | ||
|
||
it('should display mitre attack', () => { | ||
cy.get(DOCUMENT_DETAILS_FLYOUT_OVERVIEW_TAB_MITRE_ATTACK_TITLE).should('be.visible'); | ||
cy.get(DOCUMENT_DETAILS_FLYOUT_OVERVIEW_TAB_MITRE_ATTACK_DETAILS).should('be.visible'); | ||
}); | ||
} | ||
); |
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
66 changes: 66 additions & 0 deletions
66
x-pack/plugins/security_solution/public/flyout/right/components/mitre_attack.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,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 type { Story } from '@storybook/react'; | ||
import { RightPanelContext } from '../context'; | ||
import { MitreAttack } from './mitre_attack'; | ||
|
||
export default { | ||
component: MitreAttack, | ||
title: 'Flyout/MitreAttack', | ||
}; | ||
|
||
export const Default: Story<void> = () => { | ||
const contextValue = { | ||
searchHit: { | ||
fields: { | ||
'kibana.alert.rule.parameters': [ | ||
{ | ||
threat: [ | ||
{ | ||
framework: 'MITRE ATT&CK', | ||
tactic: { | ||
id: '123', | ||
reference: 'https://attack.mitre.org/tactics/123', | ||
name: 'Tactic', | ||
}, | ||
technique: [ | ||
{ | ||
id: '456', | ||
reference: 'https://attack.mitre.org/techniques/456', | ||
name: 'Technique', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
} as unknown as RightPanelContext; | ||
|
||
return ( | ||
<RightPanelContext.Provider value={contextValue}> | ||
<MitreAttack /> | ||
</RightPanelContext.Provider> | ||
); | ||
}; | ||
|
||
export const Emtpy: Story<void> = () => { | ||
const contextValue = { | ||
searchHit: { | ||
some_field: 'some_value', | ||
}, | ||
} as unknown as RightPanelContext; | ||
|
||
return ( | ||
<RightPanelContext.Provider value={contextValue}> | ||
<MitreAttack /> | ||
</RightPanelContext.Provider> | ||
); | ||
}; |
73 changes: 73 additions & 0 deletions
73
x-pack/plugins/security_solution/public/flyout/right/components/mitre_attack.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,73 @@ | ||
/* | ||
* 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 { MitreAttack } from './mitre_attack'; | ||
import { RightPanelContext } from '../context'; | ||
import { MITRE_ATTACK_DETAILS_TEST_ID, MITRE_ATTACK_TITLE_TEST_ID } from './test_ids'; | ||
|
||
describe('<MitreAttack />', () => { | ||
it('should render mitre attack information', () => { | ||
const contextValue = { | ||
searchHit: { | ||
fields: { | ||
'kibana.alert.rule.parameters': [ | ||
{ | ||
threat: [ | ||
{ | ||
framework: 'MITRE ATT&CK', | ||
tactic: { | ||
id: '123', | ||
reference: 'https://attack.mitre.org/tactics/123', | ||
name: 'Tactic', | ||
}, | ||
technique: [ | ||
{ | ||
id: '456', | ||
reference: 'https://attack.mitre.org/techniques/456', | ||
name: 'Technique', | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}, | ||
} as unknown as RightPanelContext; | ||
|
||
const { getByTestId } = render( | ||
<RightPanelContext.Provider value={contextValue}> | ||
<MitreAttack /> | ||
</RightPanelContext.Provider> | ||
); | ||
|
||
expect(getByTestId(MITRE_ATTACK_TITLE_TEST_ID)).toBeInTheDocument(); | ||
expect(getByTestId(MITRE_ATTACK_DETAILS_TEST_ID)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render empty component if missing mitre attack value', () => { | ||
const contextValue = { | ||
searchHit: { | ||
some_field: 'some_value', | ||
}, | ||
} as unknown as RightPanelContext; | ||
|
||
const { baseElement } = render( | ||
<RightPanelContext.Provider value={contextValue}> | ||
<MitreAttack /> | ||
</RightPanelContext.Provider> | ||
); | ||
|
||
expect(baseElement).toMatchInlineSnapshot(` | ||
<body> | ||
<div /> | ||
</body> | ||
`); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
x-pack/plugins/security_solution/public/flyout/right/components/mitre_attack.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,37 @@ | ||
/* | ||
* 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 { EuiFlexGroup, EuiFlexItem, EuiTitle } from '@elastic/eui'; | ||
import type { FC } from 'react'; | ||
import React, { useMemo } from 'react'; | ||
import { MITRE_ATTACK_DETAILS_TEST_ID, MITRE_ATTACK_TITLE_TEST_ID } from './test_ids'; | ||
import { getMitreComponentParts } from '../../../detections/mitre/get_mitre_threat_component'; | ||
import { useRightPanelContext } from '../context'; | ||
|
||
export const MitreAttack: FC = () => { | ||
const { searchHit } = useRightPanelContext(); | ||
const threatDetails = useMemo(() => getMitreComponentParts(searchHit), [searchHit]); | ||
|
||
if (!threatDetails || !threatDetails[0]) { | ||
return <></>; | ||
} | ||
|
||
return ( | ||
<EuiFlexGroup direction="column" gutterSize="s"> | ||
<EuiFlexItem data-test-subj={MITRE_ATTACK_TITLE_TEST_ID}> | ||
<EuiTitle size="xxs"> | ||
<h5>{threatDetails[0].title}</h5> | ||
</EuiTitle> | ||
</EuiFlexItem> | ||
<EuiFlexItem data-test-subj={MITRE_ATTACK_DETAILS_TEST_ID}> | ||
{threatDetails[0].description} | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; | ||
|
||
MitreAttack.displayName = 'MitreAttack'; |
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