Skip to content

Commit

Permalink
Merge branch 'master' into fix-repo-root-finding-for-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jul 12, 2021
2 parents d8d1284 + 0e83e99 commit 5e214ec
Show file tree
Hide file tree
Showing 25 changed files with 495 additions and 35 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/project-assigner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ jobs:
name: Assign issue or PR to project based on label
steps:
- name: Assign to project
uses: elastic/github-actions/project-assigner@v2.0.0
uses: elastic/github-actions/project-assigner@v2.1.0
id: project_assigner
with:
issue-mappings: '[{"label": "Feature:Lens", "projectNumber": 32, "columnName": "Long-term goals"}, {"label": "Feature:Canvas", "projectNumber": 38, "columnName": "Inbox"}, {"label": "Feature:Dashboard", "projectNumber": 68, "columnName": "Inbox"}, {"label": "Feature:Drilldowns", "projectNumber": 68, "columnName": "Inbox"}, {"label": "Feature:Input Controls", "projectNumber": 72, "columnName": "Inbox"}]'
issue-mappings: |
[
{"label": "Feature:Lens", "projectNumber": 32, "columnName": "Long-term goals"},
{"label": "Feature:Canvas", "projectNumber": 38, "columnName": "Inbox"},
{"label": "Feature:Dashboard", "projectNumber": 68, "columnName": "Inbox"},
{"label": "Feature:Drilldowns", "projectNumber": 68, "columnName": "Inbox"},
{"label": "Feature:Input Controls", "projectNumber": 72, "columnName": "Inbox"},
{"label": "Team:Security", "projectNumber": 320, "columnName": "Awaiting triage", "projectScope": "org"}
]
ghToken: ${{ secrets.PROJECT_ASSIGNER_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ import routeData from 'react-router';

import { getFormMock, useFormMock, useFormDataMock } from '../__mock__/form';
import { useUpdateComment } from '../../containers/use_update_comment';
import { basicCase, basicPush, getUserAction } from '../../containers/mock';
import {
basicCase,
basicPush,
getUserAction,
getHostIsolationUserAction,
hostIsolationComment,
hostReleaseComment,
} from '../../containers/mock';
import { UserActionTree } from '.';
import { TestProviders } from '../../common/mock';
import { Ecs } from '../../../common';
Expand Down Expand Up @@ -368,4 +375,82 @@ describe(`UserActionTree`, () => {
).toEqual(true);
});
});
describe('Host isolation action', () => {
it('renders in the cases details view', async () => {
const isolateAction = [getHostIsolationUserAction()];
const props = {
...defaultProps,
caseUserActions: isolateAction,
data: { ...defaultProps.data, comments: [...basicCase.comments, hostIsolationComment()] },
};

const wrapper = mount(
<TestProviders>
<UserActionTree {...props} />
</TestProviders>
);
await waitFor(() => {
expect(wrapper.find(`[data-test-subj="endpoint-action"]`).exists()).toBe(true);
});
});

it('shows the correct username', async () => {
const isolateAction = [getHostIsolationUserAction()];
const props = {
...defaultProps,
caseUserActions: isolateAction,
data: { ...defaultProps.data, comments: [hostIsolationComment()] },
};

const wrapper = mount(
<TestProviders>
<UserActionTree {...props} />
</TestProviders>
);
await waitFor(() => {
expect(wrapper.find(`[data-test-subj="user-action-avatar"]`).first().prop('name')).toEqual(
defaultProps.data.createdBy.fullName
);
});
});

it('shows a lock icon if the action is isolate', async () => {
const isolateAction = [getHostIsolationUserAction()];
const props = {
...defaultProps,
caseUserActions: isolateAction,
data: { ...defaultProps.data, comments: [hostIsolationComment()] },
};

const wrapper = mount(
<TestProviders>
<UserActionTree {...props} />
</TestProviders>
);
await waitFor(() => {
expect(
wrapper.find(`[data-test-subj="endpoint-action"]`).first().prop('timelineIcon')
).toBe('lock');
});
});
it('shows a lockOpen icon if the action is unisolate/release', async () => {
const isolateAction = [getHostIsolationUserAction()];
const props = {
...defaultProps,
caseUserActions: isolateAction,
data: { ...defaultProps.data, comments: [hostReleaseComment()] },
};

const wrapper = mount(
<TestProviders>
<UserActionTree {...props} />
</TestProviders>
);
await waitFor(() => {
expect(
wrapper.find(`[data-test-subj="endpoint-action"]`).first().prop('timelineIcon')
).toBe('lockOpen');
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 React from 'react';
import { mount } from 'enzyme';
import { HostIsolationCommentEvent } from './user_action_host_isolation_comment_event';

const defaultProps = () => {
return {
type: 'isolate',
endpoints: [{ endpointId: 'e1', hostname: 'host1' }],
href: jest.fn(),
onClick: jest.fn(),
};
};

describe('UserActionHostIsolationCommentEvent', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('renders with the correct action and hostname', async () => {
const wrapper = mount(<HostIsolationCommentEvent {...defaultProps()} />);
expect(wrapper.find(`[data-test-subj="actions-link-e1"]`).first().exists()).toBeTruthy();
expect(wrapper.text()).toBe('isolated host host1');
});

it('navigates to app on link click', async () => {
const onActionsLinkClick = jest.fn();

const wrapper = mount(
<HostIsolationCommentEvent {...defaultProps()} onClick={onActionsLinkClick} />
);

wrapper.find(`[data-test-subj="actions-link-e1"]`).first().simulate('click');
expect(onActionsLinkClick).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const HostIsolationCommentEventComponent: React.FC<Props> = ({
<LinkAnchor
onClick={onLinkClick}
href={endpointDetailsHref}
data-test-subj={`endpointDetails-activity-log-link-${endpoints[0].endpointId}`}
data-test-subj={`actions-link-${endpoints[0].endpointId}`}
>
{endpoints[0].hostname}
</LinkAnchor>
Expand Down
61 changes: 61 additions & 0 deletions x-pack/plugins/cases/public/containers/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,58 @@ export const alertComment: Comment = {
version: 'WzQ3LDFc',
};

export const hostIsolationComment: () => Comment = () => {
return {
type: CommentType.actions,
comment: 'I just isolated the host!',
id: 'isolate-comment-id',
actions: {
targets: [
{
hostname: 'host1',
endpointId: '001',
},
],
type: 'isolate',
},
associationType: AssociationType.case,
createdAt: basicCreatedAt,
createdBy: elasticUser,
owner: SECURITY_SOLUTION_OWNER,
pushedAt: null,
pushedBy: null,
updatedAt: null,
updatedBy: null,
version: 'WzQ3LDFc',
};
};

export const hostReleaseComment: () => Comment = () => {
return {
type: CommentType.actions,
comment: 'I just released the host!',
id: 'isolate-comment-id',
actions: {
targets: [
{
hostname: 'host1',
endpointId: '001',
},
],
type: 'unisolate',
},
associationType: AssociationType.case,
createdAt: basicCreatedAt,
createdBy: elasticUser,
owner: SECURITY_SOLUTION_OWNER,
pushedAt: null,
pushedBy: null,
updatedAt: null,
updatedBy: null,
version: 'WzQ3LDFc',
};
};

export const basicCase: Case = {
type: CaseType.individual,
owner: SECURITY_SOLUTION_OWNER,
Expand Down Expand Up @@ -374,6 +426,15 @@ export const getAlertUserAction = () => ({
newValue: '{"type":"alert","alertId":"alert-id-1","index":"index-id-1"}',
});

export const getHostIsolationUserAction = () => ({
...basicAction,
actionId: 'isolate-action-id',
actionField: ['comment'] as UserActionField,
action: 'create' as UserAction,
commentId: 'isolate-comment-id',
newValue: 'some value',
});

export const caseUserActions: CaseUserActions[] = [
getUserAction(['description'], 'create'),
getUserAction(['comment'], 'create'),
Expand Down
100 changes: 100 additions & 0 deletions x-pack/plugins/cases/server/client/cases/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,106 @@ export const comment: CommentResponse = {
version: 'WzEsMV0=',
};

export const isolateCommentActions: CommentResponse = {
associationType: AssociationType.case,
id: 'mock-action-comment-1',
comment: 'Isolating this for investigation',
type: CommentType.actions as const,
created_at: '2019-11-25T21:55:00.177Z',
actions: {
targets: [
{
endpointId: '123',
hostname: 'windows-host-1',
},
],
type: 'isolate',
},
created_by: {
full_name: 'elastic',
email: 'testemail@elastic.co',
username: 'elastic',
},
owner: SECURITY_SOLUTION_OWNER,
pushed_at: null,
pushed_by: null,
updated_at: '2019-11-25T21:55:00.177Z',
updated_by: {
full_name: 'elastic',
email: 'testemail@elastic.co',
username: 'elastic',
},
version: 'WzEsMV0=',
};

export const releaseCommentActions: CommentResponse = {
associationType: AssociationType.case,
id: 'mock-action-comment-1',
comment: 'Releasing this for investigation',
type: CommentType.actions as const,
created_at: '2019-11-25T21:55:00.177Z',
actions: {
targets: [
{
endpointId: '123',
hostname: 'windows-host-1',
},
],
type: 'unisolate',
},
created_by: {
full_name: 'elastic',
email: 'testemail@elastic.co',
username: 'elastic',
},
owner: SECURITY_SOLUTION_OWNER,
pushed_at: null,
pushed_by: null,
updated_at: '2019-11-25T21:55:00.177Z',
updated_by: {
full_name: 'elastic',
email: 'testemail@elastic.co',
username: 'elastic',
},
version: 'WzEsMV0=',
};

export const isolateCommentActionsMultipleTargets: CommentResponse = {
associationType: AssociationType.case,
id: 'mock-action-comment-1',
comment: 'Isolating this for investigation',
type: CommentType.actions as const,
created_at: '2019-11-25T21:55:00.177Z',
actions: {
targets: [
{
endpointId: '123',
hostname: 'windows-host-1',
},
{
endpointId: '456',
hostname: 'windows-host-2',
},
],
type: 'isolate',
},
created_by: {
full_name: 'elastic',
email: 'testemail@elastic.co',
username: 'elastic',
},
owner: SECURITY_SOLUTION_OWNER,
pushed_at: null,
pushed_by: null,
updated_at: '2019-11-25T21:55:00.177Z',
updated_by: {
full_name: 'elastic',
email: 'testemail@elastic.co',
username: 'elastic',
},
version: 'WzEsMV0=',
};

export const commentAlert: CommentResponse = {
associationType: AssociationType.case,
id: 'mock-comment-1',
Expand Down
Loading

0 comments on commit 5e214ec

Please sign in to comment.