fix(codeartifact): treat identical-content maven redeploy as idempotent (#4837)

Reposilite's own redeployment:false setting rejects a redeploy to an
existing GAV path unconditionally, even when the new content is
byte-identical to what is already there (confirmed against a real
instance). AWS's own CodeArtifact docs ("Overwriting package assets"
in the packages overview) say a republish of an asset whose content
matches what is already published succeeds because the operation is
idempotent; only a genuine content mismatch is a real conflict.
Reposilite has no content-aware mode of its own, so this fetches the
existing artifact first and short-circuits to a 200 on an exact match
rather than ever sending Reposilite a PUT it would reject regardless
of whether the retry was actually harmless.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-01 21:18:01 -05:00
1 parent c7bb03ace3
commit cd89be4a80
4 files changed
+198 -10

No files matched your search

@@ -90,8 +90,54 @@ class CodeArtifactMavenDockerIntegrationTest {
.then().statusCode(200);
}
/**
* Reposilite's {@code redeployment: false} rejects a redeploy to an existing GAV path
* unconditionally, even when the new content is byte-identical to what is already there. AWS's
* own CodeArtifact docs ("Overwriting package assets" in packages-overview.html) say that case
* specifically succeeds because the operation is idempotent; only a genuine content mismatch,
* covered by {@link #redeployingDifferentBytesStillConflicts}, is a real conflict.
*/
@Test
@Order(2)
void redeployingTheExactSameBytesSucceedsIdempotently() {
byte[] content = "real-jar-bytes".getBytes(StandardCharsets.UTF_8);
given().header("Authorization", "Bearer " + bearerToken).body(content)
.put("/codeartifact/maven/" + DOMAIN + "/" + REPO + "/" + GAV)
.then().statusCode(200);
byte[] fetched = given().header("Authorization", "Bearer " + bearerToken)
.get("/codeartifact/maven/" + DOMAIN + "/" + REPO + "/" + GAV)
.then().statusCode(200)
.extract().asByteArray();
assertEquals(new String(content, StandardCharsets.UTF_8), new String(fetched, StandardCharsets.UTF_8));
}
/**
* The real content-mismatch counterpart to the idempotent-retry test above, against the live
* shared Reposilite container rather than a fake server: proves the fix only closes the
* byte-identical-retry gap and leaves Reposilite's own {@code redeployment: false} enforcement
* for a genuine conflict untouched, so a config change there that started allowing silent
* overwrites would still be caught here.
*/
@Test
@Order(3)
void redeployingDifferentBytesStillConflicts() {
byte[] different = "different-jar-bytes".getBytes(StandardCharsets.UTF_8);
given().header("Authorization", "Bearer " + bearerToken).body(different)
.put("/codeartifact/maven/" + DOMAIN + "/" + REPO + "/" + GAV)
.then().statusCode(409);
byte[] fetched = given().header("Authorization", "Bearer " + bearerToken)
.get("/codeartifact/maven/" + DOMAIN + "/" + REPO + "/" + GAV)
.then().statusCode(200)
.extract().asByteArray();
assertEquals("real-jar-bytes", new String(fetched, StandardCharsets.UTF_8));
}
@Test
@Order(4)
void missingArtifactAndMissingRepositoryAreNotFound() {
given().header("Authorization", "Bearer " + bearerToken)
.get("/codeartifact/maven/" + DOMAIN + "/" + REPO + "/does/not/exist.jar")
@@ -103,7 +149,7 @@ class CodeArtifactMavenDockerIntegrationTest {
}
@Test
@Order(3)
@Order(5)
void repositoriesAreIsolatedFromEachOther() {
given().contentType("application/json").header("Authorization", AUTH).body("{}")
.post("/v1/repository?domain=" + DOMAIN + "&repository=other-repo")
@@ -115,7 +161,7 @@ class CodeArtifactMavenDockerIntegrationTest {
}
@Test
@Order(4)
@Order(6)
void missingOrWrongDomainTokensAreUnauthorized() {
// Challenges as Basic, not Bearer: a real Maven wagon client only retries a 401 with its
// configured settings.xml credentials when the challenge scheme matches what it sent.
@@ -141,7 +187,7 @@ class CodeArtifactMavenDockerIntegrationTest {
}
@Test
@Order(5)
@Order(7)
void concurrentFirstUseOfANewRepositoryOnlyProvisionsItOnce() throws InterruptedException {
given().contentType("application/json").header("Authorization", AUTH).body("{}")
.post("/v1/repository?domain=" + DOMAIN + "&repository=concurrent-repo")
@@ -186,7 +232,7 @@ class CodeArtifactMavenDockerIntegrationTest {
}
@Test
@Order(6)
@Order(8)
void recreatingASameNamedRepositoryDoesNotInheritThePreviousOnesArtifacts() {
given().contentType("application/json").header("Authorization", AUTH).body("{}")
.post("/v1/repository?domain=" + DOMAIN + "&repository=reused-name")
@@ -208,7 +254,7 @@ class CodeArtifactMavenDockerIntegrationTest {
}
@Test
@Order(7)
@Order(9)
void aRealMavenClientsBasicAuthCredentialsAreAcceptedWithTheTokenAsThePassword() {
String basic = "Basic " + Base64.getEncoder().encodeToString(("aws:" + bearerToken).getBytes(StandardCharsets.UTF_8));
byte[] content = "basic-auth-bytes".getBytes(StandardCharsets.UTF_8);
@@ -225,7 +271,7 @@ class CodeArtifactMavenDockerIntegrationTest {
}
@Test
@Order(8)
@Order(10)
void aDomainCreatedInANonDefaultRegionIsServedThroughTheTokensOwnRegionNotTheDefault() {
// The default region here is us-east-1 (application.yml). Every other test in this class
// creates its domain under an AUTH header whose SigV4 scope is also us-east-1, so those
@@ -259,7 +305,7 @@ class CodeArtifactMavenDockerIntegrationTest {
}
@Test
@Order(9)
@Order(11)
void aDomainCreatedUnderANonDefaultAccountIsServedThroughTheTokensOwnAccountNotTheDefault() {
// Every other test in this class authenticates as the default account (000000000000), so
// none of them would notice if the owner half of the token-scope fix regressed and every
@@ -291,7 +337,7 @@ class CodeArtifactMavenDockerIntegrationTest {
}
@Test
@Order(9)
@Order(11)
void deletingARepositoryReleasesItsStorageFromTheSharedReposiliteInstance() throws Exception {
given().contentType("application/json").header("Authorization", AUTH).body("{}")
.post("/v1/repository?domain=" + DOMAIN + "&repository=released-repo")
@@ -266,6 +266,74 @@ class ReposiliteSidecarClientTest {
assertThat(authHeader.get(), equalTo("Basic dGVzdDp0ZXN0"));
}
@Test
void deployArtifactShortCircuitsToTwoHundredWithoutPuttingWhenContentIsByteIdentical() {
byte[] content = "hello".getBytes(StandardCharsets.UTF_8);
List<String> methodsSeen = new CopyOnWriteArrayList<>();
server.createContext("/dom--repo/com/example/a/1.0/a-1.0.jar", exchange -> {
methodsSeen.add(exchange.getRequestMethod());
respond(exchange, 200, "hello");
});
int status = client.deployArtifact("dom--repo", "com/example/a/1.0/a-1.0.jar", content);
assertThat(status, is(200));
assertThat(methodsSeen, equalTo(List.of("GET")));
}
@Test
void deployArtifactStillPutsWhenExistingContentDiffers() {
AtomicReference<byte[]> putBody = new AtomicReference<>();
List<String> methodsSeen = new CopyOnWriteArrayList<>();
server.createContext("/dom--repo/com/example/a/1.0/a-1.0.jar", exchange -> {
methodsSeen.add(exchange.getRequestMethod());
if ("PUT".equals(exchange.getRequestMethod())) {
putBody.set(exchange.getRequestBody().readAllBytes());
// Reposilite's real redeployment:false response for a genuine content mismatch;
// this must pass straight through unchanged.
respond(exchange, 409, "{\"status\":409,\"message\":\"Redeployment is not allowed\"}");
} else {
respond(exchange, 200, "goodbye");
}
});
int status = client.deployArtifact("dom--repo", "com/example/a/1.0/a-1.0.jar",
"hello".getBytes(StandardCharsets.UTF_8));
assertThat(status, is(409));
assertThat(methodsSeen, equalTo(List.of("GET", "PUT")));
assertArrayEquals("hello".getBytes(StandardCharsets.UTF_8), putBody.get());
}
@Test
void deployArtifactStillPutsWhenThePreflightCheckFails() {
AtomicReference<byte[]> putBody = new AtomicReference<>();
List<String> methodsSeen = new CopyOnWriteArrayList<>();
server.createContext("/dom--repo/com/example/a/1.0/a-1.0.jar", exchange -> {
methodsSeen.add(exchange.getRequestMethod());
if ("PUT".equals(exchange.getRequestMethod())) {
putBody.set(exchange.getRequestBody().readAllBytes());
respond(exchange, 200, "");
} else {
// Simulates a dropped connection on the preflight GET (a timeout, a transient
// network error): closing without ever sending a response is what the client sees
// as an IOException, not a clean 4xx/5xx. The PUT must still go through. The JDK's
// own HttpClient transparently retries an idempotent GET once on this kind of
// connection-level failure before giving up, so more than one GET landing here
// first is expected and not itself part of what this test is checking.
exchange.close();
}
});
int status = client.deployArtifact("dom--repo", "com/example/a/1.0/a-1.0.jar",
"hello".getBytes(StandardCharsets.UTF_8));
assertThat(status, is(200));
assertTrue(methodsSeen.stream().allMatch(m -> m.equals("GET") || m.equals("PUT")));
assertThat(methodsSeen.get(methodsSeen.size() - 1), equalTo("PUT"));
assertArrayEquals("hello".getBytes(StandardCharsets.UTF_8), putBody.get());
}
@Test
void fetchArtifactReturnsBytesAndContentTypeOnSuccess() {
server.createContext("/dom--repo/com/example/a/1.0/a-1.0.jar", exchange -> {