Skip to content
Open
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 @@ -55,7 +55,7 @@ export const ExecutorSubActionCreateAlertParamsSchema = schema.object({
source: schema.string(),
sourceRef: schema.string(),
severity: schema.nullable(schema.number({ defaultValue: TheHiveSeverity.MEDIUM })),
isRuleSeverity: schema.boolean(),
isRuleSeverity: schema.nullable(schema.boolean({ defaultValue: false })),
tlp: schema.nullable(schema.number({ defaultValue: TheHiveTLP.AMBER })),
tags: schema.nullable(schema.arrayOf(schema.string())),
body: schema.nullable(schema.string()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ describe('TheHiveParamsFields renders', () => {
expect(getByTestId('descriptionTextArea')).toBeInTheDocument();
expect(getByTestId('tagsInput')).toBeInTheDocument();
expect(getByTestId('severitySelectInput')).toBeInTheDocument();
expect(getByTestId('rule-severity-toggle')).toBeInTheDocument();
expect(getByTestId('tlpSelectInput')).toBeInTheDocument();
expect(getByTestId('typeInput')).toBeInTheDocument();
expect(getByTestId('sourceInput')).toBeInTheDocument();
expect(getByTestId('sourceRefInput')).toBeInTheDocument();

expect(getByTestId('severitySelectInput')).toHaveValue('2');
expect(getByTestId('tlpSelectInput')).toHaveValue('2');
expect(getByTestId('rule-severity-toggle')).not.toBeChecked();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const TheHiveParamsAlertFields: React.FC<ActionParamsProps<ExecutorParams
const [selectedOptions, setSelected] = useState<Array<{ label: string }>>(
alert.tags?.map((tag) => ({ label: tag })) ?? []
);
const [isRuleSeverity, setIsRuleSeverity] = useState<boolean>(alert.isRuleSeverity);
const [isRuleSeverity, setIsRuleSeverity] = useState<boolean>(Boolean(alert.isRuleSeverity));

const onCreateOption = (searchValue: string) => {
setSelected([...selectedOptions, { label: searchValue }]);
Expand Down Expand Up @@ -155,11 +155,11 @@ export const TheHiveParamsAlertFields: React.FC<ActionParamsProps<ExecutorParams
}}
errors={errors['createAlertParam.sourceRef'] as string[]}
/>
{!isTest && isRuleSeverity && (
{!isTest && (
<EuiFormRow fullWidth>
<EuiSwitch
label={translations.IS_RULE_SEVERITY_LABEL}
checked={isRuleSeverity}
checked={Boolean(isRuleSeverity)}
compressed={true}
data-test-subj="rule-severity-toggle"
onChange={(e) => {
Expand All @@ -176,7 +176,7 @@ export const TheHiveParamsAlertFields: React.FC<ActionParamsProps<ExecutorParams
/>
</EuiFormRow>
)}
{!isRuleSeverity && (
{!Boolean(isRuleSeverity) && (
<EuiFormRow fullWidth label={translations.SEVERITY_LABEL}>
<EuiSelect
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const params = {
source: 'source',
sourceRef: '{{alert.uuid}}',
tlp: 2,
severity: 3,
severity: 1,
isRuleSeverity: true,
body: '{"observables":[{"datatype":"url","data":"{{url}}"}],"tags":["test"]}',
},
Expand Down Expand Up @@ -49,6 +49,26 @@ describe('TheHive - renderParameterTemplates', () => {
});
});

it('should not use rule severity if isRuleSeverity is false', () => {
const paramswithoutRuleSeverity = {
...params,
subActionParams: { ...params.subActionParams, isRuleSeverity: false },
};
const result = renderParameterTemplates(logger, paramswithoutRuleSeverity, variables);

expect(result.subActionParams).toEqual({
title: 'title',
description: 'description',
type: 'type',
source: 'source',
sourceRef: variables.alert.uuid,
tlp: 2,
severity: 1,
isRuleSeverity: false,
body: `{"observables":[{"datatype":"url","data":"${variables.url}"}],"tags":["test"]}`,
});
});

it('should render error body', () => {
const errorMessage = 'test error';
jest.spyOn(Mustache, 'render').mockImplementation(() => {
Expand Down