[SIEM][CASE] Server common constants (#63952)

This commit is contained in:
Christos Nasikas 2020-04-21 15:09:42 +03:00 committed by GitHub
parent 3b1d0e0c6b
commit 698717173d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 207 additions and 106 deletions

View file

@ -5,6 +5,9 @@
*/
import { KibanaServices } from '../../lib/kibana';
import { CASES_URL } from '../../../../../../plugins/case/common/constants';
import {
deleteCases,
getActionLicense,
@ -22,6 +25,7 @@ import {
pushCase,
pushToService,
} from './api';
import {
actionLicenses,
allCases,
@ -44,7 +48,7 @@ import {
caseUserActionsSnake,
casesStatusSnake,
} from './mock';
import { CASES_URL } from './constants';
import { DEFAULT_FILTER_OPTIONS, DEFAULT_QUERY_PARAMS } from './use_get_cases';
import * as i18n from './translations';

View file

@ -20,6 +20,21 @@ import {
ActionTypeExecutorResult,
} from '../../../../../../plugins/case/common/api';
import {
CASE_STATUS_URL,
CASES_URL,
CASE_TAGS_URL,
CASE_REPORTERS_URL,
ACTION_TYPES_URL,
ACTION_URL,
} from '../../../../../../plugins/case/common/constants';
import {
getCaseDetailsUrl,
getCaseUserActionUrl,
getCaseCommentsUrl,
} from '../../../../../../plugins/case/common/api/helpers';
import { KibanaServices } from '../../lib/kibana';
import {
@ -33,8 +48,6 @@ import {
CaseUserActions,
} from './types';
import { CASES_URL } from './constants';
import {
convertToCamelCase,
convertAllCasesToCamel,
@ -54,7 +67,7 @@ export const getCase = async (
includeComments: boolean = true,
signal: AbortSignal
): Promise<Case> => {
const response = await KibanaServices.get().http.fetch<CaseResponse>(`${CASES_URL}/${caseId}`, {
const response = await KibanaServices.get().http.fetch<CaseResponse>(getCaseDetailsUrl(caseId), {
method: 'GET',
query: {
includeComments,
@ -65,18 +78,15 @@ export const getCase = async (
};
export const getCasesStatus = async (signal: AbortSignal): Promise<CasesStatus> => {
const response = await KibanaServices.get().http.fetch<CasesStatusResponse>(
`${CASES_URL}/status`,
{
method: 'GET',
signal,
}
);
const response = await KibanaServices.get().http.fetch<CasesStatusResponse>(CASE_STATUS_URL, {
method: 'GET',
signal,
});
return convertToCamelCase<CasesStatusResponse, CasesStatus>(decodeCasesStatusResponse(response));
};
export const getTags = async (signal: AbortSignal): Promise<string[]> => {
const response = await KibanaServices.get().http.fetch<string[]>(`${CASES_URL}/tags`, {
const response = await KibanaServices.get().http.fetch<string[]>(CASE_TAGS_URL, {
method: 'GET',
signal,
});
@ -84,7 +94,7 @@ export const getTags = async (signal: AbortSignal): Promise<string[]> => {
};
export const getReporters = async (signal: AbortSignal): Promise<User[]> => {
const response = await KibanaServices.get().http.fetch<User[]>(`${CASES_URL}/reporters`, {
const response = await KibanaServices.get().http.fetch<User[]>(CASE_REPORTERS_URL, {
method: 'GET',
signal,
});
@ -96,7 +106,7 @@ export const getCaseUserActions = async (
signal: AbortSignal
): Promise<CaseUserActions[]> => {
const response = await KibanaServices.get().http.fetch<CaseUserActionsResponse>(
`${CASES_URL}/${caseId}/user_actions`,
getCaseUserActionUrl(caseId),
{
method: 'GET',
signal,
@ -193,14 +203,11 @@ export const patchComment = async (
version: string,
signal: AbortSignal
): Promise<Case> => {
const response = await KibanaServices.get().http.fetch<CaseResponse>(
`${CASES_URL}/${caseId}/comments`,
{
method: 'PATCH',
body: JSON.stringify({ comment: commentUpdate, id: commentId, version }),
signal,
}
);
const response = await KibanaServices.get().http.fetch<CaseResponse>(getCaseCommentsUrl(caseId), {
method: 'PATCH',
body: JSON.stringify({ comment: commentUpdate, id: commentId, version }),
signal,
});
return convertToCamelCase<CaseResponse, Case>(decodeCaseResponse(response));
};
@ -219,7 +226,7 @@ export const pushCase = async (
signal: AbortSignal
): Promise<Case> => {
const response = await KibanaServices.get().http.fetch<CaseResponse>(
`${CASES_URL}/${caseId}/_push`,
`${getCaseDetailsUrl(caseId)}/_push`,
{
method: 'POST',
body: JSON.stringify(push),
@ -235,7 +242,7 @@ export const pushToService = async (
signal: AbortSignal
): Promise<ServiceConnectorCaseResponse> => {
const response = await KibanaServices.get().http.fetch<ActionTypeExecutorResult>(
`/api/action/${connectorId}/_execute`,
`${ACTION_URL}/${connectorId}/_execute`,
{
method: 'POST',
body: JSON.stringify({ params: casePushParams }),
@ -251,7 +258,7 @@ export const pushToService = async (
};
export const getActionLicense = async (signal: AbortSignal): Promise<ActionLicense[]> => {
const response = await KibanaServices.get().http.fetch<ActionLicense[]>(`/api/action/types`, {
const response = await KibanaServices.get().http.fetch<ActionLicense[]>(ACTION_TYPES_URL, {
method: 'GET',
signal,
});

View file

@ -13,26 +13,27 @@ import {
} from '../../../../../../../plugins/case/common/api';
import { KibanaServices } from '../../../lib/kibana';
import { CASES_CONFIGURE_URL } from '../constants';
import {
CASE_CONFIGURE_CONNECTORS_URL,
CASE_CONFIGURE_URL,
} from '../../../../../../../plugins/case/common/constants';
import { ApiProps } from '../types';
import { convertToCamelCase, decodeCaseConfigureResponse } from '../utils';
import { CaseConfigure } from './types';
export const fetchConnectors = async ({ signal }: ApiProps): Promise<Connector[]> => {
const response = await KibanaServices.get().http.fetch(
`${CASES_CONFIGURE_URL}/connectors/_find`,
{
method: 'GET',
signal,
}
);
const response = await KibanaServices.get().http.fetch(`${CASE_CONFIGURE_CONNECTORS_URL}/_find`, {
method: 'GET',
signal,
});
return response;
};
export const getCaseConfigure = async ({ signal }: ApiProps): Promise<CaseConfigure | null> => {
const response = await KibanaServices.get().http.fetch<CasesConfigureResponse>(
CASES_CONFIGURE_URL,
CASE_CONFIGURE_URL,
{
method: 'GET',
signal,
@ -51,7 +52,7 @@ export const postCaseConfigure = async (
signal: AbortSignal
): Promise<CaseConfigure> => {
const response = await KibanaServices.get().http.fetch<CasesConfigureResponse>(
CASES_CONFIGURE_URL,
CASE_CONFIGURE_URL,
{
method: 'POST',
body: JSON.stringify(caseConfiguration),
@ -68,7 +69,7 @@ export const patchCaseConfigure = async (
signal: AbortSignal
): Promise<CaseConfigure> => {
const response = await KibanaServices.get().http.fetch<CasesConfigureResponse>(
CASES_CONFIGURE_URL,
CASE_CONFIGURE_URL,
{
method: 'PATCH',
body: JSON.stringify(caseConfiguration),

View file

@ -4,7 +4,5 @@
* you may not use this file except in compliance with the Elastic License.
*/
export const CASES_URL = `/api/cases`;
export const CASES_CONFIGURE_URL = `/api/cases/configure`;
export const DEFAULT_TABLE_ACTIVE_PAGE = 1;
export const DEFAULT_TABLE_LIMIT = 5;

View file

@ -0,0 +1,28 @@
/*
* 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 {
CASE_DETAILS_URL,
CASE_COMMENTS_URL,
CASE_USER_ACTIONS_URL,
CASE_COMMENT_DETAILS_URL,
} from '../constants';
export const getCaseDetailsUrl = (id: string): string => {
return CASE_DETAILS_URL.replace('{case_id}', id);
};
export const getCaseCommentsUrl = (id: string): string => {
return CASE_COMMENTS_URL.replace('{case_id}', id);
};
export const getCaseCommentDetailsUrl = (caseId: string, commentId: string): string => {
return CASE_COMMENT_DETAILS_URL.replace('{case_id}', caseId).replace('{comment_id}', commentId);
};
export const getCaseUserActionUrl = (id: string): string => {
return CASE_USER_ACTIONS_URL.replace('{case_id}', id);
};

View file

@ -0,0 +1,29 @@
/*
* 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.
*/
export const APP_ID = 'case';
/**
* Case routes
*/
export const CASES_URL = '/api/cases';
export const CASE_DETAILS_URL = `${CASES_URL}/{case_id}`;
export const CASE_CONFIGURE_URL = `${CASES_URL}/configure`;
export const CASE_CONFIGURE_CONNECTORS_URL = `${CASE_CONFIGURE_URL}/connectors`;
export const CASE_COMMENTS_URL = `${CASE_DETAILS_URL}/comments`;
export const CASE_COMMENT_DETAILS_URL = `${CASE_DETAILS_URL}/comments/{comment_id}`;
export const CASE_REPORTERS_URL = `${CASES_URL}/reporters`;
export const CASE_STATUS_URL = `${CASES_URL}/status`;
export const CASE_TAGS_URL = `${CASES_URL}/tags`;
export const CASE_USER_ACTIONS_URL = `${CASE_DETAILS_URL}/user_actions`;
/**
* Action routes
*/
export const ACTION_URL = '/api/action';
export const ACTION_TYPES_URL = '/api/action/types';

View file

@ -9,11 +9,12 @@ import { schema } from '@kbn/config-schema';
import { buildCommentUserActionItem } from '../../../../services/user_actions/helpers';
import { RouteDeps } from '../../types';
import { wrapError } from '../../utils';
import { CASE_COMMENTS_URL } from '../../../../../common/constants';
export function initDeleteAllCommentsApi({ caseService, router, userActionService }: RouteDeps) {
router.delete(
{
path: '/api/cases/{case_id}/comments',
path: CASE_COMMENTS_URL,
validate: {
params: schema.object({
case_id: schema.string(),

View file

@ -15,6 +15,7 @@ import {
mockCaseComments,
} from '../../__fixtures__';
import { initDeleteCommentApi } from './delete_comment';
import { CASE_COMMENT_DETAILS_URL } from '../../../../../common/constants';
describe('DELETE comment', () => {
let routeHandler: RequestHandler<any, any, any>;
@ -23,7 +24,7 @@ describe('DELETE comment', () => {
});
it(`deletes the comment. responds with 204`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases/{case_id}/comments/{comment_id}',
path: CASE_COMMENT_DETAILS_URL,
method: 'delete',
params: {
case_id: 'mock-id-1',
@ -43,7 +44,7 @@ describe('DELETE comment', () => {
});
it(`returns an error when thrown from deleteComment service`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases/{case_id}/comments/{comment_id}',
path: CASE_COMMENT_DETAILS_URL,
method: 'delete',
params: {
case_id: 'mock-id-1',

View file

@ -11,11 +11,12 @@ import { CASE_SAVED_OBJECT } from '../../../../saved_object_types';
import { buildCommentUserActionItem } from '../../../../services/user_actions/helpers';
import { RouteDeps } from '../../types';
import { wrapError } from '../../utils';
import { CASE_COMMENT_DETAILS_URL } from '../../../../../common/constants';
export function initDeleteCommentApi({ caseService, router, userActionService }: RouteDeps) {
router.delete(
{
path: '/api/cases/{case_id}/comments/{comment_id}',
path: CASE_COMMENT_DETAILS_URL,
validate: {
params: schema.object({
case_id: schema.string(),

View file

@ -18,11 +18,12 @@ import {
} from '../../../../../common/api';
import { RouteDeps } from '../../types';
import { escapeHatch, transformComments, wrapError } from '../../utils';
import { CASE_COMMENTS_URL } from '../../../../../common/constants';
export function initFindCaseCommentsApi({ caseService, router }: RouteDeps) {
router.get(
{
path: '/api/cases/{case_id}/comments/_find',
path: `${CASE_COMMENTS_URL}/_find`,
validate: {
params: schema.object({
case_id: schema.string(),

View file

@ -9,11 +9,12 @@ import { schema } from '@kbn/config-schema';
import { AllCommentsResponseRt } from '../../../../../common/api';
import { RouteDeps } from '../../types';
import { flattenCommentSavedObjects, wrapError } from '../../utils';
import { CASE_COMMENTS_URL } from '../../../../../common/constants';
export function initGetAllCommentsApi({ caseService, router }: RouteDeps) {
router.get(
{
path: '/api/cases/{case_id}/comments',
path: CASE_COMMENTS_URL,
validate: {
params: schema.object({
case_id: schema.string(),

View file

@ -15,6 +15,7 @@ import {
} from '../../__fixtures__';
import { flattenCommentSavedObject } from '../../utils';
import { initGetCommentApi } from './get_comment';
import { CASE_COMMENT_DETAILS_URL } from '../../../../../common/constants';
describe('GET comment', () => {
let routeHandler: RequestHandler<any, any, any>;
@ -23,7 +24,7 @@ describe('GET comment', () => {
});
it(`returns the comment`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases/{case_id}/comments/{comment_id}',
path: CASE_COMMENT_DETAILS_URL,
method: 'get',
params: {
case_id: 'mock-id-1',
@ -48,7 +49,7 @@ describe('GET comment', () => {
});
it(`returns an error when getComment throws`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases/{case_id}/comments/{comment_id}',
path: CASE_COMMENT_DETAILS_URL,
method: 'get',
params: {
case_id: 'mock-id-1',

View file

@ -9,11 +9,12 @@ import { schema } from '@kbn/config-schema';
import { CommentResponseRt } from '../../../../../common/api';
import { RouteDeps } from '../../types';
import { flattenCommentSavedObject, wrapError } from '../../utils';
import { CASE_COMMENT_DETAILS_URL } from '../../../../../common/constants';
export function initGetCommentApi({ caseService, router }: RouteDeps) {
router.get(
{
path: '/api/cases/{case_id}/comments/{comment_id}',
path: CASE_COMMENT_DETAILS_URL,
validate: {
params: schema.object({
case_id: schema.string(),

View file

@ -14,6 +14,7 @@ import {
mockCases,
} from '../../__fixtures__';
import { initPatchCommentApi } from './patch_comment';
import { CASE_COMMENTS_URL } from '../../../../../common/constants';
describe('PATCH comment', () => {
let routeHandler: RequestHandler<any, any, any>;
@ -22,7 +23,7 @@ describe('PATCH comment', () => {
});
it(`Patch a comment`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases/{case_id}/comments',
path: CASE_COMMENTS_URL,
method: 'patch',
params: {
case_id: 'mock-id-1',
@ -50,7 +51,7 @@ describe('PATCH comment', () => {
it(`Fails with 409 if version does not match`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases/{case_id}/comments',
path: CASE_COMMENTS_URL,
method: 'patch',
params: {
case_id: 'mock-id-1',
@ -74,7 +75,7 @@ describe('PATCH comment', () => {
});
it(`Returns an error if updateComment throws`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases/{case_id}/comments',
path: CASE_COMMENTS_URL,
method: 'patch',
params: {
case_id: 'mock-id-1',

View file

@ -15,11 +15,12 @@ import { CASE_SAVED_OBJECT } from '../../../../saved_object_types';
import { buildCommentUserActionItem } from '../../../../services/user_actions/helpers';
import { RouteDeps } from '../../types';
import { escapeHatch, wrapError, flattenCaseSavedObject } from '../../utils';
import { CASE_COMMENTS_URL } from '../../../../../common/constants';
export function initPatchCommentApi({ caseService, router, userActionService }: RouteDeps) {
router.patch(
{
path: '/api/cases/{case_id}/comments',
path: CASE_COMMENTS_URL,
validate: {
params: schema.object({
case_id: schema.string(),

View file

@ -15,6 +15,7 @@ import {
mockCaseComments,
} from '../../__fixtures__';
import { initPostCommentApi } from './post_comment';
import { CASE_COMMENTS_URL } from '../../../../../common/constants';
describe('POST comment', () => {
let routeHandler: RequestHandler<any, any, any>;
@ -27,7 +28,7 @@ describe('POST comment', () => {
});
it(`Posts a new comment`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases/{case_id}/comments',
path: CASE_COMMENTS_URL,
method: 'post',
params: {
case_id: 'mock-id-1',
@ -52,7 +53,7 @@ describe('POST comment', () => {
});
it(`Returns an error if the case does not exist`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases/{case_id}/comments',
path: CASE_COMMENTS_URL,
method: 'post',
params: {
case_id: 'this-is-not-real',
@ -75,7 +76,7 @@ describe('POST comment', () => {
});
it(`Returns an error if postNewCase throws`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases/{case_id}/comments',
path: CASE_COMMENTS_URL,
method: 'post',
params: {
case_id: 'mock-id-1',
@ -100,7 +101,7 @@ describe('POST comment', () => {
routeHandler = await createRoute(initPostCommentApi, 'post', true);
const request = httpServerMock.createKibanaRequest({
path: '/api/cases/{case_id}/comments',
path: CASE_COMMENTS_URL,
method: 'post',
params: {
case_id: 'mock-id-1',

View file

@ -15,11 +15,12 @@ import { CASE_SAVED_OBJECT } from '../../../../saved_object_types';
import { buildCommentUserActionItem } from '../../../../services/user_actions/helpers';
import { escapeHatch, transformNewComment, wrapError, flattenCaseSavedObject } from '../../utils';
import { RouteDeps } from '../../types';
import { CASE_COMMENTS_URL } from '../../../../../common/constants';
export function initPostCommentApi({ caseService, router, userActionService }: RouteDeps) {
router.post(
{
path: '/api/cases/{case_id}/comments',
path: CASE_COMMENTS_URL,
validate: {
params: schema.object({
case_id: schema.string(),

View file

@ -15,6 +15,7 @@ import {
import { mockCaseConfigure } from '../../__fixtures__/mock_saved_objects';
import { initGetCaseConfigure } from './get_configure';
import { CASE_CONFIGURE_URL } from '../../../../../common/constants';
describe('GET configuration', () => {
let routeHandler: RequestHandler<any, any, any>;
@ -24,7 +25,7 @@ describe('GET configuration', () => {
it('returns the configuration', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'get',
});
@ -44,7 +45,7 @@ describe('GET configuration', () => {
it('handles undefined version correctly', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'get',
});
@ -78,7 +79,7 @@ describe('GET configuration', () => {
it('returns an empty object when there is no configuration', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'get',
});
@ -95,7 +96,7 @@ describe('GET configuration', () => {
it('returns an error if find throws an error', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'get',
});

View file

@ -7,11 +7,12 @@
import { CaseConfigureResponseRt } from '../../../../../common/api';
import { RouteDeps } from '../../types';
import { wrapError } from '../../utils';
import { CASE_CONFIGURE_URL } from '../../../../../common/constants';
export function initGetCaseConfigure({ caseConfigureService, caseService, router }: RouteDeps) {
router.get(
{
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
validate: false,
},
async (context, request, response) => {

View file

@ -16,6 +16,7 @@ import {
import { mockCaseConfigure } from '../../__fixtures__/mock_saved_objects';
import { initCaseConfigureGetActionConnector } from './get_connectors';
import { getActions } from '../../__mocks__/request_responses';
import { CASE_CONFIGURE_CONNECTORS_URL } from '../../../../../common/constants';
describe('GET connectors', () => {
let routeHandler: RequestHandler<any, any, any>;
@ -25,7 +26,7 @@ describe('GET connectors', () => {
it('returns the connectors', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure/connectors/_find',
path: `${CASE_CONFIGURE_CONNECTORS_URL}/_find`,
method: 'get',
});
@ -44,7 +45,7 @@ describe('GET connectors', () => {
it('it throws an error when actions client is null', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure/connectors/_find',
path: `${CASE_CONFIGURE_CONNECTORS_URL}/_find`,
method: 'get',
});

View file

@ -8,6 +8,8 @@ import Boom from 'boom';
import { RouteDeps } from '../../types';
import { wrapError } from '../../utils';
import { CASE_CONFIGURE_CONNECTORS_URL } from '../../../../../common/constants';
/*
* Be aware that this api will only return 20 connectors
*/
@ -17,7 +19,7 @@ const CASE_SERVICE_NOW_ACTION = '.servicenow';
export function initCaseConfigureGetActionConnector({ caseService, router }: RouteDeps) {
router.get(
{
path: '/api/cases/configure/connectors/_find',
path: `${CASE_CONFIGURE_CONNECTORS_URL}/_find`,
validate: false,
},
async (context, request, response) => {

View file

@ -15,6 +15,7 @@ import {
import { mockCaseConfigure } from '../../__fixtures__/mock_saved_objects';
import { initPatchCaseConfigure } from './patch_configure';
import { CASE_CONFIGURE_URL } from '../../../../../common/constants';
describe('PATCH configuration', () => {
let routeHandler: RequestHandler<any, any, any>;
@ -29,7 +30,7 @@ describe('PATCH configuration', () => {
it('patch configuration', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'patch',
body: {
closure_type: 'close-by-pushing',
@ -61,7 +62,7 @@ describe('PATCH configuration', () => {
routeHandler = await createRoute(initPatchCaseConfigure, 'patch', true);
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'patch',
body: {
closure_type: 'close-by-pushing',
@ -91,7 +92,7 @@ describe('PATCH configuration', () => {
it('throw error when configuration have not being created', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'patch',
body: {
closure_type: 'close-by-pushing',
@ -113,7 +114,7 @@ describe('PATCH configuration', () => {
it('throw error when the versions are different', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'patch',
body: {
closure_type: 'close-by-pushing',
@ -135,7 +136,7 @@ describe('PATCH configuration', () => {
it('handles undefined version correctly', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'patch',
body: { connector_id: 'no-version', version: mockCaseConfigure[0].version },
});

View file

@ -16,11 +16,12 @@ import {
} from '../../../../../common/api';
import { RouteDeps } from '../../types';
import { wrapError, escapeHatch } from '../../utils';
import { CASE_CONFIGURE_URL } from '../../../../../common/constants';
export function initPatchCaseConfigure({ caseConfigureService, caseService, router }: RouteDeps) {
router.patch(
{
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
validate: {
body: escapeHatch,
},

View file

@ -16,6 +16,7 @@ import {
import { mockCaseConfigure } from '../../__fixtures__/mock_saved_objects';
import { initPostCaseConfigure } from './post_configure';
import { newConfiguration } from '../../__mocks__/request_responses';
import { CASE_CONFIGURE_URL } from '../../../../../common/constants';
describe('POST configuration', () => {
let routeHandler: RequestHandler<any, any, any>;
@ -30,7 +31,7 @@ describe('POST configuration', () => {
it('create configuration', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'post',
body: newConfiguration,
});
@ -61,7 +62,7 @@ describe('POST configuration', () => {
routeHandler = await createRoute(initPostCaseConfigure, 'post', true);
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'post',
body: newConfiguration,
});
@ -90,7 +91,7 @@ describe('POST configuration', () => {
it('throws when missing connector_id', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'post',
body: {
connector_name: 'My connector 2',
@ -111,7 +112,7 @@ describe('POST configuration', () => {
it('throws when missing connector_name', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'post',
body: {
connector_id: '456',
@ -132,7 +133,7 @@ describe('POST configuration', () => {
it('throws when missing closure_type', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'post',
body: {
connector_id: '456',
@ -153,7 +154,7 @@ describe('POST configuration', () => {
it('it deletes the previous configuration', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'post',
body: newConfiguration,
});
@ -172,7 +173,7 @@ describe('POST configuration', () => {
it('it does NOT delete when not found', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'post',
body: newConfiguration,
});
@ -191,7 +192,7 @@ describe('POST configuration', () => {
it('it deletes all configuration', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'post',
body: newConfiguration,
});
@ -214,7 +215,7 @@ describe('POST configuration', () => {
it('returns an error if find throws an error', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'post',
body: newConfiguration,
});
@ -232,7 +233,7 @@ describe('POST configuration', () => {
it('returns an error if delete throws an error', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'post',
body: newConfiguration,
});
@ -250,7 +251,7 @@ describe('POST configuration', () => {
it('returns an error if post throws an error', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'post',
body: {
connector_id: 'throw-error-create',
@ -272,7 +273,7 @@ describe('POST configuration', () => {
it('handles undefined version correctly', async () => {
const req = httpServerMock.createKibanaRequest({
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
method: 'post',
body: { ...newConfiguration, connector_id: 'no-version' },
});

View file

@ -16,11 +16,12 @@ import {
} from '../../../../../common/api';
import { RouteDeps } from '../../types';
import { wrapError, escapeHatch } from '../../utils';
import { CASE_CONFIGURE_URL } from '../../../../../common/constants';
export function initPostCaseConfigure({ caseConfigureService, caseService, router }: RouteDeps) {
router.post(
{
path: '/api/cases/configure',
path: CASE_CONFIGURE_URL,
validate: {
body: escapeHatch,
},

View file

@ -16,6 +16,7 @@ import {
mockCaseComments,
} from '../__fixtures__';
import { initDeleteCasesApi } from './delete_cases';
import { CASES_URL } from '../../../../common/constants';
describe('DELETE case', () => {
let routeHandler: RequestHandler<any, any, any>;
@ -24,7 +25,7 @@ describe('DELETE case', () => {
});
it(`deletes the case. responds with 204`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases',
path: CASES_URL,
method: 'delete',
query: {
ids: ['mock-id-1'],
@ -43,7 +44,7 @@ describe('DELETE case', () => {
});
it(`returns an error when thrown from deleteCase service`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases',
path: CASES_URL,
method: 'delete',
query: {
ids: ['not-real'],
@ -62,7 +63,7 @@ describe('DELETE case', () => {
});
it(`returns an error when thrown from getAllCaseComments service`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases',
path: CASES_URL,
method: 'delete',
query: {
ids: ['bad-guy'],
@ -81,7 +82,7 @@ describe('DELETE case', () => {
});
it(`returns an error when thrown from deleteComment service`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases',
path: CASES_URL,
method: 'delete',
query: {
ids: ['valid-id'],

View file

@ -9,11 +9,12 @@ import { schema } from '@kbn/config-schema';
import { buildCaseUserActionItem } from '../../../services/user_actions/helpers';
import { RouteDeps } from '../types';
import { wrapError } from '../utils';
import { CASES_URL } from '../../../../common/constants';
export function initDeleteCasesApi({ caseService, router, userActionService }: RouteDeps) {
router.delete(
{
path: '/api/cases',
path: CASES_URL,
validate: {
query: schema.object({
ids: schema.arrayOf(schema.string()),

View file

@ -14,6 +14,7 @@ import {
mockCases,
} from '../__fixtures__';
import { initFindCasesApi } from './find_cases';
import { CASES_URL } from '../../../../common/constants';
describe('GET all cases', () => {
let routeHandler: RequestHandler<any, any, any>;
@ -22,7 +23,7 @@ describe('GET all cases', () => {
});
it(`gets all the cases`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases',
path: `${CASES_URL}/_find`,
method: 'get',
});

View file

@ -15,6 +15,7 @@ import { CasesFindResponseRt, CasesFindRequestRt, throwErrors } from '../../../.
import { transformCases, sortToSnake, wrapError, escapeHatch } from '../utils';
import { RouteDeps, TotalCommentByCase } from '../types';
import { CASE_SAVED_OBJECT } from '../../../saved_object_types';
import { CASES_URL } from '../../../../common/constants';
const combineFilters = (filters: string[], operator: 'OR' | 'AND'): string =>
filters?.filter(i => i !== '').join(` ${operator} `);
@ -41,7 +42,7 @@ const buildFilter = (
export function initFindCasesApi({ caseService, router }: RouteDeps) {
router.get(
{
path: '/api/cases/_find',
path: `${CASES_URL}/_find`,
validate: {
query: escapeHatch,
},

View file

@ -18,6 +18,7 @@ import {
} from '../__fixtures__';
import { flattenCaseSavedObject } from '../utils';
import { initGetCaseApi } from './get_case';
import { CASE_DETAILS_URL } from '../../../../common/constants';
describe('GET case', () => {
let routeHandler: RequestHandler<any, any, any>;
@ -26,7 +27,7 @@ describe('GET case', () => {
});
it(`returns the case with empty case comments when includeComments is false`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases/{case_id}',
path: CASE_DETAILS_URL,
method: 'get',
params: {
case_id: 'mock-id-1',
@ -55,7 +56,7 @@ describe('GET case', () => {
});
it(`returns an error when thrown from getCase`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases/{case_id}',
path: CASE_DETAILS_URL,
method: 'get',
params: {
case_id: 'abcdefg',
@ -78,7 +79,7 @@ describe('GET case', () => {
});
it(`returns the case with case comments when includeComments is true`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases/{case_id}',
path: CASE_DETAILS_URL,
method: 'get',
params: {
case_id: 'mock-id-1',
@ -102,7 +103,7 @@ describe('GET case', () => {
});
it(`returns an error when thrown from getAllCaseComments`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases/{case_id}',
path: CASE_DETAILS_URL,
method: 'get',
params: {
case_id: 'bad-guy',

View file

@ -9,11 +9,12 @@ import { schema } from '@kbn/config-schema';
import { CaseResponseRt } from '../../../../common/api';
import { RouteDeps } from '../types';
import { flattenCaseSavedObject, wrapError } from '../utils';
import { CASE_DETAILS_URL } from '../../../../common/constants';
export function initGetCaseApi({ caseService, router }: RouteDeps) {
router.get(
{
path: '/api/cases/{case_id}',
path: CASE_DETAILS_URL,
validate: {
params: schema.object({
case_id: schema.string(),

View file

@ -20,11 +20,12 @@ import { escapeHatch, wrapError, flattenCaseSavedObject } from '../utils';
import { RouteDeps } from '../types';
import { getCaseToUpdate } from './helpers';
import { buildCaseUserActions } from '../../../services/user_actions/helpers';
import { CASES_URL } from '../../../../common/constants';
export function initPatchCasesApi({ caseService, router, userActionService }: RouteDeps) {
router.patch(
{
path: '/api/cases',
path: CASES_URL,
validate: {
body: escapeHatch,
},

View file

@ -14,6 +14,7 @@ import {
mockCases,
} from '../__fixtures__';
import { initPostCaseApi } from './post_case';
import { CASES_URL } from '../../../../common/constants';
describe('POST cases', () => {
let routeHandler: RequestHandler<any, any, any>;
@ -26,7 +27,7 @@ describe('POST cases', () => {
});
it(`Posts a new case`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases',
path: CASES_URL,
method: 'post',
body: {
description: 'This is a brand new case of a bad meanie defacing data',
@ -49,7 +50,7 @@ describe('POST cases', () => {
it(`Error if you passing status for a new case`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases',
path: CASES_URL,
method: 'post',
body: {
description: 'This is a brand new case of a bad meanie defacing data',
@ -70,7 +71,7 @@ describe('POST cases', () => {
});
it(`Returns an error if postNewCase throws`, async () => {
const request = httpServerMock.createKibanaRequest({
path: '/api/cases',
path: CASES_URL,
method: 'post',
body: {
description: 'Throw an error',
@ -93,7 +94,7 @@ describe('POST cases', () => {
routeHandler = await createRoute(initPostCaseApi, 'post', true);
const request = httpServerMock.createKibanaRequest({
path: '/api/cases',
path: CASES_URL,
method: 'post',
body: {
description: 'This is a brand new case of a bad meanie defacing data',

View file

@ -14,11 +14,12 @@ import { flattenCaseSavedObject, transformNewCase, wrapError, escapeHatch } from
import { CasePostRequestRt, throwErrors, excess, CaseResponseRt } from '../../../../common/api';
import { buildCaseUserActionItem } from '../../../services/user_actions/helpers';
import { RouteDeps } from '../types';
import { CASES_URL } from '../../../../common/constants';
export function initPostCaseApi({ caseService, router, userActionService }: RouteDeps) {
router.post(
{
path: '/api/cases',
path: CASES_URL,
validate: {
body: escapeHatch,
},

View file

@ -15,6 +15,7 @@ import { flattenCaseSavedObject, wrapError, escapeHatch } from '../utils';
import { CaseExternalServiceRequestRt, CaseResponseRt, throwErrors } from '../../../../common/api';
import { buildCaseUserActionItem } from '../../../services/user_actions/helpers';
import { RouteDeps } from '../types';
import { CASE_DETAILS_URL } from '../../../../common/constants';
export function initPushCaseUserActionApi({
caseConfigureService,
@ -24,7 +25,7 @@ export function initPushCaseUserActionApi({
}: RouteDeps) {
router.post(
{
path: '/api/cases/{case_id}/_push',
path: `${CASE_DETAILS_URL}/_push`,
validate: {
params: schema.object({
case_id: schema.string(),

View file

@ -7,11 +7,12 @@
import { UsersRt } from '../../../../../common/api';
import { RouteDeps } from '../../types';
import { wrapError } from '../../utils';
import { CASE_REPORTERS_URL } from '../../../../../common/constants';
export function initGetReportersApi({ caseService, router }: RouteDeps) {
router.get(
{
path: '/api/cases/reporters',
path: CASE_REPORTERS_URL,
validate: {},
},
async (context, request, response) => {

View file

@ -9,11 +9,12 @@ import { wrapError } from '../../utils';
import { CasesStatusResponseRt } from '../../../../../common/api';
import { CASE_SAVED_OBJECT } from '../../../../saved_object_types';
import { CASE_STATUS_URL } from '../../../../../common/constants';
export function initGetCasesStatusApi({ caseService, router }: RouteDeps) {
router.get(
{
path: '/api/cases/status',
path: CASE_STATUS_URL,
validate: {},
},
async (context, request, response) => {

View file

@ -6,11 +6,12 @@
import { RouteDeps } from '../../types';
import { wrapError } from '../../utils';
import { CASE_TAGS_URL } from '../../../../../common/constants';
export function initGetTagsApi({ caseService, router }: RouteDeps) {
router.get(
{
path: '/api/cases/tags',
path: CASE_TAGS_URL,
validate: {},
},
async (context, request, response) => {

View file

@ -10,11 +10,12 @@ import { CaseUserActionsResponseRt } from '../../../../../common/api';
import { CASE_SAVED_OBJECT, CASE_COMMENT_SAVED_OBJECT } from '../../../../saved_object_types';
import { RouteDeps } from '../../types';
import { wrapError } from '../../utils';
import { CASE_USER_ACTIONS_URL } from '../../../../../common/constants';
export function initGetAllUserActionsApi({ userActionService, router }: RouteDeps) {
router.get(
{
path: '/api/cases/{case_id}/user_actions',
path: CASE_USER_ACTIONS_URL,
validate: {
params: schema.object({
case_id: schema.string(),