-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security Solution] Populate alert status auditing fields #171589
Changes from all commits
c856fb0
b7c64e8
164eeda
b962530
9bca9cc
b5bd553
a11742a
7aa9caa
de56bab
1819985
95fc8e2
54cb50f
1fe5fc3
0d8d808
1f3df6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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 { act, render } from '@testing-library/react'; | ||
import { AlertStatus } from './alert_status'; | ||
import { RightPanelContext } from '../context'; | ||
import { WORKFLOW_STATUS_DETAILS_TEST_ID, WORKFLOW_STATUS_TITLE_TEST_ID } from './test_ids'; | ||
import { mockSearchHit } from '../../shared/mocks/mock_search_hit'; | ||
import { TestProviders } from '../../../../common/mock'; | ||
import { useBulkGetUserProfiles } from '../../../../common/components/user_profiles/use_bulk_get_user_profiles'; | ||
|
||
jest.mock('../../../../common/components/user_profiles/use_bulk_get_user_profiles'); | ||
|
||
const renderAlertStatus = (contextValue: RightPanelContext) => | ||
render( | ||
<TestProviders> | ||
<RightPanelContext.Provider value={contextValue}> | ||
<AlertStatus /> | ||
</RightPanelContext.Provider> | ||
</TestProviders> | ||
); | ||
|
||
const mockUserProfiles = [ | ||
{ uid: 'user-id-1', enabled: true, user: { username: 'user1', full_name: 'User 1' }, data: {} }, | ||
]; | ||
|
||
describe('<AlertStatus />', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
it('should render alert status history information', async () => { | ||
(useBulkGetUserProfiles as jest.Mock).mockReturnValue({ | ||
isLoading: false, | ||
data: mockUserProfiles, | ||
}); | ||
const contextValue = { | ||
searchHit: { | ||
...mockSearchHit, | ||
fields: { | ||
'kibana.alert.workflow_user': 'user-id-1', | ||
'kibana.alert.workflow_status_updated_at': '2023-11-01T22:33:26.893Z', | ||
}, | ||
}, | ||
} as unknown as RightPanelContext; | ||
|
||
const { getByTestId } = renderAlertStatus(contextValue); | ||
|
||
await act(async () => { | ||
expect(getByTestId(WORKFLOW_STATUS_TITLE_TEST_ID)).toBeInTheDocument(); | ||
expect(getByTestId(WORKFLOW_STATUS_DETAILS_TEST_ID)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should render empty component if missing workflow_user value', async () => { | ||
const contextValue = { | ||
searchHit: { | ||
some_field: 'some_value', | ||
}, | ||
} as unknown as RightPanelContext; | ||
|
||
const { container } = renderAlertStatus(contextValue); | ||
|
||
await act(async () => { | ||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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, EuiSpacer, EuiTitle } from '@elastic/eui'; | ||
import { getUserDisplayName } from '@kbn/user-profile-components'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import type { FC } from 'react'; | ||
import React from 'react'; | ||
import { WORKFLOW_STATUS_DETAILS_TEST_ID, WORKFLOW_STATUS_TITLE_TEST_ID } from './test_ids'; | ||
import { useRightPanelContext } from '../context'; | ||
import { useBulkGetUserProfiles } from '../../../../common/components/user_profiles/use_bulk_get_user_profiles'; | ||
import { PreferenceFormattedDate } from '../../../../common/components/formatted_date'; | ||
|
||
/** | ||
* Displays info about who last updated the alert's workflow status and when. | ||
*/ | ||
export const AlertStatus: FC = () => { | ||
const { searchHit } = useRightPanelContext(); | ||
const statusUpdatedBy = searchHit.fields?.['kibana.alert.workflow_user'] as string; | ||
const statusUpdatedAt = searchHit.fields?.['kibana.alert.workflow_status_updated_at']; | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason for not using getFieldsData along side our x-pack/plugins/security_solution/public/flyout/document_details/shared/utils.tsx like we use in the rest of the document_details flyout code? The It would be
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured getting the raw data from the searchHit was simple enough, I can change it though |
||
|
||
const result = useBulkGetUserProfiles({ uids: new Set(statusUpdatedBy) }); | ||
const user = result.data?.[0]?.user; | ||
|
||
if (!statusUpdatedBy || !statusUpdatedAt || result.isLoading || user == null) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<EuiFlexGroup direction="column" gutterSize="s"> | ||
<EuiSpacer size="m" /> | ||
<EuiFlexItem data-test-subj={WORKFLOW_STATUS_TITLE_TEST_ID}> | ||
<EuiTitle size="xxs"> | ||
<h5> | ||
<FormattedMessage | ||
id="xpack.securitySolution.flyout.right.about.status.statusHistoryTitle" | ||
defaultMessage="Last alert status change" | ||
/> | ||
</h5> | ||
</EuiTitle> | ||
</EuiFlexItem> | ||
<EuiFlexItem data-test-subj={WORKFLOW_STATUS_DETAILS_TEST_ID}> | ||
<FormattedMessage | ||
id="xpack.securitySolution.flyout.right.about.status.statusHistoryDetails" | ||
defaultMessage="Alert status updated by {user} on {date}" | ||
values={{ | ||
user: getUserDisplayName(user), | ||
date: <PreferenceFormattedDate value={new Date(statusUpdatedAt)} />, | ||
}} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; | ||
|
||
AlertStatus.displayName = 'AlertStatus'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,10 @@ const MITRE_ATTACK_TEST_ID = `${PREFIX}MitreAttack` as const; | |
export const MITRE_ATTACK_TITLE_TEST_ID = `${MITRE_ATTACK_TEST_ID}Title` as const; | ||
export const MITRE_ATTACK_DETAILS_TEST_ID = `${MITRE_ATTACK_TEST_ID}Details` as const; | ||
|
||
export const WORKFLOW_STATUS_TEST_ID = `${PREFIX}WorkflowStatus` as const; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit but this one doesn't need to be exported |
||
export const WORKFLOW_STATUS_TITLE_TEST_ID = `${WORKFLOW_STATUS_TEST_ID}Title` as const; | ||
export const WORKFLOW_STATUS_DETAILS_TEST_ID = `${WORKFLOW_STATUS_TEST_ID}Details` as const; | ||
|
||
/* Investigation section */ | ||
|
||
export const INVESTIGATION_SECTION_TEST_ID = `${PREFIX}InvestigationSection` as const; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please add a short documentation here, just to be consistent with all the other components in the
document_details
folder?