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][Exceptions] - Fix bug allowing user to type in custom field option for endpoint exception #152619

Merged
merged 7 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -122,6 +122,9 @@ describe('BuilderEntryItem', () => {
expect(wrapper.find('.euiFormHelpText.euiFormRow__text').at(0).text()).toEqual(
i18n.CUSTOM_COMBOBOX_OPTION_TEXT
);
expect(wrapper.find('[data-test-subj="exceptionBuilderEntryField"]').at(0).props()).toEqual(
expect.objectContaining({ acceptsCustomOptions: true })
);
});

test('it does not render custom option text when "allowCustomOptions" is "true" and it is a nested entry', () => {
Expand Down Expand Up @@ -154,6 +157,44 @@ describe('BuilderEntryItem', () => {
);

expect(wrapper.find('.euiFormHelpText.euiFormRow__text').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="exceptionBuilderEntryField"]').at(0).props()).toEqual(
expect.objectContaining({ acceptsCustomOptions: false })
);
});

test('it does not render custom option text when "allowCustomOptions" is "false"', () => {
wrapper = mount(
<BuilderEntryItem
autocompleteService={autocompleteStartMock}
entry={{
correspondingKeywordField: undefined,
entryIndex: 0,
field: getField('ip'),
id: '123',
nested: undefined,
operator: isOperator,
parent: undefined,
value: '1234',
}}
httpService={mockKibanaHttpService}
indexPattern={{
fields,
id: '1234',
title: 'logstash-*',
}}
listType="detection"
onChange={jest.fn()}
setErrorsExist={jest.fn()}
setWarningsExist={jest.fn()}
showLabel
allowCustomOptions={false}
/>
);

expect(wrapper.find('.euiFormHelpText.euiFormRow__text').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="exceptionBuilderEntryField"]').at(0).props()).toEqual(
expect.objectContaining({ acceptsCustomOptions: false })
);
});

test('it render mapping issues warning text when field has mapping conflicts', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
isLoading={false}
isDisabled={isDisabled || indexPattern == null}
onChange={handleFieldChange}
acceptsCustomOptions={entry.nested == null}
acceptsCustomOptions={entry.nested == null && allowCustomOptions}
data-test-subj="exceptionBuilderEntryField"
showMappingConflicts={true}
/>
Expand Down