|
21 | 21 | package land.oras; |
22 | 22 |
|
23 | 23 | import static com.github.tomakehurst.wiremock.client.WireMock.*; |
| 24 | +import static org.junit.Assert.assertTrue; |
24 | 25 | import static org.junit.jupiter.api.Assertions.assertEquals; |
25 | 26 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
26 | 27 | import static org.junit.jupiter.api.Assertions.assertThrows; |
@@ -588,4 +589,50 @@ void shouldHandleConcurrentBlobPushes(WireMockRuntimeInfo wmRuntimeInfo) throws |
588 | 589 | boolean completed = executor.awaitTermination(10, TimeUnit.SECONDS); |
589 | 590 | assertEquals(true, completed, "Concurrent blob pushes did not complete within timeout"); |
590 | 591 | } |
| 592 | + |
| 593 | + @Test |
| 594 | + void shouldHandleNetworkConnectivityLoss(WireMockRuntimeInfo wmRuntimeInfo) { |
| 595 | + WireMock wireMock = wmRuntimeInfo.getWireMock(); |
| 596 | + String registryUrl = wmRuntimeInfo.getHttpBaseUrl().replace("http://", ""); |
| 597 | + |
| 598 | + // Setup WireMock to simulate a connection reset |
| 599 | + wireMock.register(get(urlEqualTo("/v2/library/network-loss/tags/list")) |
| 600 | + .willReturn(aResponse().withStatus(503).withBody("Service Unavailable"))); |
| 601 | + |
| 602 | + Registry registry = Registry.Builder.builder() |
| 603 | + .withAuthProvider(authProvider) |
| 604 | + .withInsecure(true) |
| 605 | + .build(); |
| 606 | + |
| 607 | + ContainerRef ref = ContainerRef.parse("%s/library/network-loss".formatted(registryUrl)); |
| 608 | + |
| 609 | + // Verify that a network connectivity loss results in an OrasException |
| 610 | + OrasException exception = assertThrows(OrasException.class, () -> registry.getTags(ref)); |
| 611 | + assertEquals("Response code: 503", exception.getMessage()); |
| 612 | + } |
| 613 | + |
| 614 | + @Test |
| 615 | + void shouldHandleCorruptedResponse(WireMockRuntimeInfo wmRuntimeInfo) { |
| 616 | + WireMock wireMock = wmRuntimeInfo.getWireMock(); |
| 617 | + String registryUrl = wmRuntimeInfo.getHttpBaseUrl().replace("http://", ""); |
| 618 | + String digest = SupportedAlgorithm.SHA256.digest("blob-data".getBytes()); |
| 619 | + |
| 620 | + // Setup WireMock to return a corrupted blob response |
| 621 | + wireMock.register(head(urlEqualTo("/v2/library/corrupted-blob/blobs/%s".formatted(digest))) |
| 622 | + .willReturn(aResponse().withStatus(200))); |
| 623 | + wireMock.register(get(urlEqualTo("/v2/library/corrupted-blob/blobs/%s".formatted(digest))) |
| 624 | + .willReturn(aResponse().withStatus(200).withBody("corrupted-data"))); |
| 625 | + |
| 626 | + Registry registry = Registry.Builder.builder() |
| 627 | + .withAuthProvider(authProvider) |
| 628 | + .withInsecure(true) |
| 629 | + .build(); |
| 630 | + |
| 631 | + ContainerRef containerRef = ContainerRef.parse("%s/library/corrupted-blob".formatted(registryUrl)); |
| 632 | + |
| 633 | + // Expect digest mismatch exception |
| 634 | + OrasException exception = |
| 635 | + assertThrows(OrasException.class, () -> registry.getBlob(containerRef.withDigest(digest))); |
| 636 | + assertTrue(exception.getMessage().startsWith("Digest mismatch")); |
| 637 | + } |
591 | 638 | } |
0 commit comments