Skip to content

Commit

Permalink
[SIEM] Additional Endgame Row Renderer Code Coverage (elastic#48722) (e…
Browse files Browse the repository at this point in the history
…lastic#48931)

## [SIEM] Additional Endgame Row Renderer Code Coverage

Adds additional unit test coverage for the [Endgame row renderers](elastic#48277)

### Endgame Event Types / Subtypes

Additional unit tests were added for the following Endgame event types / subtypes:

* DNS (`dns_event`)
  - [X] `request_event`
* File (FIM) (`file_event`)
  - [X] `file_create_event`
  - [X] `file_delete_event`
* Network (`network_event`)
  - [X] `ipv4_connection_accept_event`
  - [X] `ipv6_connection_accept_event`
  - [X] `ipv4_disconnect_received_event`
  - [X] `ipv6_disconnect_received_event`
* Security (Authentication) (`security_event`)
  - [X] `user_logon`
  - [X] `admin_logon`
  - [X] `explicit_user_logon`
  - [X] `user_logoff`
* Process (`process_event`)
  - [X] `creation_event`
  - [X] `termination_event`

### Non-Endgame Events

Additional unit tests for some non-Endgame events were also added, including:

* FIM file `created` events
* FIM file `deleted` events
* Socket `socket_opened` events
* Socket `socket_closed` events

elastic/ecs-dev#178
  • Loading branch information
andrew-goldstein authored Oct 22, 2019
1 parent caa7bcb commit 113bc2e
Show file tree
Hide file tree
Showing 17 changed files with 2,414 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import * as React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';

import { TestProviders } from '../../../../mock';

import { ExitCodeDraggable } from './exit_code_draggable';

describe('ExitCodeDraggable', () => {
test('it renders the expected text and exit code, when both text and an endgameExitCode are provided', () => {
const wrapper = mountWithIntl(
<TestProviders>
<ExitCodeDraggable contextId="test" endgameExitCode="0" eventId="1" text="with exit code" />
</TestProviders>
);
expect(wrapper.text()).toEqual('with exit code0');
});

test('it returns an empty string when text is provided, but endgameExitCode is undefined', () => {
const wrapper = mountWithIntl(
<TestProviders>
<ExitCodeDraggable
contextId="test"
endgameExitCode={undefined}
eventId="1"
text="with exit code"
/>
</TestProviders>
);
expect(wrapper.text()).toEqual('');
});

test('it returns an empty string when text is provided, but endgameExitCode is null', () => {
const wrapper = mountWithIntl(
<TestProviders>
<ExitCodeDraggable
contextId="test"
endgameExitCode={null}
eventId="1"
text="with exit code"
/>
</TestProviders>
);
expect(wrapper.text()).toEqual('');
});

test('it returns an empty string when text is provided, but endgameExitCode is an empty string', () => {
const wrapper = mountWithIntl(
<TestProviders>
<ExitCodeDraggable contextId="test" endgameExitCode="" eventId="1" text="with exit code" />
</TestProviders>
);
expect(wrapper.text()).toEqual('');
});

test('it renders just the exit code when text is undefined', () => {
const wrapper = mountWithIntl(
<TestProviders>
<ExitCodeDraggable contextId="test" endgameExitCode="1" eventId="1" text={undefined} />
</TestProviders>
);
expect(wrapper.text()).toEqual('1');
});

test('it renders just the exit code when text is null', () => {
const wrapper = mountWithIntl(
<TestProviders>
<ExitCodeDraggable contextId="test" endgameExitCode="1" eventId="1" text={null} />
</TestProviders>
);
expect(wrapper.text()).toEqual('1');
});

test('it renders just the exit code when text is an empty string', () => {
const wrapper = mountWithIntl(
<TestProviders>
<ExitCodeDraggable contextId="test" endgameExitCode="1" eventId="1" text="" />
</TestProviders>
);
expect(wrapper.text()).toEqual('1');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import * as React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';

import { TestProviders } from '../../../../mock';

import { FileDraggable } from './file_draggable';

describe('FileDraggable', () => {
test('it prefers fileName and filePath over endgameFileName and endgameFilePath when all of them are provided', () => {
const wrapper = mountWithIntl(
<TestProviders>
<FileDraggable
contextId="test"
endgameFileName="[endgameFileName]"
endgameFilePath="[endgameFilePath]"
eventId="1"
fileName="[fileName]"
filePath="[filePath]"
></FileDraggable>
</TestProviders>
);
expect(wrapper.text()).toEqual('[fileName]in[filePath]');
});

test('it returns an empty string when none of the files or paths are provided', () => {
const wrapper = mountWithIntl(
<TestProviders>
<FileDraggable
contextId="test"
endgameFileName={undefined}
endgameFilePath={undefined}
eventId="1"
fileName={undefined}
filePath={undefined}
></FileDraggable>
</TestProviders>
);
expect(wrapper.text()).toEqual('');
});

test('it renders just the endgameFileName if only endgameFileName is provided', () => {
const wrapper = mountWithIntl(
<TestProviders>
<FileDraggable
contextId="test"
endgameFileName="[endgameFileName]"
endgameFilePath={undefined}
eventId="1"
fileName={undefined}
filePath={undefined}
/>
</TestProviders>
);
expect(wrapper.text()).toEqual('[endgameFileName]');
});

test('it renders "in endgameFilePath" if only endgameFilePath is provided', () => {
const wrapper = mountWithIntl(
<TestProviders>
<FileDraggable
contextId="test"
endgameFileName={undefined}
endgameFilePath="[endgameFilePath]"
eventId="1"
fileName={undefined}
filePath={undefined}
/>
</TestProviders>
);
expect(wrapper.text()).toEqual('in[endgameFilePath]');
});

test('it renders just the filename if only fileName is provided', () => {
const wrapper = mountWithIntl(
<TestProviders>
<FileDraggable
contextId="test"
endgameFileName={undefined}
endgameFilePath={undefined}
eventId="1"
fileName="[fileName]"
filePath={undefined}
/>
</TestProviders>
);
expect(wrapper.text()).toEqual('[fileName]');
});

test('it renders "in filePath" if only filePath is provided', () => {
const wrapper = mountWithIntl(
<TestProviders>
<FileDraggable
contextId="test"
endgameFileName={undefined}
endgameFilePath={undefined}
eventId="1"
fileName={undefined}
filePath="[filePath]"
/>
</TestProviders>
);
expect(wrapper.text()).toEqual('in[filePath]');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export const FileDraggable = React.memo<Props>(
return null;
}

const fileNameIsKnown =
!isNillEmptyOrNotFinite(fileName) || !isNillEmptyOrNotFinite(endgameFileName);
const filePathIsKnown =
!isNillEmptyOrNotFinite(filePath) || !isNillEmptyOrNotFinite(endgameFilePath);

return (
<>
Expand All @@ -58,7 +58,7 @@ export const FileDraggable = React.memo<Props>(
</TokensFlexItem>
) : null}

{fileNameIsKnown && (
{filePathIsKnown && (
<TokensFlexItem data-test-subj="in" grow={false} component="span">
{i18n.IN}
</TokensFlexItem>
Expand Down
Loading

0 comments on commit 113bc2e

Please sign in to comment.