From 22d32ad634e51342ae34f9eccdb68a36c4d3592f Mon Sep 17 00:00:00 2001 From: Jonathan Buttner Date: Tue, 11 Oct 2022 10:29:30 -0400 Subject: [PATCH] Removing details validation --- .../connector_types/stack/opsgenie/schema.ts | 24 ++------ .../actions/connector_types/stack/opsgenie.ts | 55 ------------------- 2 files changed, 6 insertions(+), 73 deletions(-) diff --git a/x-pack/plugins/stack_connectors/server/connector_types/stack/opsgenie/schema.ts b/x-pack/plugins/stack_connectors/server/connector_types/stack/opsgenie/schema.ts index 84804097f3e77..35a3c0c9eb58a 100644 --- a/x-pack/plugins/stack_connectors/server/connector_types/stack/opsgenie/schema.ts +++ b/x-pack/plugins/stack_connectors/server/connector_types/stack/opsgenie/schema.ts @@ -6,7 +6,6 @@ */ import { schema } from '@kbn/config-schema'; -import { i18n } from '@kbn/i18n'; export const ConfigSchema = schema.object({ apiUrl: schema.string(), @@ -23,20 +22,6 @@ const responderTypes = schema.oneOf([ schema.literal('schedule'), ]); -const validateDetails = (details: Record): string | void => { - let totalChars = 0; - - for (const value of Object.values(details)) { - totalChars += value.length; - - if (totalChars > 8000) { - return i18n.translate('xpack.stackConnectors.opsgenie.invalidDetails', { - defaultMessage: 'details field character count exceeds the 8000 limit', - }); - } - } -}; - export const CreateAlertParamsSchema = schema.object({ message: schema.string({ maxLength: 130 }), /** @@ -82,9 +67,12 @@ export const CreateAlertParamsSchema = schema.object({ ), actions: schema.maybe(schema.arrayOf(schema.string({ maxLength: 50 }), { maxSize: 10 })), tags: schema.maybe(schema.arrayOf(schema.string({ maxLength: 50 }), { maxSize: 20 })), - details: schema.maybe( - schema.recordOf(schema.string(), schema.string(), { validate: validateDetails }) - ), + /** + * The validation requirement here is that the total characters between the key and value do not exceed 8000. Opsgenie + * will truncate the value if it would exceed the 8000 but it doesn't throw an error. Because of this I'm intentionally + * not validating the length of the keys and values here. + */ + details: schema.maybe(schema.recordOf(schema.string(), schema.string())), entity: schema.maybe(schema.string({ maxLength: 512 })), source: schema.maybe(schema.string({ maxLength: 100 })), priority: schema.maybe( diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/connector_types/stack/opsgenie.ts b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/connector_types/stack/opsgenie.ts index 4941b90c2b976..bea3205d1abec 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/connector_types/stack/opsgenie.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/group2/tests/actions/connector_types/stack/opsgenie.ts @@ -452,61 +452,6 @@ export default function opsgenieTest({ getService }: FtrProviderContext) { }); }); - it('should fail to create an alert when the details field keys are more than 8000 characters', async () => { - const { body } = await supertest - .post(`/api/actions/connector/${opsgenieActionId}/_execute`) - .set('kbn-xsrf', 'foo') - .send({ - params: { - subAction: 'createAlert', - subActionParams: { - message: 'hello', - details: { - bananas: 'a'.repeat(8001), - }, - }, - }, - }) - .expect(200); - - expect(body).to.eql({ - connector_id: opsgenieActionId, - status: 'error', - retry: false, - message: 'an error occurred while running the action', - service_message: - 'Request validation failed (Error: [details]: details field character count exceeds the 8000 limit)', - }); - }); - - it('should succeed to create an alert when the details field keys total equal 8000 characters', async () => { - const { body } = await supertest - .post(`/api/actions/connector/${opsgenieActionId}/_execute`) - .set('kbn-xsrf', 'foo') - .send({ - params: { - subAction: 'createAlert', - subActionParams: { - message: 'hello', - details: { - bananas: 'a'.repeat(8000), - }, - }, - }, - }) - .expect(200); - - expect(body).to.eql({ - connector_id: opsgenieActionId, - status: 'ok', - data: { - requestId: '43a29c5c-3dbf-4fa4-9c26-f4f71023e120', - result: 'Request will be processed', - took: 0.107, - }, - }); - }); - it('should succeed to create an alert when the details field a record of string to string', async () => { const { body } = await supertest .post(`/api/actions/connector/${opsgenieActionId}/_execute`)