Skip to content

Commit

Permalink
Checking if security license isEnabled, and if not, throwing 404 that…
Browse files Browse the repository at this point in the history
… is expected downstream (#142410)

(cherry picked from commit 36b2296)
  • Loading branch information
kc13greiner committed Oct 4, 2022
1 parent ce7621e commit b006583
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('Share Saved Object Permissions', () => {
describe('GET /internal/security/_share_saved_object_permissions', () => {
let routeHandler: RequestHandler<any, any, any, SecurityRequestHandlerContext>;
let routeConfig: RouteConfig<any, any, any, any>;

beforeEach(() => {
const [shareRouteConfig, shareRouteHandler] = router.get.mock.calls.find(
([{ path }]) => path === '/internal/security/_share_saved_object_permissions'
Expand All @@ -50,6 +51,24 @@ describe('Share Saved Object Permissions', () => {
expect(routeConfig.validate).toHaveProperty('query');
});

it('returns `not found` when security is diabled', async () => {
routeParamsMock.license.isEnabled = jest.fn().mockReturnValue(false);

const request = httpServerMock.createKibanaRequest({
query: {
type: 'foo-type',
},
});

await expect(
routeHandler(mockContext, request, kibanaResponseFactory)
).resolves.toMatchObject({
status: 404,
});

expect(routeParamsMock.license.isEnabled).toHaveBeenCalled();
});

it('returns `true` when the user is authorized globally', async () => {
const checkPrivilegesWithRequest = jest.fn().mockResolvedValue({ hasAllRequested: true });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import type { RouteDefinitionParams } from '../..';
import { wrapIntoCustomErrorResponse } from '../../../errors';
import { createLicensedRouteHandler } from '../../licensed_route_handler';

export function defineShareSavedObjectPermissionRoutes({ router, authz }: RouteDefinitionParams) {
export function defineShareSavedObjectPermissionRoutes({
router,
authz,
license,
}: RouteDefinitionParams) {
router.get(
{
path: '/internal/security/_share_saved_object_permissions',
Expand All @@ -21,6 +25,10 @@ export function defineShareSavedObjectPermissionRoutes({ router, authz }: RouteD
let shareToAllSpaces = true;
const { type } = request.query;

if (!license.isEnabled()) {
return response.notFound();
}

try {
const checkPrivileges = authz.checkPrivilegesWithRequest(request);
shareToAllSpaces = (
Expand Down

0 comments on commit b006583

Please sign in to comment.