Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Dec 22, 2022
1 parent bf88a7e commit 383eb89
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docs/user/security/audit-logging.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ Refer to the corresponding {es} logs for potential write errors.
| `success` | User has accessed an alert as part of a search operation.
| `failure` | User is not authorized to access alerts.

.2+| `case_bulk_get`
| `success` | User has accessed multiple case.
| `failure` | User is not authorized to access multiple case.

3+a|
===== Category: web

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/authorization/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class Authorization {

/**
*
* Returns all authorized entities for an operation. It throws if the user is not authorized
* Returns all authorized entities for an operation. It throws error if the user is not authorized
* to any of the owners
*
* @param entities an array of entities describing the case owners in conjunction with the saved object ID attempting
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/cases/server/authorization/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,18 @@ describe('utils', () => {
const res = getAuthorizedAndUnauthorizedSavedObjects(cases, authorizedEntities);
expect(res).toEqual([[{ id: '1' }], [{ id: '2' }, { id: '3' }]]);
});

it('partitions authorized and unauthorized cases correctly when there are not authorized entities', () => {
const cases = [{ id: '1' }, { id: '2' }, { id: '3' }] as unknown as SavedObject[];

const res = getAuthorizedAndUnauthorizedSavedObjects(cases, []);
expect(res).toEqual([[], cases]);
});

it('partitions authorized and unauthorized cases correctly when there are no saved objects', () => {
const authorizedEntities = [{ id: '1', owner: 'cases' }];
const res = getAuthorizedAndUnauthorizedSavedObjects([], authorizedEntities);
expect(res).toEqual([[], []]);
});
});
});
8 changes: 4 additions & 4 deletions x-pack/plugins/cases/server/client/cases/bulk_get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export const bulkGet = async (
fold(throwErrors(Boom.badRequest), identity)
);

throwIfCaseIdsReachTheLimit(request.ids);
throwIfFieldsAreInvalid(fields);
throwErrorIfCaseIdsReachTheLimit(request.ids);
throwErrorIfFieldsAreInvalid(fields);

const finalFields = fields?.length ? [...fields, 'id', 'version'] : fields;
const cases = await caseService.getCases({ caseIds: request.ids, fields: finalFields });
Expand Down Expand Up @@ -134,7 +134,7 @@ export const bulkGet = async (
}
};

const throwIfFieldsAreInvalid = (fields?: string[]) => {
const throwErrorIfFieldsAreInvalid = (fields?: string[]) => {
if (!fields || fields.length === 0) {
return;
}
Expand All @@ -149,7 +149,7 @@ const throwIfFieldsAreInvalid = (fields?: string[]) => {
}
};

const throwIfCaseIdsReachTheLimit = (ids: string[]) => {
const throwErrorIfCaseIdsReachTheLimit = (ids: string[]) => {
if (ids.length > MAX_BULK_GET_CASES) {
throw Boom.badRequest(`Maximum request limit of ${MAX_BULK_GET_CASES} cases reached`);
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/client/cases/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export interface CasesSubClient {
*/
resolve(params: GetParams): Promise<ICaseResolveResponse>;
/**
* Retrieves a single case with the specified ID.
* Retrieves multiple cases with the specified IDs.
*/
bulkGet(params: CasesBulkGetRequest): Promise<ICasesBulkGetResponse>;
/**
Expand Down

0 comments on commit 383eb89

Please sign in to comment.