diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/index.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/index.ts index a872edfc17135..aeec07aba906c 100644 --- a/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/index.ts +++ b/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/index.ts @@ -29,7 +29,7 @@ export function getAllExternalServiceSimulatorPaths(): string[] { const allPaths = Object.values(ExternalServiceSimulator).map(service => getExternalServiceSimulatorPath(service) ); - allPaths.push(`/api/_${NAME}/${ExternalServiceSimulator.SERVICENOW}/api/now/v1/table/incident`); + allPaths.push(`/api/_${NAME}/${ExternalServiceSimulator.SERVICENOW}/api/now/v2/table/incident`); return allPaths; } diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/servicenow_simulation.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/servicenow_simulation.ts index f215b63560339..9cd773be1a4ec 100644 --- a/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/servicenow_simulation.ts +++ b/x-pack/test/alerting_api_integration/common/fixtures/plugins/actions/servicenow_simulation.ts @@ -6,11 +6,14 @@ import Joi from 'joi'; import Hapi from 'hapi'; +import { version } from 'bluebird'; interface ServiceNowRequest extends Hapi.Request { payload: { - comments: string; - short_description: string; + caseId: string; + title?: string; + description?: string; + comments?: Array<{ commentId: string; version: string; comment: string }>; }; } export function initPlugin(server: Hapi.Server, path: string) { @@ -22,8 +25,16 @@ export function initPlugin(server: Hapi.Server, path: string) { validate: { options: { abortEarly: false }, payload: Joi.object().keys({ - comments: Joi.string(), - short_description: Joi.string(), + caseId: Joi.string(), + title: Joi.string(), + description: Joi.string(), + comments: Joi.array().items( + Joi.object({ + commentId: Joi.string(), + version: Joi.string(), + comment: Joi.string(), + }) + ), }), }, }, @@ -32,14 +43,46 @@ export function initPlugin(server: Hapi.Server, path: string) { server.route({ method: 'POST', - path: `${path}/api/now/v1/table/incident`, + path: `${path}/api/now/v2/table/incident`, options: { auth: false, validate: { options: { abortEarly: false }, payload: Joi.object().keys({ - comments: Joi.string(), - short_description: Joi.string(), + caseId: Joi.string(), + title: Joi.string(), + description: Joi.string(), + comments: Joi.array().items( + Joi.object({ + commentId: Joi.string(), + version: Joi.string(), + comment: Joi.string(), + }) + ), + }), + }, + }, + handler: servicenowHandler, + }); + + server.route({ + method: 'PATCH', + path: `${path}/api/now/v2/table/incident`, + options: { + auth: false, + validate: { + options: { abortEarly: false }, + payload: Joi.object().keys({ + caseId: Joi.string(), + title: Joi.string(), + description: Joi.string(), + comments: Joi.array().items( + Joi.object({ + commentId: Joi.string(), + version: Joi.string(), + comment: Joi.string(), + }) + ), }), }, }, @@ -52,60 +95,9 @@ export function initPlugin(server: Hapi.Server, path: string) { function servicenowHandler(request: ServiceNowRequest, h: any) { const body = request.payload; - const text = body && body.short_description; - if (text == null) { - return jsonResponse(h, 400, 'bad request to servicenow simulator'); - } - - switch (text) { - case 'success': - return jsonResponse(h, 200, 'Success'); - - case 'created': - return jsonResponse(h, 201, 'Created'); - - case 'no_text': - return jsonResponse(h, 204, 'Success'); - - case 'invalid_payload': - return jsonResponse(h, 400, 'Bad Request'); - - case 'unauthorized': - return jsonResponse(h, 401, 'Unauthorized'); - - case 'forbidden': - return jsonResponse(h, 403, 'Forbidden'); - - case 'not_found': - return jsonResponse(h, 404, 'Not found'); - - case 'not_allowed': - return jsonResponse(h, 405, 'Method not allowed'); - - case 'not_acceptable': - return jsonResponse(h, 406, 'Not acceptable'); - - case 'unsupported': - return jsonResponse(h, 415, 'Unsupported media type'); - - case 'status_500': - return jsonResponse(h, 500, 'simulated servicenow 500 response'); - - case 'rate_limit': - const response = { - retry_after: 1, - ok: false, - error: 'rate_limited', - }; - - return h - .response(response) - .type('application/json') - .header('retry-after', '1') - .code(429); - } + const text = body && body.caseId; - return jsonResponse(h, 400, 'unknown request to servicenow simulator'); + return jsonResponse(h, 200, 'Success'); } function jsonResponse(h: any, code: number, object?: any) { diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts index ec7629be3d6f6..1ae347fe7d37d 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/actions/builtin_action_types/servicenow.ts @@ -283,7 +283,7 @@ export default function servicenowTest({ getService }: FtrProviderContext) { .post(`/api/action/${simulatedActionId}/_execute`) .set('kbn-xsrf', 'foo') .send({ - params: { ...mockServiceNow.params }, + params: { caseId: 'success' }, }) .expect(200);