From 00aae585d99329326a7eca2bc460df6184001693 Mon Sep 17 00:00:00 2001 From: kartiksharma-git Date: Mon, 28 Apr 2025 21:14:16 +0530 Subject: [PATCH] Reset GitHub Actions workflows to match main Signed-off-by: kartiksharma-git --- .../java/land/oras/RegistryWireMockTest.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/test/java/land/oras/RegistryWireMockTest.java b/src/test/java/land/oras/RegistryWireMockTest.java index 4a9a924..721494e 100644 --- a/src/test/java/land/oras/RegistryWireMockTest.java +++ b/src/test/java/land/oras/RegistryWireMockTest.java @@ -21,6 +21,7 @@ package land.oras; import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -588,4 +589,50 @@ void shouldHandleConcurrentBlobPushes(WireMockRuntimeInfo wmRuntimeInfo) throws boolean completed = executor.awaitTermination(10, TimeUnit.SECONDS); assertEquals(true, completed, "Concurrent blob pushes did not complete within timeout"); } + + @Test + void shouldHandleNetworkConnectivityLoss(WireMockRuntimeInfo wmRuntimeInfo) { + WireMock wireMock = wmRuntimeInfo.getWireMock(); + String registryUrl = wmRuntimeInfo.getHttpBaseUrl().replace("http://", ""); + + // Setup WireMock to simulate a connection reset + wireMock.register(get(urlEqualTo("/v2/library/network-loss/tags/list")) + .willReturn(aResponse().withStatus(503).withBody("Service Unavailable"))); + + Registry registry = Registry.Builder.builder() + .withAuthProvider(authProvider) + .withInsecure(true) + .build(); + + ContainerRef ref = ContainerRef.parse("%s/library/network-loss".formatted(registryUrl)); + + // Verify that a network connectivity loss results in an OrasException + OrasException exception = assertThrows(OrasException.class, () -> registry.getTags(ref)); + assertEquals("Response code: 503", exception.getMessage()); + } + + @Test + void shouldHandleCorruptedResponse(WireMockRuntimeInfo wmRuntimeInfo) { + WireMock wireMock = wmRuntimeInfo.getWireMock(); + String registryUrl = wmRuntimeInfo.getHttpBaseUrl().replace("http://", ""); + String digest = SupportedAlgorithm.SHA256.digest("blob-data".getBytes()); + + // Setup WireMock to return a corrupted blob response + wireMock.register(head(urlEqualTo("/v2/library/corrupted-blob/blobs/%s".formatted(digest))) + .willReturn(aResponse().withStatus(200))); + wireMock.register(get(urlEqualTo("/v2/library/corrupted-blob/blobs/%s".formatted(digest))) + .willReturn(aResponse().withStatus(200).withBody("corrupted-data"))); + + Registry registry = Registry.Builder.builder() + .withAuthProvider(authProvider) + .withInsecure(true) + .build(); + + ContainerRef containerRef = ContainerRef.parse("%s/library/corrupted-blob".formatted(registryUrl)); + + // Expect digest mismatch exception + OrasException exception = + assertThrows(OrasException.class, () -> registry.getBlob(containerRef.withDigest(digest))); + assertTrue(exception.getMessage().startsWith("Digest mismatch")); + } }