Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Feb 2, 2021
1 parent 1570f33 commit c3549f0
Show file tree
Hide file tree
Showing 17 changed files with 234 additions and 389 deletions.
29 changes: 18 additions & 11 deletions x-pack/plugins/case/common/api/connectors/mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ import { ResilientFieldsRT } from './resilient';
import { ServiceNowITSMFieldsRT } from './servicenow_itsm';
import { JiraFieldsRT } from './jira';
import { ServiceNowSIRFieldsRT } from './servicenow_sir';

// Formerly imported from security_solution
export interface ElasticUser {
readonly email?: string | null;
readonly fullName?: string | null;
readonly username?: string | null;
}
import { CaseResponse } from '../cases';

export {
JiraPushToServiceApiParams,
Expand Down Expand Up @@ -79,21 +73,34 @@ const ConnectorFieldRt = rt.type({
required: rt.boolean,
type: FieldTypeRT,
});

export type ConnectorField = rt.TypeOf<typeof ConnectorFieldRt>;
export const ConnectorRequestParamsRt = rt.type({
connector_id: rt.string,
});

export const GetFieldsRequestQueryRt = rt.type({
connector_type: rt.string,
});

const GetFieldsResponseRt = rt.type({
defaultMappings: rt.array(ConnectorMappingsAttributesRT),
fields: rt.array(ConnectorFieldRt),
});

export type GetFieldsResponse = rt.TypeOf<typeof GetFieldsResponseRt>;

export type ExternalServiceParams = Record<string, unknown>;

export interface BasicParams {
title: CaseResponse['title'];
description: CaseResponse['description'];
createdAt: CaseResponse['created_at'];
createdBy: CaseResponse['created_by'];
updatedAt: CaseResponse['updated_at'];
updatedBy: CaseResponse['updated_by'];
}

export interface PipedField {
actionType: string;
key: string;
Expand All @@ -106,10 +113,10 @@ export interface PrepareFieldsForTransformArgs {
params: { title: string; description: string };
}
export interface EntityInformation {
createdAt: string;
createdBy: ElasticUser;
updatedAt: string | null;
updatedBy: ElasticUser | null;
createdAt: CaseResponse['created_at'];
createdBy: CaseResponse['created_by'];
updatedAt: CaseResponse['updated_at'];
updatedBy: CaseResponse['updated_by'];
}
export interface TransformerArgs {
date?: string;
Expand Down
9 changes: 8 additions & 1 deletion x-pack/plugins/case/server/client/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ export type CaseClientMock = jest.Mocked<CaseClient>;
export const createCaseClientMock = (): CaseClientMock => ({
addComment: jest.fn(),
create: jest.fn(),
get: jest.fn(),
getAlerts: jest.fn(),
getFields: jest.fn(),
getMappings: jest.fn(),
getUserActions: jest.fn(),
update: jest.fn(),
updateAlertsStatus: jest.fn(),
});
Expand Down Expand Up @@ -66,7 +69,11 @@ export const createCaseClientWithMockSavedObjectsClient = async ({
getUserActions: jest.fn(),
};

const alertsService = { initialize: jest.fn(), updateAlertsStatus: jest.fn() };
const alertsService = {
initialize: jest.fn(),
updateAlertsStatus: jest.fn(),
getAlerts: jest.fn(),
};

const context = {
core: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
} from '../../../../common/api';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { FindActionResult } from '../../../../../actions/server/types';
import { params } from '../cases/configure/mock';

export const newCase: CasePostRequest = {
title: 'My new case',
Expand Down Expand Up @@ -128,8 +127,7 @@ export const newConfiguration: CasesConfigureRequest = {
};

export const newPostPushRequest: PostPushRequest = {
params: params[ConnectorTypes.jira],
connector_type: ConnectorTypes.jira,
case_id: '123',
};

export const executePushResponse = {
Expand Down
80 changes: 32 additions & 48 deletions x-pack/plugins/case/server/routes/api/cases/configure/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,68 +4,52 @@
* you may not use this file except in compliance with the Elastic License.
*/
import {
ServiceConnectorCaseParams,
ServiceConnectorCommentParams,
BasicParams,
CommentResponse,
CommentType,
ConnectorMappingsAttributes,
ConnectorTypes,
} from '../../../../../common/api/connectors';
} from '../../../../../common/api';

export const updateUser = {
updatedAt: '2020-03-13T08:34:53.450Z',
updatedBy: { fullName: 'Another User', username: 'another' },
updatedBy: { full_name: 'Another User', username: 'another' },
};

const entity = {
createdAt: '2020-03-13T08:34:53.450Z',
createdBy: { fullName: 'Elastic User', username: 'elastic' },
createdBy: { full_name: 'Elastic User', username: 'elastic', email: 'elastic@elastic.co' },
updatedAt: null,
updatedBy: null,
};
export const comment: ServiceConnectorCommentParams = {
comment: 'first comment',
commentId: 'b5b4c4d0-574e-11ea-9e2e-21b90f8a9631',
...entity,

export const comment: CommentResponse = {
id: 'mock-comment-1',
comment: 'Wow, good luck catching that bad meanie!',
type: CommentType.user as const,
created_at: '2019-11-25T21:55:00.177Z',
created_by: {
full_name: 'elastic',
email: 'testemail@elastic.co',
username: 'elastic',
},
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 defaultPipes = ['informationCreated'];
const basicParams = {
comments: [comment],
export const basicParams: BasicParams = {
description: 'a description',
title: 'a title',
savedObjectId: '1231231231232',
externalId: null,
};
export const params = {
[ConnectorTypes.jira]: {
...basicParams,
issueType: '10003',
priority: 'Highest',
parent: '5002',
...entity,
} as ServiceConnectorCaseParams,
[ConnectorTypes.resilient]: {
...basicParams,
incidentTypes: ['10003'],
severityCode: '1',
...entity,
} as ServiceConnectorCaseParams,
[ConnectorTypes.serviceNowITSM]: {
...basicParams,
impact: '3',
severity: '1',
urgency: '2',
...entity,
} as ServiceConnectorCaseParams,
[ConnectorTypes.serviceNowSIR]: {
...basicParams,
category: 'Denial of Service',
destIp: '192.68.1.1',
sourceIp: '192.68.1.2',
malwareHash: '098f6bcd4621d373cade4e832627b4f6',
malwareUrl: 'https://attack.com',
priority: '1',
subcategory: '20',
...entity,
} as ServiceConnectorCaseParams,
[ConnectorTypes.none]: {},
...entity,
};

export const mappings: ConnectorMappingsAttributes[] = [
{
source: 'title',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ import { CASE_CONFIGURE_PUSH_URL } from '../../../../../common/constants';
import {
ActionConnector,
ConnectorRequestParamsRt,
CommentResponseAlertsType,
PostPushRequestRt,
throwErrors,
CommentType,
} from '../../../../../common/api';
import { createIncident } from './utils';
import { createIncident, isCommentAlertType } from './utils';

export function initPostPushToService({ router }: RouteDeps) {
router.post(
Expand Down Expand Up @@ -58,10 +56,7 @@ export function initPostPushToService({ router }: RouteDeps) {
const theCase = await caseClient.get({ id: body.case_id, includeComments: true });
const userActions = await caseClient.getUserActions({ caseId: body.case_id });
const alerts = await caseClient.getAlerts({
ids:
theCase.comments
?.filter<CommentResponseAlertsType>((comment) => comment.type === CommentType.alert)
.map((comment) => comment.alertId) ?? [],
ids: theCase.comments?.filter(isCommentAlertType).map((comment) => comment.alertId) ?? [],
});

const connectorMappings = await caseClient.getMappings({
Expand Down
Loading

0 comments on commit c3549f0

Please sign in to comment.