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

[7.x] [Ingest pipelines] add community id processor (#103863) #106376

Merged
merged 3 commits into from
Jul 21, 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
@@ -0,0 +1,109 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { act } from 'react-dom/test-utils';
import { setup, SetupResult, getProcessorValue } from './processor.helpers';

const COMMUNITY_ID_TYPE = 'community_id';

describe('Processor: Community id', () => {
let onUpdate: jest.Mock;
let testBed: SetupResult;

beforeAll(() => {
jest.useFakeTimers();
});

afterAll(() => {
jest.useRealTimers();
});

beforeEach(async () => {
onUpdate = jest.fn();

await act(async () => {
testBed = await setup({
value: {
processors: [],
},
onFlyoutOpen: jest.fn(),
onUpdate,
});
});

testBed.component.update();

// Open flyout to add new processor
testBed.actions.addProcessor();
// Add type (the other fields are not visible until a type is selected)
await testBed.actions.addProcessorType(COMMUNITY_ID_TYPE);
});

test('can submit if no fields are filled', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;

// Click submit button with no fields filled
await saveNewProcessor();

// Expect no form errors
expect(form.getErrorsMessages()).toHaveLength(0);
});

test('allows to set either iana_number or transport', async () => {
const { find, form } = testBed;

expect(find('ianaField.input').exists()).toBe(true);
expect(find('transportField.input').exists()).toBe(true);

form.setInputValue('ianaField.input', 'iana_number');
expect(find('transportField.input').props().disabled).toBe(true);

form.setInputValue('ianaField.input', '');
form.setInputValue('transportField.input', 'transport');
expect(find('ianaField.input').props().disabled).toBe(true);
});

test('allows optional parameters to be set', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;

form.toggleEuiSwitch('ignoreMissingSwitch.input');
form.toggleEuiSwitch('ignoreFailureSwitch.input');
form.setInputValue('sourceIpField.input', 'source.ip');
form.setInputValue('sourcePortField.input', 'source.port');
form.setInputValue('targetField.input', 'target_field');
form.setInputValue('destinationIpField.input', 'destination.ip');
form.setInputValue('destinationPortField.input', 'destination.port');
form.setInputValue('icmpTypeField.input', 'icmp_type');
form.setInputValue('icmpCodeField.input', 'icmp_code');
form.setInputValue('ianaField.input', 'iana');
form.setInputValue('seedField.input', '10');

// Save the field with new changes
await saveNewProcessor();

const processors = getProcessorValue(onUpdate, COMMUNITY_ID_TYPE);
expect(processors[0][COMMUNITY_ID_TYPE]).toEqual({
ignore_failure: true,
ignore_missing: false,
target_field: 'target_field',
source_ip: 'source.ip',
source_port: 'source.port',
destination_ip: 'destination.ip',
destination_port: 'destination.port',
icmp_type: 'icmp_type',
icmp_code: 'icmp_code',
iana_number: 'iana',
seed: 10,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,13 @@ type TestSubject =
| 'fieldsValueField.input'
| 'saltValueField.input'
| 'methodsValueField'
| 'sourceIpField.input'
| 'sourcePortField.input'
| 'destinationIpField.input'
| 'destinationPortField.input'
| 'icmpTypeField.input'
| 'icmpCodeField.input'
| 'ianaField.input'
| 'transportField.input'
| 'seedField.input'
| 'trimSwitch.input';
Loading