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] RBAC: Create & Find integration tests #95511

Merged
merged 19 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion x-pack/plugins/cases/common/api/runtime_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ const getExcessProps = (props: rt.Props, r: Record<string, unknown>): string[] =
return ex;
};

export function excess<C extends rt.InterfaceType<rt.Props>>(codec: C): C {
export function excess<C extends rt.InterfaceType<rt.Props> | rt.PartialType<rt.Props>>(
codec: C
): C {
const r = new rt.InterfaceType(
codec.name,
codec.is,
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/server/client/cases/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
throwErrors,
caseStatuses,
CasesFindResponseRt,
excess,
} from '../../../common/api';

import { CASE_SAVED_OBJECT } from '../../../common/constants';
Expand Down Expand Up @@ -49,7 +50,7 @@ export const find = async ({
}: FindParams): Promise<CasesFindResponse> => {
try {
const queryParams = pipe(
CasesFindRequestRt.decode(options),
excess(CasesFindRequestRt).decode(options),
fold(throwErrors(Boom.badRequest), identity)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -790,10 +790,34 @@ export default ({ getService }: FtrProviderContext): void => {
expectCasesToBeValidOwner(res.cases, 1, ['securitySolutionFixture']);
});

appendToUrl: 'search=securitySolutionFixture+observabilityFixture&searchFields[0]=scope',
// This test is to prevent a future developer to add the filter attribute without taking into consideration
// the authorizationFilter produced by the cases authorization class
it('should NOT allow to pass a filter query parameter', async () => {
await supertest
.get(
`${CASES_URL}/_find?sortOrder=asc&filter=cases.attributes.owner=observabilityFixture`
)
.set('kbn-xsrf', 'true')
.send()
.expect(400);
});

// This test ensures that the user is not allowed to define the namespaces query param
// so she cannot search across spaces
it('should NOT allow to pass a namespaces query parameter', async () => {
await supertest
.get(`${CASES_URL}/_find?sortOrder=asc&namespaces[0]=*`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add an additional case to ensure that the non-array syntax is also prevented? This is the more common syntax:

${CASES_URL}/_find?sortOrder=asc&namespaces=*

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course!

.set('kbn-xsrf', 'true')
.send()
.expect(400);
});

expectCasesToBeValidScoped(res.cases, 1, ['securitySolutionFixture']);
it('should NOT allow to pass a non supported query parameter', async () => {
await supertest
.get(`${CASES_URL}/_find?notExists=papa`)
.set('kbn-xsrf', 'true')
.send()
.expect(400);
});
});
});
Expand Down