[Security Solution][Exceptions] - Fix operator logic for large value lists (#99490)

### Summary
Logic for operators was off, this fix adds unit tests to ensure this bug is not hit again and updates logic
This commit is contained in:
Yara Tercero 2021-05-09 22:14:24 -07:00 committed by GitHub
parent f669addb40
commit ebe85665a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 1 deletions

View file

@ -228,6 +228,7 @@ describe('BuilderEntryItem', () => {
test('it renders field values correctly when operator is "isInListOperator"', () => {
wrapper = mount(
<BuilderEntryItem
allowLargeValueLists
autocompleteService={autocompleteStartMock}
entry={{
correspondingKeywordField: undefined,
@ -264,6 +265,7 @@ describe('BuilderEntryItem', () => {
test('it renders field values correctly when operator is "isNotInListOperator"', () => {
wrapper = mount(
<BuilderEntryItem
allowLargeValueLists
autocompleteService={autocompleteStartMock}
entry={{
correspondingKeywordField: undefined,

View file

@ -193,7 +193,7 @@ export const BuilderEntryItem: React.FC<EntryItemProps> = ({
entry,
listType,
entry.field != null && entry.field.type === 'boolean',
isFirst && !allowLargeValueLists
isFirst && allowLargeValueLists
);
const comboBox = (
<OperatorComponent

View file

@ -120,6 +120,80 @@ describe('ExceptionBuilderComponent', () => {
);
});
test('it displays "is in list" operators if "allowLargeValueLists" is true', async () => {
wrapper = mount(
<EuiThemeProvider>
<ExceptionBuilderComponent
allowLargeValueLists={true}
autocompleteService={autocompleteStartMock}
exceptionListItems={[
{
...getExceptionListItemSchemaMock(),
entries: [
{ ...getEntryMatchAnyMock(), field: getField('ip').name, value: ['some ip'] },
],
},
]}
httpService={mockKibanaHttpService}
indexPatterns={{
fields,
id: '1234',
title: 'logstash-*',
}}
isAndDisabled={false}
isNestedDisabled={false}
isOrDisabled={false}
listId="list_id"
listNamespaceType="single"
listType="detection"
ruleName="Test rule"
onChange={jest.fn()}
/>
</EuiThemeProvider>
);
expect(
wrapper.find('[data-test-subj="operatorAutocompleteComboBox"]').at(0).prop('options')
).toEqual(expect.arrayContaining([{ label: 'is in list' }, { label: 'is not in list' }]));
});
test('it does not display "is in list" operators if "allowLargeValueLists" is false', async () => {
wrapper = mount(
<EuiThemeProvider>
<ExceptionBuilderComponent
allowLargeValueLists={false}
autocompleteService={autocompleteStartMock}
exceptionListItems={[
{
...getExceptionListItemSchemaMock(),
entries: [
{ ...getEntryMatchAnyMock(), field: getField('ip').name, value: ['some ip'] },
],
},
]}
httpService={mockKibanaHttpService}
indexPatterns={{
fields,
id: '1234',
title: 'logstash-*',
}}
isAndDisabled={false}
isNestedDisabled={false}
isOrDisabled={false}
listId="list_id"
listNamespaceType="single"
listType="detection"
ruleName="Test rule"
onChange={jest.fn()}
/>
</EuiThemeProvider>
);
expect(
wrapper.find('[data-test-subj="operatorAutocompleteComboBox"]').at(0).prop('options')
).not.toEqual(expect.arrayContaining([{ label: 'is in list' }, { label: 'is not in list' }]));
});
test('it displays "or", "and" and "add nested button" enabled', () => {
wrapper = mount(
<EuiThemeProvider>