mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Security Solution][Endpoint] Move Response Action's file download api to versioned router (#161272)
## Summary - Moves the file download API of response actions to versioned router (after getting support for this type of API via #160399 )
This commit is contained in:
parent
d118fb4ba4
commit
8a170249fa
4 changed files with 36 additions and 23 deletions
|
@ -60,7 +60,11 @@ describe('When using the `ResponseActionFileDownloadLink` component', () => {
|
|||
expect(apiMocks.responseProvider.fileInfo).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
expect(renderResult.getByTestId('test-downloadButton')).not.toBeNull();
|
||||
const downlaodButton = renderResult.getByTestId('test-downloadButton');
|
||||
|
||||
expect(downlaodButton.getAttribute('href')).toEqual(
|
||||
'/api/endpoint/action/123/file/123.agent-a/download?apiVersion=2023-10-31'
|
||||
);
|
||||
expect(renderResult.getByTestId('test-passcodeMessage')).toHaveTextContent(
|
||||
FILE_PASSCODE_INFO_MESSAGE
|
||||
);
|
||||
|
|
|
@ -134,10 +134,10 @@ export const ResponseActionFileDownloadLink = memo<ResponseActionFileDownloadLin
|
|||
}, [action.isCompleted, action.wasSuccessful]);
|
||||
|
||||
const downloadUrl: string = useMemo(() => {
|
||||
return resolvePathVariables(ACTION_AGENT_FILE_DOWNLOAD_ROUTE, {
|
||||
return `${resolvePathVariables(ACTION_AGENT_FILE_DOWNLOAD_ROUTE, {
|
||||
action_id: action.id,
|
||||
file_id: getFileDownloadId(action, agentId),
|
||||
});
|
||||
})}?apiVersion=2023-10-31`;
|
||||
}, [action, agentId]);
|
||||
|
||||
const {
|
||||
|
|
|
@ -50,7 +50,11 @@ describe('Response Actions file download API', () => {
|
|||
|
||||
it('should register the route', () => {
|
||||
expect(
|
||||
apiTestSetup.getRegisteredRouteHandler('get', ACTION_AGENT_FILE_DOWNLOAD_ROUTE)
|
||||
apiTestSetup.getRegisteredVersionedRoute(
|
||||
'get',
|
||||
ACTION_AGENT_FILE_DOWNLOAD_ROUTE,
|
||||
'2023-10-31'
|
||||
)
|
||||
).toBeDefined();
|
||||
});
|
||||
|
||||
|
@ -59,11 +63,9 @@ describe('Response Actions file download API', () => {
|
|||
(await httpHandlerContextMock.securitySolution).getEndpointAuthz as jest.Mock
|
||||
).mockResolvedValue(getEndpointAuthzInitialStateMock({ canWriteFileOperations: false }));
|
||||
|
||||
await apiTestSetup.getRegisteredRouteHandler('get', ACTION_AGENT_FILE_DOWNLOAD_ROUTE)(
|
||||
httpHandlerContextMock,
|
||||
httpRequestMock,
|
||||
httpResponseMock
|
||||
);
|
||||
await apiTestSetup
|
||||
.getRegisteredVersionedRoute('get', ACTION_AGENT_FILE_DOWNLOAD_ROUTE, '2023-10-31')
|
||||
.routeHandler(httpHandlerContextMock, httpRequestMock, httpResponseMock);
|
||||
|
||||
expect(httpResponseMock.forbidden).toHaveBeenCalledWith({
|
||||
body: expect.any(EndpointAuthorizationError),
|
||||
|
|
|
@ -25,22 +25,29 @@ export const registerActionFileDownloadRoutes = (
|
|||
) => {
|
||||
const logger = endpointContext.logFactory.get('actionFileDownload');
|
||||
|
||||
// NOTE:
|
||||
// This API (as of today - 2023-06-21) can not be versioned because it is used
|
||||
// to download files from the UI, where its used as part of a `<a>` anchor, which
|
||||
// has no way to define the version header.
|
||||
router.get(
|
||||
{
|
||||
router.versioned
|
||||
.get({
|
||||
access: 'public',
|
||||
// NOTE:
|
||||
// Because this API is used in the browser via `href` (ex. on link to download a file),
|
||||
// we need to enable setting the version number via query params
|
||||
enableQueryVersion: true,
|
||||
path: ACTION_AGENT_FILE_DOWNLOAD_ROUTE,
|
||||
validate: EndpointActionFileDownloadSchema,
|
||||
options: { authRequired: true, tags: ['access:securitySolution'] },
|
||||
},
|
||||
withEndpointAuthz(
|
||||
{ all: ['canWriteFileOperations'] },
|
||||
logger,
|
||||
getActionFileDownloadRouteHandler(endpointContext)
|
||||
)
|
||||
);
|
||||
})
|
||||
.addVersion(
|
||||
{
|
||||
version: '2023-10-31',
|
||||
validate: {
|
||||
request: EndpointActionFileDownloadSchema,
|
||||
},
|
||||
},
|
||||
withEndpointAuthz(
|
||||
{ all: ['canWriteFileOperations'] },
|
||||
logger,
|
||||
getActionFileDownloadRouteHandler(endpointContext)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export const getActionFileDownloadRouteHandler = (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue