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] Guardrails: Total number cases update #161076

Merged
merged 5 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion x-pack/plugins/cases/common/api/cases/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
MAX_ASSIGNEES_FILTER_LENGTH,
MAX_REPORTERS_FILTER_LENGTH,
MAX_TAGS_FILTER_LENGTH,
MAX_CASES_TO_UPDATE,
} from '../../constants';

export const AttachmentTotalsRt = rt.strict({
Expand Down Expand Up @@ -420,7 +421,10 @@ export const CasePatchRequestRt = rt.intersection([
rt.strict({ id: rt.string, version: rt.string }),
]);

export const CasesPatchRequestRt = rt.strict({ cases: rt.array(CasePatchRequestRt) });
export const CasesPatchRequestRt = rt.strict({
cases: limitedArraySchema(CasePatchRequestRt, 1, MAX_CASES_TO_UPDATE, 'cases'),
});

export const CasesRt = rt.array(CaseRt);

export const CasePushRequestParamsRt = rt.strict({
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/cases/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const MAX_DESCRIPTION_LENGTH = 30000 as const;
export const MAX_LENGTH_PER_TAG = 256 as const;
export const MAX_TAGS_PER_CASE = 200 as const;
export const MAX_DELETE_IDS_LENGTH = 100 as const;
export const MAX_CASES_TO_UPDATE = 100 as const;

/**
* Cases features
Expand Down
32 changes: 17 additions & 15 deletions x-pack/plugins/cases/docs/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,18 @@
"url": "https://www.elastic.co/licensing/elastic-license"
}
},
"servers": [
{
"url": "http://localhost:5601",
"description": "local"
}
],
"security": [
{
"basicAuth": []
},
{
"apiKeyAuth": []
}
],
"tags": [
{
"name": "cases",
"description": "Case APIs enable you to open and track issues."
}
],
"servers": [
{
"url": "http://localhost:5601",
"description": "local"
}
],
"paths": {
"/api/cases": {
"post": {
Expand Down Expand Up @@ -5213,6 +5205,8 @@
"cases": {
"type": "array",
"description": "An array containing one or more case objects.",
"maxItems": 100,
"minItems": 1,
"items": {
"type": "object",
"required": [
Expand Down Expand Up @@ -7161,5 +7155,13 @@
]
}
}
}
},
"security": [
{
"basicAuth": []
},
{
"apiKeyAuth": []
}
]
}
14 changes: 8 additions & 6 deletions x-pack/plugins/cases/docs/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@ info:
license:
name: Elastic License 2.0
url: https://www.elastic.co/licensing/elastic-license
servers:
- url: http://localhost:5601
description: local
security:
- basicAuth: []
- apiKeyAuth: []
tags:
- name: cases
description: Case APIs enable you to open and track issues.
servers:
- url: http://localhost:5601
description: local
paths:
/api/cases:
post:
Expand Down Expand Up @@ -3346,6 +3343,8 @@ components:
cases:
type: array
description: An array containing one or more case objects.
maxItems: 100
minItems: 1
items:
type: object
required:
Expand Down Expand Up @@ -4772,3 +4771,6 @@ components:
isPreconfigured: false
isDeprecated: false
referencedByCount: 0
security:
- basicAuth: []
- apiKeyAuth: []
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ properties:
cases:
type: array
description: An array containing one or more case objects.
maxItems: 100
minItems: 1
items:
type: object
required:
Expand Down Expand Up @@ -35,7 +37,7 @@ properties:
settings:
$ref: 'settings.yaml'
severity:
$ref: 'severity_property.yaml'
$ref: 'severity_property.yaml'
status:
$ref: 'status.yaml'
tags:
Expand All @@ -55,4 +57,4 @@ properties:
maxLength: 160
version:
description: The current version of the case. To determine this value, use the get case or find cases APIs.
type: string
type: string
37 changes: 37 additions & 0 deletions x-pack/plugins/cases/server/client/cases/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
MAX_TAGS_PER_CASE,
MAX_LENGTH_PER_TAG,
MAX_TITLE_LENGTH,
MAX_CASES_TO_UPDATE,
} from '../../../common/constants';
import { mockCases } from '../../mocks';
import { createCasesClientMockArgs } from '../mocks';
Expand Down Expand Up @@ -701,4 +702,40 @@ describe('update', () => {
);
});
});

describe('Validation', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it(`throws an error when trying to update more than ${MAX_CASES_TO_UPDATE} cases`, async () => {
await expect(
update(
{
cases: Array(MAX_CASES_TO_UPDATE + 1).fill({
id: mockCases[0].id,
version: mockCases[0].version ?? '',
title: 'This is a test case!!',
}),
},
createCasesClientMockArgs()
)
).rejects.toThrow(
'Error: The length of the field cases is too long. Array must be of length <= 100.'
);
});

it('throws an error when trying to update zero cases', async () => {
await expect(
update(
{
cases: [],
},
createCasesClientMockArgs()
)
).rejects.toThrow(
'Error: The length of the field cases is too short. Array must be of length >= 1.'
);
});
});
});
Loading