From c144d02e0cdd6ef8318944032264e9338498a8ad Mon Sep 17 00:00:00 2001 From: Ying Mao Date: Thu, 12 Nov 2020 14:53:42 -0500 Subject: [PATCH] Fixing pagerduty timestamp validation --- .../builtin_action_types/pagerduty.test.ts | 34 +++++++++++++++++++ .../server/builtin_action_types/pagerduty.ts | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts index e406b37ae61fb..3d3b48e800101 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.test.ts @@ -140,6 +140,40 @@ describe('validateParams()', () => { expect(validateParams(actionType, params)).toEqual(params); }); + test('should validate and pass when params is valid and optional timestamp is empty string', () => { + expect(validateParams(actionType, {})).toEqual({}); + + const params = { + eventAction: 'trigger', + dedupKey: 'a dedupKey', + summary: 'a summary', + source: 'a source', + severity: 'critical', + timestamp: '', + component: 'a component', + group: 'a group', + class: 'a class', + }; + expect(validateParams(actionType, params)).toEqual(params); + }); + + test('should validate and pass when params is valid and optional timestamp is null', () => { + expect(validateParams(actionType, {})).toEqual({}); + + const params = { + eventAction: 'trigger', + dedupKey: 'a dedupKey', + summary: 'a summary', + source: 'a source', + severity: 'critical', + timestamp: null, + component: 'a component', + group: 'a group', + class: 'a class', + }; + expect(validateParams(actionType, params)).toEqual(params); + }); + test('should validate and throw error when params is invalid', () => { expect(() => { validateParams(actionType, { eventAction: 'ackynollage' }); diff --git a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.ts b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.ts index 4574b748e6014..a670f48e43486 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/pagerduty.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/pagerduty.ts @@ -86,7 +86,7 @@ const ParamsSchema = schema.object( function validateParams(paramsObject: unknown): string | void { const { timestamp, eventAction, dedupKey } = paramsObject as ActionParamsType; - if (timestamp != null) { + if (timestamp != null && timestamp.length > 0) { try { const date = Date.parse(timestamp); if (isNaN(date)) {