Skip to content
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] BUG Manual Alert in case #93726

Merged
merged 3 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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