Skip to content

Commit

Permalink
[Security Solution] Webhook - Case Management Connector Follow Ups (#…
Browse files Browse the repository at this point in the history
…137227) (#137627)

(cherry picked from commit 2d3d930)

Co-authored-by: Steph Milovic <stephanie.milovic@elastic.co>
  • Loading branch information
kibanamachine and stephmilovic authored Jul 29, 2022
1 parent 82ddf1e commit f9ee6db
Show file tree
Hide file tree
Showing 35 changed files with 859 additions and 451 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('api', () => {
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
url: 'https://coolsite.net/browse/CK-1',
comments: [
{
commentId: 'case-comment-1',
Expand All @@ -57,7 +57,7 @@ describe('api', () => {
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
url: 'https://coolsite.net/browse/CK-1',
});
});

Expand Down Expand Up @@ -109,7 +109,7 @@ describe('api', () => {
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
url: 'https://coolsite.net/browse/CK-1',
comments: [
{
commentId: 'case-comment-1',
Expand All @@ -135,7 +135,7 @@ describe('api', () => {
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
url: 'https://coolsite.net/browse/CK-1',
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ const createMock = (): jest.Mocked<ExternalService> => {
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
url: 'https://coolsite.net/browse/CK-1',
})
),
updateIncident: jest.fn().mockImplementation(() =>
Promise.resolve({
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
url: 'https://coolsite.net/browse/CK-1',
})
),
createComment: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const ExternalIncidentServiceConfiguration = {
getIncidentResponseCreatedDateKey: schema.string(),
getIncidentResponseExternalTitleKey: schema.string(),
getIncidentResponseUpdatedDateKey: schema.string(),
incidentViewUrl: schema.string(),
viewIncidentUrl: schema.string(),
updateIncidentUrl: schema.string(),
updateIncidentMethod: schema.oneOf(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,23 @@ const configurationUtilities = actionsConfigMock.create();
const config: CasesWebhookPublicConfigurationType = {
createCommentJson: '{"body":{{{case.comment}}}}',
createCommentMethod: CasesWebhookMethods.POST,
createCommentUrl:
'https://siem-kibana.atlassian.net/rest/api/2/issue/{{{external.system.id}}}/comment',
createCommentUrl: 'https://coolsite.net/issue/{{{external.system.id}}}/comment',
createIncidentJson:
'{"fields":{"title":{{{case.title}}},"description":{{{case.description}}},"tags":{{{case.tags}}},"project":{"key":"ROC"},"issuetype":{"id":"10024"}}}',
createIncidentMethod: CasesWebhookMethods.POST,
createIncidentResponseKey: 'id',
createIncidentUrl: 'https://siem-kibana.atlassian.net/rest/api/2/issue',
createIncidentUrl: 'https://coolsite.net/issue',
getIncidentResponseCreatedDateKey: 'fields.created',
getIncidentResponseExternalTitleKey: 'key',
getIncidentResponseUpdatedDateKey: 'fields.updated',
hasAuth: true,
headers: { ['content-type']: 'application/json' },
incidentViewUrl: 'https://siem-kibana.atlassian.net/browse/{{{external.system.title}}}',
getIncidentUrl: 'https://siem-kibana.atlassian.net/rest/api/2/issue/{{{external.system.id}}}',
viewIncidentUrl: 'https://coolsite.net/browse/{{{external.system.title}}}',
getIncidentUrl: 'https://coolsite.net/issue/{{{external.system.id}}}',
updateIncidentJson:
'{"fields":{"title":{{{case.title}}},"description":{{{case.description}}},"tags":{{{case.tags}}},"project":{"key":"ROC"},"issuetype":{"id":"10024"}}}',
updateIncidentMethod: CasesWebhookMethods.PUT,
updateIncidentUrl: 'https://siem-kibana.atlassian.net/rest/api/2/issue/{{{external.system.id}}}',
updateIncidentUrl: 'https://coolsite.net/issue/{{{external.system.id}}}',
};
const secrets = {
user: 'user',
Expand Down Expand Up @@ -76,7 +75,7 @@ describe('Cases webhook service', () => {
describe('createExternalService', () => {
const requiredUrls = [
'createIncidentUrl',
'incidentViewUrl',
'viewIncidentUrl',
'getIncidentUrl',
'updateIncidentUrl',
];
Expand Down Expand Up @@ -154,7 +153,7 @@ describe('Cases webhook service', () => {
await service.getIncident('1');
expect(requestMock).toHaveBeenCalledWith({
axios,
url: 'https://siem-kibana.atlassian.net/rest/api/2/issue/1',
url: 'https://coolsite.net/issue/1',
logger,
configurationUtilities,
});
Expand Down Expand Up @@ -231,7 +230,7 @@ describe('Cases webhook service', () => {
title: 'CK-1',
id: '1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
url: 'https://coolsite.net/browse/CK-1',
});
});

Expand Down Expand Up @@ -260,7 +259,7 @@ describe('Cases webhook service', () => {

expect(requestMock.mock.calls[0][0]).toEqual({
axios,
url: 'https://siem-kibana.atlassian.net/rest/api/2/issue',
url: 'https://coolsite.net/issue',
logger,
method: CasesWebhookMethods.POST,
configurationUtilities,
Expand Down Expand Up @@ -326,7 +325,7 @@ describe('Cases webhook service', () => {
title: 'CK-1',
id: '1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
url: 'https://coolsite.net/browse/CK-1',
});
});

Expand All @@ -348,7 +347,7 @@ describe('Cases webhook service', () => {
logger,
method: CasesWebhookMethods.PUT,
configurationUtilities,
url: 'https://siem-kibana.atlassian.net/rest/api/2/issue/1',
url: 'https://coolsite.net/issue/1',
data: JSON.stringify({
fields: {
title: 'title',
Expand Down Expand Up @@ -426,7 +425,7 @@ describe('Cases webhook service', () => {
logger,
method: CasesWebhookMethods.POST,
configurationUtilities,
url: 'https://siem-kibana.atlassian.net/rest/api/2/issue/1/comment',
url: 'https://coolsite.net/issue/1/comment',
data: `{"body":"comment"}`,
});
});
Expand Down Expand Up @@ -664,7 +663,7 @@ describe('Cases webhook service', () => {
test('getIncident- escapes url', async () => {
await service.getIncident('../../malicious-app/malicious-endpoint/');
expect(requestMock.mock.calls[0][0].url).toEqual(
'https://siem-kibana.atlassian.net/rest/api/2/issue/..%2F..%2Fmalicious-app%2Fmalicious-endpoint%2F'
'https://coolsite.net/issue/..%2F..%2Fmalicious-app%2Fmalicious-endpoint%2F'
);
});

Expand All @@ -681,7 +680,7 @@ describe('Cases webhook service', () => {
};
const res = await service.createIncident(incident);
expect(res.url).toEqual(
'https://siem-kibana.atlassian.net/browse/..%2F..%2Fmalicious-app%2Fmalicious-endpoint%2F'
'https://coolsite.net/browse/..%2F..%2Fmalicious-app%2Fmalicious-endpoint%2F'
);
});

Expand All @@ -700,7 +699,7 @@ describe('Cases webhook service', () => {

await service.updateIncident(incident);
expect(requestMock.mock.calls[0][0].url).toEqual(
'https://siem-kibana.atlassian.net/rest/api/2/issue/..%2F..%2Fmalicious-app%2Fmalicious-endpoint%2F'
'https://coolsite.net/issue/..%2F..%2Fmalicious-app%2Fmalicious-endpoint%2F'
);
});
test('createComment- escapes url', async () => {
Expand All @@ -714,7 +713,7 @@ describe('Cases webhook service', () => {

await service.createComment(commentReq);
expect(requestMock.mock.calls[0][0].url).toEqual(
'https://siem-kibana.atlassian.net/rest/api/2/issue/..%2F..%2Fmalicious-app%2Fmalicious-endpoint%2F/comment'
'https://coolsite.net/issue/..%2F..%2Fmalicious-app%2Fmalicious-endpoint%2F/comment'
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const createExternalService = (
getIncidentUrl,
hasAuth,
headers,
incidentViewUrl,
viewIncidentUrl,
updateIncidentJson,
updateIncidentMethod,
updateIncidentUrl,
Expand All @@ -64,7 +64,7 @@ export const createExternalService = (
if (
!getIncidentUrl ||
!createIncidentUrlConfig ||
!incidentViewUrl ||
!viewIncidentUrl ||
!updateIncidentUrl ||
(hasAuth && (!password || !user))
) {
Expand Down Expand Up @@ -163,7 +163,7 @@ export const createExternalService = (

logger.debug(`response from webhook action "${actionId}": [HTTP ${status}] ${statusText}`);

const viewUrl = renderMustacheStringNoEscape(incidentViewUrl, {
const viewUrl = renderMustacheStringNoEscape(viewIncidentUrl, {
external: {
system: {
id: encodeURIComponent(externalId),
Expand Down Expand Up @@ -233,7 +233,7 @@ export const createExternalService = (
res,
});
const updatedIncident = await getIncident(incidentId as string);
const viewUrl = renderMustacheStringNoEscape(incidentViewUrl, {
const viewUrl = renderMustacheStringNoEscape(viewIncidentUrl, {
external: {
system: {
id: encodeURIComponent(incidentId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ const validateConfig = (
const {
createCommentUrl,
createIncidentUrl,
incidentViewUrl,
viewIncidentUrl,
getIncidentUrl,
updateIncidentUrl,
} = configObject;

const urls = [
createIncidentUrl,
createCommentUrl,
incidentViewUrl,
viewIncidentUrl,
getIncidentUrl,
updateIncidentUrl,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('api', () => {
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
url: 'https://coolsite.net/browse/CK-1',
comments: [
{
commentId: 'case-comment-1',
Expand All @@ -57,7 +57,7 @@ describe('api', () => {
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
url: 'https://coolsite.net/browse/CK-1',
});
});

Expand Down Expand Up @@ -150,7 +150,7 @@ describe('api', () => {
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
url: 'https://coolsite.net/browse/CK-1',
comments: [
{
commentId: 'case-comment-1',
Expand All @@ -176,7 +176,7 @@ describe('api', () => {
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
url: 'https://coolsite.net/browse/CK-1',
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ const createMock = (): jest.Mocked<ExternalService> => {
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
url: 'https://coolsite.net/browse/CK-1',
})
),
updateIncident: jest.fn().mockImplementation(() =>
Promise.resolve({
id: 'incident-1',
title: 'CK-1',
pushedDate: '2020-04-27T10:59:46.202Z',
url: 'https://siem-kibana.atlassian.net/browse/CK-1',
url: 'https://coolsite.net/browse/CK-1',
})
),
createComment: jest.fn(),
Expand Down
Loading

0 comments on commit f9ee6db

Please sign in to comment.