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

[8.5] Checking if security license isEnabled, and if not, throwing 404 that is expected downstream (#142410) #142638

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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