mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[SIEM][CASE] Improve api integration test (#67249)
This commit is contained in:
parent
995c2cb725
commit
ce18e6e9ec
4 changed files with 107 additions and 5 deletions
|
@ -16,7 +16,7 @@ import {
|
|||
deleteComments,
|
||||
deleteConfiguration,
|
||||
getConfiguration,
|
||||
getConnector,
|
||||
getServiceNowConnector,
|
||||
} from '../../../common/lib/utils';
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
|
@ -39,7 +39,7 @@ export default ({ getService }: FtrProviderContext): void => {
|
|||
const { body: connector } = await supertest
|
||||
.post('/api/actions/action')
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(getConnector())
|
||||
.send(getServiceNowConnector())
|
||||
.expect(200);
|
||||
|
||||
actionsRemover.add('default', connector.id, 'action', 'actions');
|
||||
|
@ -75,7 +75,7 @@ export default ({ getService }: FtrProviderContext): void => {
|
|||
const { body: connector } = await supertest
|
||||
.post('/api/actions/action')
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(getConnector())
|
||||
.send(getServiceNowConnector())
|
||||
.expect(200);
|
||||
|
||||
actionsRemover.add('default', connector.id, 'action', 'actions');
|
||||
|
|
|
@ -15,12 +15,16 @@ import {
|
|||
deleteComments,
|
||||
deleteConfiguration,
|
||||
getConfiguration,
|
||||
getServiceNowConnector,
|
||||
} from '../../../../common/lib/utils';
|
||||
|
||||
import { ObjectRemover as ActionsRemover } from '../../../../../alerting_api_integration/common/lib';
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default ({ getService }: FtrProviderContext): void => {
|
||||
const supertest = getService('supertest');
|
||||
const es = getService('es');
|
||||
const actionsRemover = new ActionsRemover(supertest);
|
||||
|
||||
describe('get_all_user_actions', () => {
|
||||
afterEach(async () => {
|
||||
|
@ -28,6 +32,7 @@ export default ({ getService }: FtrProviderContext): void => {
|
|||
await deleteComments(es);
|
||||
await deleteConfiguration(es);
|
||||
await deleteCasesUserActions(es);
|
||||
await actionsRemover.removeAll();
|
||||
});
|
||||
|
||||
it(`on new case, user action: 'create' should be called with actionFields: ['description', 'status', 'tags', 'title']`, async () => {
|
||||
|
@ -264,11 +269,20 @@ export default ({ getService }: FtrProviderContext): void => {
|
|||
});
|
||||
|
||||
it(`on new push to service, user action: 'push-to-service' should be called with actionFields: ['pushed']`, async () => {
|
||||
const { body: connector } = await supertest
|
||||
.post('/api/actions/action')
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(getServiceNowConnector())
|
||||
.expect(200);
|
||||
|
||||
actionsRemover.add('default', connector.id, 'action', 'actions');
|
||||
|
||||
const { body: configure } = await supertest
|
||||
.post(CASE_CONFIGURE_URL)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(getConfiguration())
|
||||
.send(getConfiguration(connector.id))
|
||||
.expect(200);
|
||||
|
||||
const { body: postedCase } = await supertest
|
||||
.post(CASES_URL)
|
||||
.set('kbn-xsrf', 'true')
|
||||
|
|
|
@ -8,12 +8,19 @@ import expect from '@kbn/expect';
|
|||
import { FtrProviderContext } from '../../../common/ftr_provider_context';
|
||||
|
||||
import { CASE_CONFIGURE_CONNECTORS_URL } from '../../../../../plugins/case/common/constants';
|
||||
import { ObjectRemover as ActionsRemover } from '../../../../alerting_api_integration/common/lib';
|
||||
import { getServiceNowConnector, getJiraConnector } from '../../../common/lib/utils';
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default ({ getService }: FtrProviderContext): void => {
|
||||
const supertest = getService('supertest');
|
||||
const actionsRemover = new ActionsRemover(supertest);
|
||||
|
||||
describe('get_connectors', () => {
|
||||
afterEach(async () => {
|
||||
await actionsRemover.removeAll();
|
||||
});
|
||||
|
||||
it('should return an empty find body correctly if no connectors are loaded', async () => {
|
||||
const { body } = await supertest
|
||||
.get(`${CASE_CONFIGURE_CONNECTORS_URL}/_find`)
|
||||
|
@ -23,5 +30,54 @@ export default ({ getService }: FtrProviderContext): void => {
|
|||
|
||||
expect(body).to.eql([]);
|
||||
});
|
||||
|
||||
it('should return the correct connectors', async () => {
|
||||
const { body: connectorOne } = await supertest
|
||||
.post('/api/actions/action')
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(getServiceNowConnector())
|
||||
.expect(200);
|
||||
|
||||
const { body: connectorTwo } = await supertest
|
||||
.post('/api/actions/action')
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send({
|
||||
name: 'An email action',
|
||||
actionTypeId: '.email',
|
||||
config: {
|
||||
service: '__json',
|
||||
from: 'bob@example.com',
|
||||
},
|
||||
secrets: {
|
||||
user: 'bob',
|
||||
password: 'supersecret',
|
||||
},
|
||||
})
|
||||
.expect(200);
|
||||
|
||||
const { body: connectorThree } = await supertest
|
||||
.post('/api/actions/action')
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send(getJiraConnector())
|
||||
.expect(200);
|
||||
|
||||
actionsRemover.add('default', connectorOne.id, 'action', 'actions');
|
||||
actionsRemover.add('default', connectorTwo.id, 'action', 'actions');
|
||||
actionsRemover.add('default', connectorThree.id, 'action', 'actions');
|
||||
|
||||
const { body: connectors } = await supertest
|
||||
.get(`${CASE_CONFIGURE_CONNECTORS_URL}/_find`)
|
||||
.set('kbn-xsrf', 'true')
|
||||
.send()
|
||||
.expect(200);
|
||||
|
||||
expect(connectors.length).to.equal(2);
|
||||
expect(
|
||||
connectors.some((c: { actionTypeId: string }) => c.actionTypeId === '.servicenow')
|
||||
).to.equal(true);
|
||||
expect(connectors.some((c: { actionTypeId: string }) => c.actionTypeId === '.jira')).to.equal(
|
||||
true
|
||||
);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@ export const getConfigurationOutput = (update = false): Partial<CasesConfigureRe
|
|||
};
|
||||
};
|
||||
|
||||
export const getConnector = () => ({
|
||||
export const getServiceNowConnector = () => ({
|
||||
name: 'ServiceNow Connector',
|
||||
actionTypeId: '.servicenow',
|
||||
secrets: {
|
||||
|
@ -54,6 +54,38 @@ export const getConnector = () => ({
|
|||
},
|
||||
});
|
||||
|
||||
export const getJiraConnector = () => ({
|
||||
name: 'Jira Connector',
|
||||
actionTypeId: '.jira',
|
||||
secrets: {
|
||||
email: 'elastic@elastic.co',
|
||||
apiToken: 'token',
|
||||
},
|
||||
config: {
|
||||
apiUrl: 'http://some.non.existent.com',
|
||||
projectKey: 'pkey',
|
||||
casesConfiguration: {
|
||||
mapping: [
|
||||
{
|
||||
source: 'title',
|
||||
target: 'summary',
|
||||
actionType: 'overwrite',
|
||||
},
|
||||
{
|
||||
source: 'description',
|
||||
target: 'description',
|
||||
actionType: 'overwrite',
|
||||
},
|
||||
{
|
||||
source: 'comments',
|
||||
target: 'comments',
|
||||
actionType: 'append',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const removeServerGeneratedPropertiesFromConfigure = (
|
||||
config: Partial<CasesConfigureResponse>
|
||||
): Partial<CasesConfigureResponse> => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue