From 2e038b5cfbebfd13329b4d81af0a494b7a440f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20Andr=C3=A9?= <92062874+matheusandre1@users.noreply.github.com> Date: Mon, 21 Sep 2026 19:00:27 -0300 Subject: [PATCH] test(codeartifact): pin ResourceNotFoundException on DeleteDomain of a missing domain (#4107) AWS returns ResourceNotFoundException (404) when DeleteDomain targets a domain that does not exist, even though the API reference leaves it out of the operation's error list. Keep that behaviour, pin it with unit and integration tests, and note it in the docs and next to requireDomain. Closes #4000 --- docs/services/codeartifact.md | 2 +- .../services/codeartifact/CodeArtifactService.java | 6 ++++++ .../codeartifact/CodeArtifactIntegrationTest.java | 7 ++++++- .../codeartifact/CodeArtifactServiceTest.java | 13 +++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/services/codeartifact.md b/docs/services/codeartifact.md index b02ad6ee0b..aa44c60f12 100644 --- a/docs/services/codeartifact.md +++ b/docs/services/codeartifact.md @@ -16,7 +16,7 @@ proxy behind them yet. | Action | Description | | --- | --- | | `CreateDomain` | Creates a domain (max 10 per account per Region), optionally with a KMS encryption key and initial tags. | -| `DeleteDomain` | Deletes a domain; fails with `ConflictException` while it still contains repositories. | +| `DeleteDomain` | Deletes a domain; fails with `ConflictException` while it still contains repositories, and with `ResourceNotFoundException` for a missing domain (as AWS does, although the API reference does not list it). | | `DescribeDomain` | Returns a domain's full description, including its repository count. | | `ListDomains` | Lists domain summaries for the account and Region, paginated. | | `PutDomainPermissionsPolicy` | Attaches or replaces a domain's resource policy, versioned by `policyRevision`. | diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactService.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactService.java index 37cfe3b7de..461bfad89f 100644 --- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactService.java +++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactService.java @@ -162,6 +162,10 @@ public class CodeArtifactService implements Resettable { return new DomainView(d, 0); } + /** + * A missing domain fails with {@code ResourceNotFoundException} (404), which is what AWS + * returns even though the API reference leaves it out of DeleteDomain's error list. + */ public synchronized DomainView deleteDomain(String region, String domain, String domainOwner) { String owner = effectiveOwner(domainOwner); String key = domainKey(region, domain); @@ -687,6 +691,8 @@ public class CodeArtifactService implements Resettable { } } + // Used by DeleteDomain too: AWS returns ResourceNotFoundException for a missing domain there, + // although the API reference does not declare it on that operation. private CodeArtifactDomain requireDomain(String owner, String key, String domainName) { if (domainName == null || domainName.isBlank()) { throw validation("domain is required."); diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactIntegrationTest.java index 820477d2b6..08aa34be1a 100644 --- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactIntegrationTest.java @@ -58,7 +58,12 @@ class CodeArtifactIntegrationTest { given().header("Authorization", AUTH) .delete("/v1/domain?domain=lifecycle-domain") - .then().statusCode(200); + .then().statusCode(200).body("domain.name", equalTo("lifecycle-domain")); + + // AWS returns ResourceNotFoundException here although the API reference does not list it on DeleteDomain. + given().header("Authorization", AUTH) + .delete("/v1/domain?domain=lifecycle-domain") + .then().statusCode(404).body("__type", equalTo("ResourceNotFoundException")); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactServiceTest.java index 4e345fdd72..36bf6ecf82 100644 --- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactServiceTest.java @@ -163,6 +163,19 @@ class CodeArtifactServiceTest { assertEquals("with-repo", deleted.domain().getName()); } + @Test + void deleteDomainOfMissingDomainReturnsResourceNotFound() { + // AWS returns this even though the API reference does not list it on DeleteDomain. + AwsException e = assertThrows(AwsException.class, () -> service.deleteDomain(REGION, "never-created", null)); + assertEquals("ResourceNotFoundException", e.getErrorCode()); + assertEquals(404, e.getHttpStatus()); + + service.createDomain(REGION, "once", null, Map.of()); + service.deleteDomain(REGION, "once", null); + AwsException again = assertThrows(AwsException.class, () -> service.deleteDomain(REGION, "once", null)); + assertEquals("ResourceNotFoundException", again.getErrorCode()); + } + @Test void describeDomainReflectsLiveRepositoryCount() { service.createDomain(REGION, "counted", null, Map.of());