Skip to content

Commit

Permalink
[SECURITY SOLUTION] BUG Manual Alert in case (#93726)
Browse files Browse the repository at this point in the history
* get the data where it belongs

* Fix layout when alert is deleted

Co-authored-by: Christos Nasikas <[email protected]>
  • Loading branch information
XavierM and cnasikas authored Mar 8, 2021
1 parent 5e634e9 commit 5d96e5f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ export const getAlertAttachment = ({
alertId: string;
index: string;
loadingAlertData: boolean;
ruleId: string;
ruleName: string;
ruleId?: string | null;
ruleName?: string | null;
}): EuiCommentProps => {
return {
username: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,10 @@ export const UserActionTree = React.memo(
return comments;
}

const ruleId = comment?.rule?.id ?? manualAlertsData[alertId]?.rule?.id?.[0] ?? '';
const ruleId =
comment?.rule?.id ?? manualAlertsData[alertId]?.signal?.rule?.id?.[0] ?? null;
const ruleName =
comment?.rule?.name ??
manualAlertsData[alertId]?.rule?.name?.[0] ??
i18n.UNKNOWN_RULE;
comment?.rule?.name ?? manualAlertsData[alertId]?.signal?.rule?.name?.[0] ?? null;

return [
...comments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,18 @@ describe('UserActionAvatar ', () => {
expect(wrapper.text()).toBe('added an alert from Awesome rule');
});

it('does NOT render the link when the alert is undefined', async () => {
it('does NOT render the link when the rule is null', async () => {
const wrapper = mount(
<TestProviders>
{/* @ts-expect-error */}
<AlertCommentEvent alert={undefined} commentType={CommentType.alert} />
<AlertCommentEvent {...props} ruleId={null} />
</TestProviders>
);

expect(
wrapper.find(`[data-test-subj="alert-rule-link-alert-id-1"]`).first().exists()
).toBeFalsy();

expect(wrapper.text()).toBe('added an alert from ');
});

it('does NOT render the link when the rule is undefined', async () => {
const alert = {
alertId: 'alert-id-1',
commentType: CommentType.alert,
};

const wrapper = mount(
<TestProviders>
{/* @ts-expect-error*/}
<AlertCommentEvent alert={alert} />
</TestProviders>
);

expect(
wrapper.find(`[data-test-subj="alert-rule-link-alert-id-1"]`).first().exists()
).toBeFalsy();

expect(wrapper.text()).toBe('added an alert from ');
expect(wrapper.text()).toBe('added an alert from Unknown rule');
});

it('navigate to app on link click', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import React, { memo, useCallback } from 'react';
import { isEmpty } from 'lodash';
import { EuiText, EuiLoadingSpinner } from '@elastic/eui';

import { APP_ID } from '../../../../common/constants';
Expand All @@ -20,8 +21,8 @@ import { LinkAnchor } from '../../../common/components/links';
interface Props {
alertId: string;
commentType: CommentType;
ruleId: string;
ruleName: string;
ruleId?: string | null;
ruleName?: string | null;
alertsCount?: number;
loadingAlertData?: boolean;
}
Expand Down Expand Up @@ -51,16 +52,16 @@ const AlertCommentEventComponent: React.FC<Props> = ({
<>
{`${i18n.ALERT_COMMENT_LABEL_TITLE} `}
{loadingAlertData && <EuiLoadingSpinner size="m" />}
{!loadingAlertData && ruleId !== '' && (
{!loadingAlertData && !isEmpty(ruleId) && (
<LinkAnchor
onClick={onLinkClick}
href={formatUrl(getRuleDetailsUrl(ruleId ?? '', urlSearch))}
data-test-subj={`alert-rule-link-${alertId ?? 'deleted'}`}
>
{ruleName}
{ruleName ?? i18n.UNKNOWN_RULE}
</LinkAnchor>
)}
{!loadingAlertData && ruleId === '' && <EuiText>{ruleName}</EuiText>}
{!loadingAlertData && isEmpty(ruleId) && i18n.UNKNOWN_RULE}
</>
) : (
<>
Expand Down

0 comments on commit 5d96e5f

Please sign in to comment.