From c71948402a42786027badbdbc99cd7554d9f2af3 Mon Sep 17 00:00:00 2001 From: Janki Salvi <117571355+js-jankisalvi@users.noreply.github.com> Date: Wed, 5 Jul 2023 16:03:18 +0200 Subject: [PATCH] PR feedback --- .../common/api/cases/comment/index.test.ts | 18 ++++++++++++++++++ .../server/client/attachments/add.test.ts | 4 +--- .../common/internal/bulk_create_attachments.ts | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/cases/common/api/cases/comment/index.test.ts b/x-pack/plugins/cases/common/api/cases/comment/index.test.ts index b0f99125226c..353f78cb1033 100644 --- a/x-pack/plugins/cases/common/api/cases/comment/index.test.ts +++ b/x-pack/plugins/cases/common/api/cases/comment/index.test.ts @@ -29,6 +29,7 @@ import { BulkGetAttachmentsRequestRt, BulkGetAttachmentsResponseRt, } from '.'; +import { MAX_COMMENT_LENGTH } from '../../../constants'; describe('Comments', () => { describe('CommentAttributesBasicRt', () => { @@ -340,6 +341,23 @@ describe('Comments', () => { right: defaultRequest, }); }); + + it.skip('throws error when comment is too long', () => { + const longComment = 'x'.repeat(MAX_COMMENT_LENGTH + 1); + + expect(CommentRequestRt.decode({ ...defaultRequest, comment: longComment })).toMatchObject({ + _tag: 'Left', + left: [{ + context:[{ + actual: { + ...defaultRequest, + comment: longComment, + message: "The length of the comment is too long. The maximum length is 30000." + } + }] + }] + }); + }); }); describe('CommentRt', () => { diff --git a/x-pack/plugins/cases/server/client/attachments/add.test.ts b/x-pack/plugins/cases/server/client/attachments/add.test.ts index 86646d0c3630..b78ec1219088 100644 --- a/x-pack/plugins/cases/server/client/attachments/add.test.ts +++ b/x-pack/plugins/cases/server/client/attachments/add.test.ts @@ -25,9 +25,7 @@ describe('addComment', () => { }); it('should throw an error if the comment length is too long', async () => { - const longComment = Array(MAX_COMMENT_LENGTH + 1) - .fill('x') - .toString(); + const longComment = 'x'.repeat(MAX_COMMENT_LENGTH + 1); await expect( addComment({ comment: { ...comment, comment: longComment }, caseId: 'test-case' }, clientArgs) diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_create_attachments.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_create_attachments.ts index 6788cc26fef9..0df7e207081a 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_create_attachments.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_create_attachments.ts @@ -441,6 +441,23 @@ export default ({ getService }: FtrProviderContext): void => { }); }); + it('400s when comment is too long', async () => { + const longComment = 'x'.repeat(30001); + + await bulkCreateAttachments({ + supertest, + caseId: 'case-id', + params: [ + { + type: CommentType.user, + comment: longComment, + owner: 'securitySolutionFixture', + }, + ], + expectedHttpCode: 400, + }); + }); + it('400s when adding excess attributes for type user', async () => { const postedCase = await createCase(supertest, postCaseReq);