Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cases] Add guardrails for add and update comment API #161200

Merged
18 changes: 18 additions & 0 deletions x-pack/plugins/cases/common/api/cases/comment/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
BulkGetAttachmentsRequestRt,
BulkGetAttachmentsResponseRt,
} from '.';
import { MAX_COMMENT_LENGTH } from '../../../constants';

describe('Comments', () => {
describe('CommentAttributesBasicRt', () => {
Expand Down Expand Up @@ -340,6 +341,23 @@ describe('Comments', () => {
right: defaultRequest,
});
});

it.skip('throws error when comment is too long', () => {
js-jankisalvi marked this conversation as resolved.
Show resolved Hide resolved
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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down