-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SIEM][CASE] Tests for server's configuration API (#63099)
* Test utils * Test get_configure * Test post_configure * Test get_connectors * Test patch_configure * Improve test * Fixes Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
d275d7f
commit 287d477
Showing
9 changed files
with
1,213 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,11 @@ | |
*/ | ||
|
||
import { SavedObject } from 'kibana/server'; | ||
import { CaseAttributes, CommentAttributes } from '../../../../common/api'; | ||
import { | ||
CaseAttributes, | ||
CommentAttributes, | ||
CasesConfigureAttributes, | ||
} from '../../../../common/api'; | ||
|
||
export const mockCases: Array<SavedObject<CaseAttributes>> = [ | ||
{ | ||
|
@@ -225,7 +229,33 @@ export const mockCaseComments: Array<SavedObject<CommentAttributes>> = [ | |
}, | ||
], | ||
updated_at: '2019-11-25T22:32:30.608Z', | ||
version: 'WzYsMV0=', | ||
}, | ||
]; | ||
|
||
export const mockCaseConfigure: Array<SavedObject<CasesConfigureAttributes>> = [ | ||
{ | ||
type: 'cases-configure', | ||
id: 'mock-configuration-1', | ||
attributes: { | ||
connector_id: '123', | ||
connector_name: 'My connector', | ||
closure_type: 'close-by-user', | ||
created_at: '2020-04-09T09:43:51.778Z', | ||
created_by: { | ||
full_name: 'elastic', | ||
email: '[email protected]', | ||
username: 'elastic', | ||
}, | ||
updated_at: '2020-04-09T09:43:51.778Z', | ||
updated_by: { | ||
full_name: 'elastic', | ||
email: '[email protected]', | ||
username: 'elastic', | ||
}, | ||
}, | ||
references: [], | ||
updated_at: '2020-04-09T09:43:51.778Z', | ||
version: 'WzYsMV0=', | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
x-pack/plugins/case/server/routes/api/__mocks__/request_responses.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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 { CasePostRequest, CasesConfigureRequest } from '../../../../common/api'; | ||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
import { FindActionResult } from '../../../../../actions/server/types'; | ||
|
||
export const newCase: CasePostRequest = { | ||
title: 'My new case', | ||
description: 'A description', | ||
tags: ['new', 'case'], | ||
}; | ||
|
||
export const getActions = (): FindActionResult[] => [ | ||
{ | ||
id: 'e90075a5-c386-41e3-ae21-ba4e61510695', | ||
actionTypeId: '.webhook', | ||
name: 'Test', | ||
config: { | ||
method: 'post', | ||
url: 'https://example.com', | ||
headers: null, | ||
}, | ||
isPreconfigured: false, | ||
referencedByCount: 0, | ||
}, | ||
{ | ||
id: 'd611af27-3532-4da9-8034-271fee81d634', | ||
actionTypeId: '.servicenow', | ||
name: 'ServiceNow', | ||
config: { | ||
casesConfiguration: { | ||
mapping: [ | ||
{ | ||
source: 'title', | ||
target: 'short_description', | ||
actionType: 'overwrite', | ||
}, | ||
{ | ||
source: 'description', | ||
target: 'description', | ||
actionType: 'overwrite', | ||
}, | ||
{ | ||
source: 'comments', | ||
target: 'comments', | ||
actionType: 'append', | ||
}, | ||
], | ||
}, | ||
apiUrl: 'https://dev102283.service-now.com', | ||
}, | ||
isPreconfigured: false, | ||
referencedByCount: 0, | ||
}, | ||
]; | ||
|
||
export const newConfiguration: CasesConfigureRequest = { | ||
connector_id: '456', | ||
connector_name: 'My connector 2', | ||
closure_type: 'close-by-pushing', | ||
}; |
112 changes: 112 additions & 0 deletions
112
x-pack/plugins/case/server/routes/api/cases/configure/get_configure.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* 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 { kibanaResponseFactory, RequestHandler } from 'src/core/server'; | ||
import { httpServerMock } from 'src/core/server/mocks'; | ||
|
||
import { | ||
createMockSavedObjectsRepository, | ||
createRoute, | ||
createRouteContext, | ||
} from '../../__fixtures__'; | ||
|
||
import { mockCaseConfigure } from '../../__fixtures__/mock_saved_objects'; | ||
import { initGetCaseConfigure } from './get_configure'; | ||
|
||
describe('GET configuration', () => { | ||
let routeHandler: RequestHandler<any, any, any>; | ||
beforeAll(async () => { | ||
routeHandler = await createRoute(initGetCaseConfigure, 'get'); | ||
}); | ||
|
||
it('returns the configuration', async () => { | ||
const req = httpServerMock.createKibanaRequest({ | ||
path: '/api/cases/configure', | ||
method: 'get', | ||
}); | ||
|
||
const context = createRouteContext( | ||
createMockSavedObjectsRepository({ | ||
caseConfigureSavedObject: mockCaseConfigure, | ||
}) | ||
); | ||
|
||
const res = await routeHandler(context, req, kibanaResponseFactory); | ||
expect(res.status).toEqual(200); | ||
expect(res.payload).toEqual({ | ||
...mockCaseConfigure[0].attributes, | ||
version: mockCaseConfigure[0].version, | ||
}); | ||
}); | ||
|
||
it('handles undefined version correctly', async () => { | ||
const req = httpServerMock.createKibanaRequest({ | ||
path: '/api/cases/configure', | ||
method: 'get', | ||
}); | ||
|
||
const context = createRouteContext( | ||
createMockSavedObjectsRepository({ | ||
caseConfigureSavedObject: [{ ...mockCaseConfigure[0], version: undefined }], | ||
}) | ||
); | ||
|
||
const res = await routeHandler(context, req, kibanaResponseFactory); | ||
expect(res.status).toEqual(200); | ||
expect(res.payload).toEqual({ | ||
connector_id: '123', | ||
connector_name: 'My connector', | ||
closure_type: 'close-by-user', | ||
created_at: '2020-04-09T09:43:51.778Z', | ||
created_by: { | ||
full_name: 'elastic', | ||
email: '[email protected]', | ||
username: 'elastic', | ||
}, | ||
updated_at: '2020-04-09T09:43:51.778Z', | ||
updated_by: { | ||
full_name: 'elastic', | ||
email: '[email protected]', | ||
username: 'elastic', | ||
}, | ||
version: '', | ||
}); | ||
}); | ||
|
||
it('returns an empty object when there is no configuration', async () => { | ||
const req = httpServerMock.createKibanaRequest({ | ||
path: '/api/cases/configure', | ||
method: 'get', | ||
}); | ||
|
||
const context = createRouteContext( | ||
createMockSavedObjectsRepository({ | ||
caseConfigureSavedObject: [], | ||
}) | ||
); | ||
|
||
const res = await routeHandler(context, req, kibanaResponseFactory); | ||
expect(res.status).toEqual(200); | ||
expect(res.payload).toEqual({}); | ||
}); | ||
|
||
it('returns an error if find throws an error', async () => { | ||
const req = httpServerMock.createKibanaRequest({ | ||
path: '/api/cases/configure', | ||
method: 'get', | ||
}); | ||
|
||
const context = createRouteContext( | ||
createMockSavedObjectsRepository({ | ||
caseConfigureSavedObject: [{ ...mockCaseConfigure[0], id: 'throw-error-find' }], | ||
}) | ||
); | ||
|
||
const res = await routeHandler(context, req, kibanaResponseFactory); | ||
expect(res.status).toEqual(404); | ||
expect(res.payload.isBoom).toEqual(true); | ||
}); | ||
}); |
Oops, something went wrong.