Skip to content

Commit

Permalink
Removing details validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-buttner committed Oct 11, 2022
1 parent cf442ad commit 22d32ad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import { schema } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n';

export const ConfigSchema = schema.object({
apiUrl: schema.string(),
Expand All @@ -23,20 +22,6 @@ const responderTypes = schema.oneOf([
schema.literal('schedule'),
]);

const validateDetails = (details: Record<string, string>): 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 }),
/**
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down

0 comments on commit 22d32ad

Please sign in to comment.