diff --git a/src/main/java/io/cryostat/net/web/http/api/beta/RecordingGetFromPathWithJwtHandler.java b/src/main/java/io/cryostat/net/web/http/api/beta/RecordingGetFromPathWithJwtHandler.java index c8f34179a9..8639e1c27a 100644 --- a/src/main/java/io/cryostat/net/web/http/api/beta/RecordingGetFromPathWithJwtHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/beta/RecordingGetFromPathWithJwtHandler.java @@ -32,6 +32,7 @@ import io.cryostat.net.web.http.api.ApiVersion; import io.cryostat.net.web.http.api.v2.AbstractAssetJwtConsumingHandler; import io.cryostat.net.web.http.api.v2.ApiException; +import io.cryostat.recordings.JvmIdHelper; import io.cryostat.recordings.RecordingArchiveHelper; import io.cryostat.recordings.RecordingNotFoundException; import io.cryostat.rules.ArchivePathException; @@ -44,8 +45,9 @@ public class RecordingGetFromPathWithJwtHandler extends AbstractAssetJwtConsumingHandler { - static final String PATH = "fs/recordings/:subdirectoryName/:recordingName/jwt"; + static final String PATH = "fs/recordings/:jvmId/:recordingName/jwt"; + private final JvmIdHelper jvmIdHelper; private final RecordingArchiveHelper recordingArchiveHelper; @Inject @@ -54,9 +56,11 @@ public class RecordingGetFromPathWithJwtHandler extends AbstractAssetJwtConsumin CredentialsManager credentialsManager, AssetJwtHelper jwtFactory, Lazy webServer, + JvmIdHelper jvmIdHelper, RecordingArchiveHelper recordingArchiveHelper, Logger logger) { super(auth, credentialsManager, jwtFactory, webServer, logger); + this.jvmIdHelper = jvmIdHelper; this.recordingArchiveHelper = recordingArchiveHelper; } @@ -87,9 +91,10 @@ public boolean isAsync() { @Override public void handleWithValidJwt(RoutingContext ctx, JWT jwt) throws Exception { - String subdirectoryName = ctx.pathParam("subdirectoryName"); + String jvmId = ctx.pathParam("jvmId"); String recordingName = ctx.pathParam("recordingName"); try { + String subdirectoryName = jvmIdHelper.jvmIdToSubdirectoryName(jvmId); Path archivedRecording = recordingArchiveHelper .getRecordingPathFromPath(subdirectoryName, recordingName) diff --git a/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandler.java b/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandler.java index 95b6e26204..283ece7304 100644 --- a/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandler.java @@ -38,6 +38,7 @@ import io.cryostat.net.web.http.api.v2.ApiException; import io.cryostat.net.web.http.api.v2.IntermediateResponse; import io.cryostat.net.web.http.api.v2.RequestParameters; +import io.cryostat.recordings.JvmIdHelper; import io.cryostat.recordings.RecordingNotFoundException; import io.cryostat.rules.ArchivePathException; @@ -47,8 +48,9 @@ public class ReportGetFromPathHandler extends AbstractV2RequestHandler { - static final String PATH = "fs/reports/:subdirectoryName/:recordingName"; + static final String PATH = "fs/reports/:jvmId/:recordingName"; + private final JvmIdHelper jvmIdHelper; private final ReportService reportService; private final long reportGenerationTimeoutSeconds; @@ -57,10 +59,12 @@ public class ReportGetFromPathHandler extends AbstractV2RequestHandler { AuthManager auth, CredentialsManager credentialsManager, Gson gson, + JvmIdHelper jvmIdHelper, ReportService reportService, @Named(ReportsModule.REPORT_GENERATION_TIMEOUT_SECONDS) long reportGenerationTimeoutSeconds) { super(auth, credentialsManager, gson); + this.jvmIdHelper = jvmIdHelper; this.reportService = reportService; this.reportGenerationTimeoutSeconds = reportGenerationTimeoutSeconds; } @@ -105,9 +109,10 @@ public boolean isAsync() { @Override public IntermediateResponse handle(RequestParameters params) throws Exception { - String subdirectoryName = params.getPathParams().get("subdirectoryName"); + String jvmId = params.getPathParams().get("jvmId"); String recordingName = params.getPathParams().get("recordingName"); try { + String subdirectoryName = jvmIdHelper.jvmIdToSubdirectoryName(jvmId); List queriedFilter = params.getQueryParams().getAll("filter"); String rawFilter = queriedFilter.isEmpty() ? "" : queriedFilter.get(0); Path report = diff --git a/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandler.java b/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandler.java index f13bd3b513..a6e8ca5a13 100644 --- a/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandler.java @@ -38,6 +38,7 @@ import io.cryostat.net.web.http.api.ApiVersion; import io.cryostat.net.web.http.api.v2.AbstractAssetJwtConsumingHandler; import io.cryostat.net.web.http.api.v2.ApiException; +import io.cryostat.recordings.JvmIdHelper; import io.cryostat.recordings.RecordingArchiveHelper; import io.cryostat.recordings.RecordingNotFoundException; import io.cryostat.rules.ArchivePathException; @@ -51,10 +52,11 @@ class ReportGetFromPathWithJwtHandler extends AbstractAssetJwtConsumingHandler { - static final String PATH = "fs/reports/:subdirectoryName/:recordingName/jwt"; + static final String PATH = "fs/reports/:jvmId/:recordingName/jwt"; private final ReportService reportService; private final long generationTimeoutSeconds; + private final JvmIdHelper jvmIdHelper; @Inject ReportGetFromPathWithJwtHandler( @@ -62,11 +64,13 @@ class ReportGetFromPathWithJwtHandler extends AbstractAssetJwtConsumingHandler { CredentialsManager credentialsManager, AssetJwtHelper jwtFactory, Lazy webServer, + JvmIdHelper jvmIdHelper, ReportService reportService, RecordingArchiveHelper recordingArchiveHelper, @Named(ReportsModule.REPORT_GENERATION_TIMEOUT_SECONDS) long generationTimeoutSeconds, Logger logger) { super(auth, credentialsManager, jwtFactory, webServer, logger); + this.jvmIdHelper = jvmIdHelper; this.reportService = reportService; this.generationTimeoutSeconds = generationTimeoutSeconds; } @@ -111,9 +115,10 @@ public boolean isOrdered() { @Override public void handleWithValidJwt(RoutingContext ctx, JWT jwt) throws Exception { - String subdirectoryName = ctx.pathParam("subdirectoryName"); + String jvmId = ctx.pathParam("jvmId"); String recordingName = ctx.pathParam("recordingName"); try { + String subdirectoryName = jvmIdHelper.jvmIdToSubdirectoryName(jvmId); List queriedFilter = ctx.queryParam("filter"); String rawFilter = queriedFilter.isEmpty() ? "" : queriedFilter.get(0); Path report = diff --git a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingDeleteFromPathHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingDeleteFromPathHandlerTest.java index bb4d8e680e..24651e694f 100644 --- a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingDeleteFromPathHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingDeleteFromPathHandlerTest.java @@ -120,18 +120,20 @@ class Behaviour { void shouldThrow404IfNoMatchingRecordingFound() throws Exception { String recordingName = "someRecording"; String jvmId = "id"; + String subdirectoryName = "someSubdirectory"; + when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName); when(params.getPathParams()) .thenReturn( Map.of( - "id", + "jvmId", jvmId, "recordingName", recordingName)); Future future = CompletableFuture.failedFuture( - new RecordingNotFoundException(jvmId, recordingName)); + new RecordingNotFoundException(subdirectoryName, recordingName)); when(recordingArchiveHelper.deleteRecordingFromPath( Mockito.anyString(), Mockito.anyString())) .thenReturn(future); @@ -145,12 +147,15 @@ void shouldThrow404IfNoMatchingRecordingFound() throws Exception { void shouldHandleSuccessfulDELETERequest() throws Exception { String recordingName = "someRecording"; String jvmId = "id"; + String subdirectoryName = "someSubdirectory"; + + when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName); when(params.getPathParams()) .thenReturn( Map.of( "recordingName", recordingName, - "id", + "jvmId", jvmId)); CompletableFuture future = Mockito.mock(CompletableFuture.class); @@ -164,7 +169,7 @@ void shouldHandleSuccessfulDELETERequest() throws Exception { verify(recordingArchiveHelper) .deleteRecordingFromPath( - Mockito.eq(jvmId), Mockito.eq(recordingName)); + Mockito.eq(subdirectoryName), Mockito.eq(recordingName)); } } } diff --git a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingGetFromPathWithJwtHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingGetFromPathWithJwtHandlerTest.java index cc1169ff7e..91b0399405 100644 --- a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingGetFromPathWithJwtHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingGetFromPathWithJwtHandlerTest.java @@ -30,6 +30,7 @@ import io.cryostat.net.web.WebServer; import io.cryostat.net.web.http.api.ApiVersion; import io.cryostat.net.web.http.api.v2.ApiException; +import io.cryostat.recordings.JvmIdHelper; import io.cryostat.recordings.RecordingArchiveHelper; import io.cryostat.recordings.RecordingNotFoundException; @@ -58,6 +59,7 @@ class RecordingGetFromPathWithJwtHandlerTest { @Mock CredentialsManager credentialsManager; @Mock AssetJwtHelper jwt; @Mock WebServer webServer; + @Mock JvmIdHelper jvmIdHelper; @Mock RecordingArchiveHelper archive; @Mock Logger logger; @@ -65,7 +67,7 @@ class RecordingGetFromPathWithJwtHandlerTest { void setup() { this.handler = new RecordingGetFromPathWithJwtHandler( - auth, credentialsManager, jwt, () -> webServer, archive, logger); + auth, credentialsManager, jwt, () -> webServer, jvmIdHelper, archive, logger); } @Nested @@ -86,7 +88,7 @@ void shouldUseExpectedPath() { MatcherAssert.assertThat( handler.path(), Matchers.equalTo( - "/api/beta/fs/recordings/:subdirectoryName/:recordingName/jwt")); + "/api/beta/fs/recordings/:jvmId/:recordingName/jwt")); } @Test @@ -115,8 +117,9 @@ class Behaviour { @Test void shouldRespond404IfNotFound() throws Exception { - when(ctx.pathParam("subdirectoryName")).thenReturn("mysubdirectory"); + when(ctx.pathParam("jvmId")).thenReturn("id"); when(ctx.pathParam("recordingName")).thenReturn("myrecording"); + when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString())).thenReturn("mysubdirectory"); Future future = CompletableFuture.failedFuture( new RecordingNotFoundException("mysubdirectory", "myrecording")); @@ -132,8 +135,9 @@ void shouldRespond404IfNotFound() throws Exception { void shouldSendFileIfFound() throws Exception { HttpServerResponse resp = Mockito.mock(HttpServerResponse.class); when(ctx.response()).thenReturn(resp); - when(ctx.pathParam("subdirectoryName")).thenReturn("mysubdirectory"); + when(ctx.pathParam("jvmId")).thenReturn("id"); when(ctx.pathParam("recordingName")).thenReturn("myrecording"); + when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString())).thenReturn("mysubdirectory"); Path path = Mockito.mock(Path.class); when(path.toAbsolutePath()).thenReturn(path); when(path.toString()).thenReturn("foo.jfr"); diff --git a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingMetadataLabelsPostFromPathHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingMetadataLabelsPostFromPathHandlerTest.java index e5d461d785..d158f2be26 100644 --- a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingMetadataLabelsPostFromPathHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingMetadataLabelsPostFromPathHandlerTest.java @@ -146,20 +146,22 @@ void shouldUpdateLabels() throws Exception { Map labels = Map.of("key", "value"); Metadata metadata = new Metadata(labels); String requestLabels = labels.toString(); + String subdirectoryName = "someSubdirectory"; Map params = Mockito.mock(Map.class); - + + when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName); when(requestParameters.getPathParams()).thenReturn(params); when(params.get("recordingName")).thenReturn(recordingName); when(params.get("jvmId")).thenReturn(jvmId); when(requestParameters.getBody()).thenReturn(requestLabels); - when(recordingArchiveHelper.getRecordingPathFromPath(jvmId, recordingName)) + when(recordingArchiveHelper.getRecordingPathFromPath(subdirectoryName, recordingName)) .thenReturn(CompletableFuture.completedFuture(Path.of(recordingName))); when(recordingMetadataManager.parseRecordingLabels(requestLabels)).thenReturn(labels); when(recordingMetadataManager.setRecordingMetadataFromPath( - jvmId, recordingName, metadata)) + subdirectoryName, recordingName, metadata)) .thenReturn(CompletableFuture.completedFuture(metadata)); IntermediateResponse response = handler.handle(requestParameters); @@ -187,15 +189,17 @@ void shouldThrow400OnEmptyLabels() throws Exception { void shouldThrowWhenRecordingNotFound() throws Exception { String jvmId = "id"; String recordingName = "someNonExistentRecording"; + String subdirectoryName = "someSubdirectory"; String labels = Map.of("key", "value").toString(); Map params = Mockito.mock(Map.class); + when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName); when(requestParameters.getPathParams()).thenReturn(params); when(params.get("recordingName")).thenReturn(recordingName); when(params.get("jvmId")).thenReturn(jvmId); when(requestParameters.getBody()).thenReturn(labels); - when(recordingArchiveHelper.getRecordingPathFromPath(jvmId, recordingName)) + when(recordingArchiveHelper.getRecordingPathFromPath(subdirectoryName, recordingName)) .thenReturn( CompletableFuture.failedFuture( new RecordingNotFoundException( diff --git a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostFromPathHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostFromPathHandlerTest.java index 273b339cc1..fcd2fc0845 100644 --- a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostFromPathHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostFromPathHandlerTest.java @@ -77,6 +77,7 @@ class RecordingUploadPostFromPathHandlerTest { static final String DATASOURCE_URL = "http://localhost:8080"; + static final String jvmId = "id"; static final String subdirectoryName = "foo"; static final String recordingName = "bar"; @@ -157,11 +158,12 @@ void shouldThrow501IfDatasourceUrlMalformed(String rawUrl) { @Test void shouldThrowExceptionIfRecordingNotFound() throws Exception { + when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName); when(params.getPathParams()) .thenReturn( Map.of( - "subdirectoryName", - subdirectoryName, + "jvmId", + jvmId, "recordingName", recordingName)); when(env.getEnv("GRAFANA_DATASOURCE_URL")).thenReturn(DATASOURCE_URL); @@ -173,7 +175,7 @@ void shouldThrowExceptionIfRecordingNotFound() throws Exception { ExecutionException e = Mockito.mock(ExecutionException.class); when(future.get()).thenThrow(e); when(e.getCause()) - .thenReturn(new RecordingNotFoundException(subdirectoryName, recordingName)); + .thenReturn(new RecordingNotFoundException("foo", recordingName)); ApiException ex = Assertions.assertThrows(ApiException.class, () -> handler.handle(params)); @@ -182,11 +184,12 @@ void shouldThrowExceptionIfRecordingNotFound() throws Exception { @Test void shouldDoUpload() throws Exception { + when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn("foo"); when(params.getPathParams()) .thenReturn( Map.of( - "subdirectoryName", - subdirectoryName, + "jvmId", + jvmId, "recordingName", recordingName)); when(env.getEnv("GRAFANA_DATASOURCE_URL")).thenReturn(DATASOURCE_URL); @@ -236,11 +239,12 @@ public Void answer(InvocationOnMock args) throws Throwable { @Test void shouldHandleInvalidResponseStatusCode() throws Exception { + when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn("someSubdirectory"); when(params.getPathParams()) .thenReturn( Map.of( - "subdirectoryName", - subdirectoryName, + "jvmId", + jvmId, "recordingName", recordingName)); when(env.getEnv("GRAFANA_DATASOURCE_URL")).thenReturn(DATASOURCE_URL); @@ -297,11 +301,12 @@ public Void answer(InvocationOnMock args) throws Throwable { @Test void shouldHandleNullStatusMessage() throws Exception { + when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn("someSubdirectory"); when(params.getPathParams()) .thenReturn( Map.of( - "subdirectoryName", - subdirectoryName, + "jvmId", + jvmId, "recordingName", recordingName)); when(env.getEnv("GRAFANA_DATASOURCE_URL")).thenReturn(DATASOURCE_URL); @@ -358,11 +363,12 @@ public Void answer(InvocationOnMock args) throws Throwable { @Test void shouldHandleNullResponseBody() throws Exception { + when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn("someSubdirectory"); when(params.getPathParams()) .thenReturn( Map.of( - "subdirectoryName", - subdirectoryName, + "jvmId", + jvmId, "recordingName", recordingName)); when(env.getEnv("GRAFANA_DATASOURCE_URL")).thenReturn(DATASOURCE_URL); diff --git a/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandlerTest.java index 1741942fb4..915577735a 100644 --- a/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathHandlerTest.java @@ -33,6 +33,7 @@ import io.cryostat.net.web.http.api.v2.ApiException; import io.cryostat.net.web.http.api.v2.IntermediateResponse; import io.cryostat.net.web.http.api.v2.RequestParameters; +import io.cryostat.recordings.JvmIdHelper; import io.cryostat.recordings.RecordingNotFoundException; import com.google.gson.Gson; @@ -56,13 +57,18 @@ class ReportGetFromPathHandlerTest { @Mock AuthManager authManager; @Mock CredentialsManager credentialsManager; @Mock Gson gson; + @Mock JvmIdHelper jvmIdHelper; @Mock ReportService reportService; + static final String jvmId = "id"; + static final String recordingName = "someRecording"; + static final String subdirectoryName = "someSubdirectory"; + @BeforeEach void setup() { this.handler = new ReportGetFromPathHandler( - authManager, credentialsManager, gson, reportService, 30); + authManager, credentialsManager, gson, jvmIdHelper, reportService, 30); } @Nested @@ -98,7 +104,7 @@ void shouldHaveExpectedRequiredPermissions() { void shouldHandleCorrectPath() { MatcherAssert.assertThat( handler.path(), - Matchers.equalTo("/api/beta/fs/reports/:subdirectoryName/:recordingName")); + Matchers.equalTo("/api/beta/fs/reports/:jvmId/:recordingName")); } @Test @@ -121,13 +127,12 @@ class Behaviour { @Test void shouldThrow404IfNoMatchingRecordingFound() throws Exception { MultiMap queryParams = MultiMap.caseInsensitiveMultiMap(); - String recordingName = "someRecording"; - String subdirectoryName = "someDirectory"; + when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName); when(params.getPathParams()) .thenReturn( Map.of( - "subdirectoryName", - subdirectoryName, + "jvmId", + jvmId, "recordingName", recordingName)); when(params.getQueryParams()).thenReturn(queryParams); @@ -149,13 +154,12 @@ void shouldThrow404IfNoMatchingRecordingFound() throws Exception { @Test void shouldRespondBySendingFile() throws Exception { MultiMap queryParams = MultiMap.caseInsensitiveMultiMap(); - String recordingName = "someRecording"; - String subdirectoryName = "subdirectoryName"; + when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName); when(params.getPathParams()) .thenReturn( Map.of( - "subdirectoryName", - subdirectoryName, + "jvmId", + jvmId, "recordingName", recordingName)); when(params.getQueryParams()).thenReturn(queryParams); @@ -178,13 +182,13 @@ void shouldRespondBySendingFile() throws Exception { void shouldRespondBySendingFileFiltered() throws Exception { MultiMap queryParams = MultiMap.caseInsensitiveMultiMap(); queryParams.add("filter", "someFilter"); - String recordingName = "someRecording"; - String subdirectoryName = "subdirectoryName"; + + when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName); when(params.getPathParams()) .thenReturn( Map.of( - "subdirectoryName", - subdirectoryName, + "jvmId", + jvmId, "recordingName", recordingName)); when(params.getQueryParams()).thenReturn(queryParams); @@ -207,13 +211,13 @@ void shouldRespondBySendingFileFiltered() throws Exception { void shouldRespondBySendingFileUnformatted() throws Exception { MultiMap queryParams = MultiMap.caseInsensitiveMultiMap(); queryParams.add("filter", "someFilter"); - String recordingName = "someRecording"; - String subdirectoryName = "subdirectoryName"; + + when(jvmIdHelper.jvmIdToSubdirectoryName(jvmId)).thenReturn(subdirectoryName); when(params.getPathParams()) .thenReturn( Map.of( - "subdirectoryName", - subdirectoryName, + "jvmId", + jvmId, "recordingName", recordingName)); when(params.getQueryParams()).thenReturn(queryParams); diff --git a/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandlerTest.java index 394b40e6f6..64711a3235 100644 --- a/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/beta/ReportGetFromPathWithJwtHandlerTest.java @@ -34,6 +34,7 @@ import io.cryostat.net.web.http.HttpMimeType; import io.cryostat.net.web.http.api.ApiVersion; import io.cryostat.net.web.http.api.v2.ApiException; +import io.cryostat.recordings.JvmIdHelper; import io.cryostat.recordings.RecordingArchiveHelper; import io.cryostat.recordings.RecordingNotFoundException; @@ -62,6 +63,7 @@ class ReportGetFromPathWithJwtHandlerTest { @Mock CredentialsManager credentialsManager; @Mock AssetJwtHelper jwt; @Mock WebServer webServer; + @Mock JvmIdHelper jvmIdHelper; @Mock ReportService reports; @Mock RecordingArchiveHelper archiveHelper; @Mock Logger logger; @@ -74,6 +76,7 @@ void setup() { credentialsManager, jwt, () -> webServer, + jvmIdHelper, reports, archiveHelper, 30, @@ -108,7 +111,7 @@ void shouldRequireResourceActions() { void shouldUseExpectedPath() { MatcherAssert.assertThat( handler.path(), - Matchers.equalTo("/api/beta/fs/reports/:subdirectoryName/:recordingName/jwt")); + Matchers.equalTo("/api/beta/fs/reports/:jvmId/:recordingName/jwt")); } @Test @@ -137,12 +140,13 @@ class Behaviour { @Test void shouldRespond404IfNotFound() throws Exception { - when(ctx.pathParam("subdirectoryName")).thenReturn("mydirectory"); + when(ctx.pathParam("jvmId")).thenReturn("id"); when(ctx.pathParam("recordingName")).thenReturn("myrecording"); + when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString())).thenReturn("mydirectory"); Future future = CompletableFuture.failedFuture( - new RecordingNotFoundException("mytarget", "myrecording")); + new RecordingNotFoundException("mydirectory", "myrecording")); when(reports.getFromPath(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(future); ApiException ex = @@ -155,8 +159,9 @@ void shouldRespond404IfNotFound() throws Exception { void shouldSendFileIfFound() throws Exception { when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); when(ctx.response()).thenReturn(resp); - when(ctx.pathParam("subdirectoryName")).thenReturn("mydirectory"); + when(ctx.pathParam("jvmId")).thenReturn("id"); when(ctx.pathParam("recordingName")).thenReturn("myrecording"); + when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString())).thenReturn("mydirectory"); Path path = Mockito.mock(Path.class); when(path.toAbsolutePath()).thenReturn(path); when(path.toString()).thenReturn("foo.jfr"); @@ -177,8 +182,9 @@ void shouldSendFileIfFound() throws Exception { void shouldSendFileIfFoundFiltered() throws Exception { when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); when(ctx.response()).thenReturn(resp); - when(ctx.pathParam("subdirectoryName")).thenReturn("mydirectory"); + when(ctx.pathParam("jvmId")).thenReturn("id"); when(ctx.pathParam("recordingName")).thenReturn("myrecording"); + when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString())).thenReturn("mydirectory"); Path path = Mockito.mock(Path.class); when(path.toAbsolutePath()).thenReturn(path); when(path.toString()).thenReturn("foo.jfr"); @@ -200,8 +206,9 @@ void shouldSendFileIfFoundFiltered() throws Exception { void shouldSendFileIfFoundUnformatted() throws Exception { when(ctx.getAcceptableContentType()).thenReturn(HttpMimeType.JSON.mime()); when(ctx.response()).thenReturn(resp); - when(ctx.pathParam("subdirectoryName")).thenReturn("mydirectory"); + when(ctx.pathParam("jvmId")).thenReturn("id"); when(ctx.pathParam("recordingName")).thenReturn("myrecording"); + when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString())).thenReturn("mydirectory"); Path path = Mockito.mock(Path.class); when(path.toAbsolutePath()).thenReturn(path); when(path.toString()).thenReturn("foo.jfr");