Skip to content

Commit

Permalink
Use mock event generator in tests, add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kqualters-elastic committed Feb 28, 2020
1 parent d291a46 commit bcda2d5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
AlertsAPIQueryParams,
CreateStructuredSelector,
} from '../../types';
import { Immutable, LegacyEndpointEvent, AlertEvent } from '../../../../../common/types';
import { Immutable, LegacyEndpointEvent } from '../../../../../common/types';

const createStructuredSelector: CreateStructuredSelector = createStructuredSelectorWithBadType;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class ResolverEmbeddableFactory extends EmbeddableFactory {
return true;
}

public async create(initialInput: EmbeddableInput, parent: IContainer) {
public async create(initialInput: EmbeddableInput, parent?: IContainer) {
return new ResolverEmbeddable(initialInput, {}, parent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,22 @@ interface UserBroughtProcessIntoView {
};
}

/**
* Used when the alert list selects an alert and the flyout shows resolver.
*/
interface UserChangedSelectedEvent {
readonly type: 'userChangedSelectedEvent';
readonly payload: {
/**
* Optional because they could have unselected the event.
*/
selectedEvent?: LegacyEndpointEvent;
};
}

/**
* Triggered by middleware when the data for resolver needs to be loaded. Used to set state in redux to 'loading'.
*/
interface AppRequestedResolverData {
readonly type: 'appRequestedResolverData';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { useEffect } from 'react';
import React, { useLayoutEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import styled from 'styled-components';
import { EuiLoadingSpinner } from '@elastic/eui';
Expand Down Expand Up @@ -49,7 +49,7 @@ export const Resolver = styled(
const { projectionMatrix, ref, onMouseDown } = useCamera();
const isLoading = useSelector(selectors.isLoading);

useEffect(() => {
useLayoutEffect(() => {
dispatch({
type: 'userChangedSelectedEvent',
payload: { selectedEvent },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { LegacyEndpointEvent } from '../../../../common/types';
import { SideEffectContext } from './side_effect_context';
import { applyMatrix3 } from '../lib/vector2';
import { sideEffectSimulator } from './side_effect_simulator';
import { mockProcessEvent } from '../models/process_event_test_helpers';

describe('useCamera on an unpainted element', () => {
let element: HTMLElement;
Expand Down Expand Up @@ -134,104 +135,28 @@ describe('useCamera on an unpainted element', () => {
describe('when the camera begins animation', () => {
let process: LegacyEndpointEvent;
beforeEach(() => {
const events: LegacyEndpointEvent[] = [];
const numberOfEvents: number = Math.floor(Math.random() * 10 + 1);

for (let index = 0; index < numberOfEvents; index++) {
const uniquePpid = index === 0 ? undefined : index - 1;
events.push(
mockProcessEvent({
endgame: {
unique_pid: index,
unique_ppid: uniquePpid,
event_type_full: 'process_event',
event_subtype_full: 'creation_event',
},
})
);
}
const serverResponseAction: ResolverAction = {
type: 'serverReturnedResolverData',
payload: {
data: {
result: {
search_results: [
{
'@timestamp': 1582233383000,
agent: {
id: '5f78bf8f-ddee-4890-ad61-6b5182309639',
type: 'endgame',
version: '3.53.9',
},
endgame: {
event_subtype_full: 'creation_event',
event_type_full: 'process_event',
pid: 6508,
ppid: 3828,
process_name: 'mimikatz.exe',
process_path: 'C:\\Users\\zeus\\Desktop\\mimikatz.exe',
serial_event_id: 3096,
timestamp_utc: '2020-02-20 21:16:23Z',
unique_pid: 3096,
unique_ppid: 2732,
},
process: {
args: ['C:\\Users\\zeus\\Desktop\\mimikatz.exe'],
executable: 'C:\\Users\\zeus\\Desktop\\mimikatz.exe',
hash: {
md5: '9cd25cee26f115876f1592dcc63cc650',
sha1: '40963139cc017a296cb9826c88749099ffdf413e',
sha256: 'ece23612029589623e0ae27da942440a9b0a9cd4f9681ec866613e64a247969d',
},
name: 'mimikatz.exe',
parent: {
executable:
'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe',
name: 'powershell.exe',
pid: 3828,
},
pid: 6508,
ppid: 3828,
thread: {},
},
rule: {},
user: {
domain: 'DESKTOP-QBBSCUT',
group: {},
id: 'S-1-5-21-4215045029-3277270250-148079304-1004',
name: 'zeus',
},
},
{
'@timestamp': 1582233383000,
agent: {
id: '5f78bf8f-ddee-4890-ad61-6b5182309639',
type: 'endgame',
version: '3.53.9',
},
endgame: {
event_subtype_full: 'creation_event',
event_type_full: 'process_event',
pid: 6509,
ppid: 6508,
process_name: 'mimikatz.exe',
process_path: 'C:\\Users\\zeus\\Desktop\\mimikatz.exe',
serial_event_id: 3097,
timestamp_utc: '2020-02-20 21:16:23Z',
unique_pid: 3097,
unique_ppid: 3096,
},
process: {
args: ['C:\\Users\\zeus\\Desktop\\mimikatz.exe'],
executable: 'C:\\Users\\zeus\\Desktop\\mimikatz.exe',
hash: {
md5: '9cd25cee26f115876f1592dcc63cc650',
sha1: '40963139cc017a296cb9826c88749099ffdf413e',
sha256: 'ece23612029589623e0ae27da942440a9b0a9cd4f9681ec866613e64a247969d',
},
name: 'mimikatz.exe',
parent: {
executable: 'C:\\test.exe',
name: 'powershell.exe',
pid: 3828,
},
pid: 6509,
ppid: 6508,
thread: {},
},
rule: {},
user: {
domain: 'DESKTOP-QBBSCUT',
group: {},
id: 'S-1-5-21-4215045029-3277270250-148079304-1004',
name: 'zeus',
},
},
],
search_results: events,
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/endpoint/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ export interface EndpointPluginSetupDependencies {

export interface EndpointPluginStartDependencies {} // eslint-disable-line @typescript-eslint/no-empty-interface

/**
* Functionality that the endpoint plugin uses from core.
*/
export interface EndpointPluginServices extends Partial<CoreStart> {
http: CoreStart['http'];
overlays: CoreStart['overlays'] | undefined;
Expand Down

0 comments on commit bcda2d5

Please sign in to comment.