test(codeartifact): pin the Maven proxy's cross-account token scoping (#4158)

Every existing Maven-proxy test authenticates as the default account, so
none of them would notice a regression that dropped the token's owner back
to the default account instead of the domain's real one. Adds a test under
a distinct 12-digit account that would fail on that regression (verified by
reverting the fix locally: only this test goes red).

Also replaces an inline org.hamcrest.Matchers.startsWith reference with a
static import to match the rest of the file.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-09-22 20:01:21 -05:00
1 parent 5c72502551
commit a459dedd43
1 file changed
+34 -1
@@ -18,6 +18,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -113,7 +114,7 @@ class CodeArtifactMavenDockerIntegrationTest {
// configured settings.xml credentials when the challenge scheme matches what it sent.
given().get("/codeartifact/maven/" + DOMAIN + "/" + REPO + "/" + GAV)
.then().statusCode(401)
.header("WWW-Authenticate", org.hamcrest.Matchers.startsWith("Basic"));
.header("WWW-Authenticate", startsWith("Basic"));
given().header("Authorization", "Bearer not-a-real-token")
.get("/codeartifact/maven/" + DOMAIN + "/" + REPO + "/" + GAV)
@@ -249,4 +250,36 @@ class CodeArtifactMavenDockerIntegrationTest {
.extract().asByteArray();
assertEquals(new String(content, StandardCharsets.UTF_8), new String(fetched, StandardCharsets.UTF_8));
}
@Test
@Order(9)
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
// Maven request fell back to the default account instead of the domain's real one.
String otherAccountAuth = "AWS4-HMAC-SHA256 Credential=111122223333/20260904/us-east-1/codeartifact/aws4_request";
String domain = "maven-sidecar-cross-account-domain";
given().contentType("application/json").header("Authorization", otherAccountAuth).body("{}")
.post("/v1/domain?domain=" + domain)
.then().statusCode(200);
given().contentType("application/json").header("Authorization", otherAccountAuth).body("{}")
.post("/v1/repository?domain=" + domain + "&repository=" + REPO)
.then().statusCode(200);
String token = given().header("Authorization", otherAccountAuth)
.post("/v1/authorization-token?domain=" + domain)
.then().statusCode(200)
.extract().jsonPath().getString("authorizationToken");
byte[] content = "cross-account-bytes".getBytes(StandardCharsets.UTF_8);
given().header("Authorization", "Bearer " + token).body(content)
.put("/codeartifact/maven/" + domain + "/" + REPO + "/" + GAV)
.then().statusCode(200);
byte[] fetched = given().header("Authorization", "Bearer " + token)
.get("/codeartifact/maven/" + domain + "/" + REPO + "/" + GAV)
.then().statusCode(200)
.extract().asByteArray();
assertEquals(new String(content, StandardCharsets.UTF_8), new String(fetched, StandardCharsets.UTF_8));
}
}