-
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.
Browse files
Browse the repository at this point in the history
* Add Host risk classification column to All hosts table * Add cypress test to risk column on all hosts table * Fix unit test * Add unit test * Add tooltip to host risk column Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
32d0e87
commit da96f61
Showing
26 changed files
with
606 additions
and
171 deletions.
There are no files selected for viewing
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
14 changes: 14 additions & 0 deletions
14
...security_solution/common/search_strategy/security_solution/hosts/risk_score/index.test.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,14 @@ | ||
/* | ||
* 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 { getHostRiskIndex } from '.'; | ||
|
||
describe('hosts risk search_strategy getHostRiskIndex', () => { | ||
it('should properly return index if space is specified', () => { | ||
expect(getHostRiskIndex('testName')).toEqual('ml_host_risk_score_latest_testName'); | ||
}); | ||
}); |
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
33 changes: 33 additions & 0 deletions
33
x-pack/plugins/security_solution/cypress/integration/hosts/hosts_risk_column.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,33 @@ | ||
/* | ||
* 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 { loginAndWaitForPage } from '../../tasks/login'; | ||
|
||
import { HOSTS_URL } from '../../urls/navigation'; | ||
import { cleanKibana } from '../../tasks/common'; | ||
import { esArchiverLoad, esArchiverUnload } from '../../tasks/es_archiver'; | ||
import { TABLE_CELL } from '../../screens/alerts_details'; | ||
import { kqlSearch } from '../../tasks/security_header'; | ||
|
||
describe('All hosts table', () => { | ||
before(() => { | ||
cleanKibana(); | ||
esArchiverLoad('risky_hosts'); | ||
}); | ||
|
||
after(() => { | ||
esArchiverUnload('risky_hosts'); | ||
}); | ||
|
||
it('it renders risk column', () => { | ||
loginAndWaitForPage(HOSTS_URL); | ||
kqlSearch('host.name: "siem-kibana" {enter}'); | ||
|
||
cy.get('[data-test-subj="tableHeaderCell_node.risk_4"]').should('exist'); | ||
cy.get(`${TABLE_CELL} .euiTableCellContent`).eq(4).should('have.text', 'Low'); | ||
}); | ||
}); |
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
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
102 changes: 102 additions & 0 deletions
102
x-pack/plugins/security_solution/public/hosts/components/common/host_risk_score.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,102 @@ | ||
/* | ||
* 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 { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { HostRiskSeverity } from '../../../../common/search_strategy'; | ||
import { TestProviders } from '../../../common/mock'; | ||
import { HostRiskScore } from './host_risk_score'; | ||
|
||
import { EuiHealth, EuiHealthProps } from '@elastic/eui'; | ||
|
||
import { euiThemeVars } from '@kbn/ui-shared-deps-src/theme'; | ||
|
||
jest.mock('@elastic/eui', () => { | ||
const original = jest.requireActual('@elastic/eui'); | ||
return { | ||
...jest.requireActual('@elastic/eui'), | ||
EuiHealth: jest.fn((props: EuiHealthProps) => <original.EuiHealth {...props} />), | ||
}; | ||
}); | ||
|
||
describe('HostRiskScore', () => { | ||
const context = {}; | ||
it('renders critical severity risk score', () => { | ||
const { container } = render( | ||
<TestProviders> | ||
<HostRiskScore severity={HostRiskSeverity.critical} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(container).toHaveTextContent(HostRiskSeverity.critical); | ||
|
||
expect(EuiHealth as jest.Mock).toHaveBeenLastCalledWith( | ||
expect.objectContaining({ color: euiThemeVars.euiColorDanger }), | ||
context | ||
); | ||
}); | ||
|
||
it('renders hight severity risk score', () => { | ||
const { container } = render( | ||
<TestProviders> | ||
<HostRiskScore severity={HostRiskSeverity.high} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(container).toHaveTextContent(HostRiskSeverity.high); | ||
|
||
expect(EuiHealth as jest.Mock).toHaveBeenLastCalledWith( | ||
expect.objectContaining({ color: euiThemeVars.euiColorVis9_behindText }), | ||
context | ||
); | ||
}); | ||
|
||
it('renders moderate severity risk score', () => { | ||
const { container } = render( | ||
<TestProviders> | ||
<HostRiskScore severity={HostRiskSeverity.moderate} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(container).toHaveTextContent(HostRiskSeverity.moderate); | ||
|
||
expect(EuiHealth as jest.Mock).toHaveBeenLastCalledWith( | ||
expect.objectContaining({ color: euiThemeVars.euiColorWarning }), | ||
context | ||
); | ||
}); | ||
|
||
it('renders low severity risk score', () => { | ||
const { container } = render( | ||
<TestProviders> | ||
<HostRiskScore severity={HostRiskSeverity.low} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(container).toHaveTextContent(HostRiskSeverity.low); | ||
|
||
expect(EuiHealth as jest.Mock).toHaveBeenLastCalledWith( | ||
expect.objectContaining({ color: euiThemeVars.euiColorVis0 }), | ||
context | ||
); | ||
}); | ||
|
||
it('renders unknown severity risk score', () => { | ||
const { container } = render( | ||
<TestProviders> | ||
<HostRiskScore severity={HostRiskSeverity.unknown} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(container).toHaveTextContent(HostRiskSeverity.unknown); | ||
|
||
expect(EuiHealth as jest.Mock).toHaveBeenLastCalledWith( | ||
expect.objectContaining({ color: euiThemeVars.euiColorMediumShade }), | ||
context | ||
); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
x-pack/plugins/security_solution/public/hosts/components/common/host_risk_score.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,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 React from 'react'; | ||
|
||
import { EuiHealth, transparentize } from '@elastic/eui'; | ||
|
||
import styled, { css } from 'styled-components'; | ||
import { euiLightVars } from '@kbn/ui-shared-deps-src/theme'; | ||
import { HostRiskSeverity } from '../../../../common/search_strategy'; | ||
|
||
const HOST_RISK_SEVERITY_COLOUR = { | ||
Unknown: euiLightVars.euiColorMediumShade, | ||
Low: euiLightVars.euiColorVis0, | ||
Moderate: euiLightVars.euiColorWarning, | ||
High: euiLightVars.euiColorVis9_behindText, | ||
Critical: euiLightVars.euiColorDanger, | ||
}; | ||
|
||
const HostRiskBadge = styled.div<{ $severity: HostRiskSeverity }>` | ||
${({ theme, $severity }) => css` | ||
width: fit-content; | ||
padding-right: ${theme.eui.paddingSizes.s}; | ||
padding-left: ${theme.eui.paddingSizes.xs}; | ||
${($severity === 'Critical' || $severity === 'High') && | ||
css` | ||
background-color: ${transparentize(theme.eui.euiColorDanger, 0.2)}; | ||
border-radius: 999px; // pill shaped | ||
`}; | ||
`} | ||
`; | ||
|
||
export const HostRiskScore: React.FC<{ severity: HostRiskSeverity }> = ({ severity }) => ( | ||
<HostRiskBadge color={euiLightVars.euiColorDanger} $severity={severity}> | ||
<EuiHealth className="eui-alignMiddle" color={HOST_RISK_SEVERITY_COLOUR[severity]}> | ||
{severity} | ||
</EuiHealth> | ||
</HostRiskBadge> | ||
); |
Oops, something went wrong.