feat(codeartifact): add DescribePackage for all package formats (#5308)

DescribePackage returns a package's format, namespace, name, and origin
controls, and answers ResourceNotFoundException for a package that does not
exist. Existence is checked where the package actually lives: stored
generic-format package versions for generic, and each format's sidecar for
maven, npm, and pypi. A package whose name merely starts with another's name
does not match it.

Origin controls are reported as publish ALLOW and upstream BLOCK, the default
CodeArtifact assigns to a package whose first version was published directly.
Floci never ingests packages from upstream and does not store origin controls,
so these values are fixed.

For maven, npm, and pypi the existence check starts that repository's sidecar
if it is not already running, the same side effect the asset bridge has.
RepositorySidecarManager gains packageExists, implemented by each sidecar client.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-08 07:49:38 -05:00
1 parent 5a8694e97a
commit e452ce8671
14 files changed
+299 -4

No files matched your search

@@ -182,6 +182,35 @@ class CodeArtifactIntegrationTest {
.then().statusCode(409).body("__type", equalTo("ConflictException"));
}
@Test
void describePackageReturnsTheDirectPublishOriginControlsAndReportsUnknownPackages() {
given().contentType("application/json").header("Authorization", AUTH)
.body("{}").post("/v1/domain?domain=describe-domain").then().statusCode(200);
given().contentType("application/json").header("Authorization", AUTH)
.body("{}").post("/v1/repository?domain=describe-domain&repository=repo").then().statusCode(200);
byte[] content = "describe".getBytes(StandardCharsets.UTF_8);
given().header("Authorization", AUTH).header("x-amz-content-sha256", sha256Hex(content))
.contentType("application/octet-stream").body(content)
.post("/v1/package/version/publish?domain=describe-domain&repository=repo&format=generic"
+ "&namespace=ns&package=my-pkg&version=1.0.0&asset=a.txt")
.then().statusCode(200);
given().header("Authorization", AUTH)
.get("/v1/package?domain=describe-domain&repository=repo&format=generic&namespace=ns"
+ "&package=my-pkg")
.then().statusCode(200)
.body("package.format", equalTo("generic"))
.body("package.namespace", equalTo("ns"))
.body("package.name", equalTo("my-pkg"))
.body("package.originConfiguration.restrictions.publish", equalTo("ALLOW"))
.body("package.originConfiguration.restrictions.upstream", equalTo("BLOCK"));
given().header("Authorization", AUTH)
.get("/v1/package?domain=describe-domain&repository=repo&format=generic&namespace=ns"
+ "&package=no-such-package")
.then().statusCode(404).body("__type", equalTo("ResourceNotFoundException"));
}
@Test
void unfinishedPublishKeepsVersionOpenForMoreAssets() {
given().contentType("application/json").header("Authorization", AUTH)
@@ -89,6 +89,13 @@ class CodeArtifactMavenDockerIntegrationTest {
given().header("Authorization", "Bearer " + bearerToken)
.head("/codeartifact/maven/" + DOMAIN + "/" + REPO + "/" + GAV)
.then().statusCode(200);
given().header("Authorization", AUTH)
.get("/v1/package?domain=" + DOMAIN + "&repository=" + REPO + "&format=maven"
+ "&namespace=com.example&package=spike")
.then().statusCode(200).body("package.name", equalTo("spike"))
.body("package.namespace", equalTo("com.example"))
.body("package.originConfiguration.restrictions.publish", equalTo("ALLOW"));
}
/**
@@ -147,6 +154,11 @@ class CodeArtifactMavenDockerIntegrationTest {
given().header("Authorization", "Bearer " + bearerToken)
.get("/codeartifact/maven/" + DOMAIN + "/no-such-repo/does/not/exist.jar")
.then().statusCode(404);
given().header("Authorization", AUTH)
.get("/v1/package?domain=" + DOMAIN + "&repository=" + REPO + "&format=maven"
+ "&namespace=com.example&package=does-not-exist")
.then().statusCode(404).body("__type", equalTo("ResourceNotFoundException"));
}
@Test
@@ -121,6 +121,11 @@ class CodeArtifactNpmDockerIntegrationTest {
.then().statusCode(200)
.extract().asByteArray();
assertArrayEquals(expectedTarballBytes, fetchedTarball);
given().header("Authorization", AUTH)
.get("/v1/package?domain=" + DOMAIN + "&repository=" + REPO + "&format=npm&package=" + PACKAGE_NAME)
.then().statusCode(200).body("package.name", equalTo(PACKAGE_NAME))
.body("package.originConfiguration.restrictions.publish", equalTo("ALLOW"));
}
/**
@@ -150,6 +155,10 @@ class CodeArtifactNpmDockerIntegrationTest {
given().header("Authorization", "Bearer " + bearerToken)
.get("/codeartifact/npm/" + DOMAIN + "/no-such-repo/does-not-exist")
.then().statusCode(404);
given().header("Authorization", AUTH)
.get("/v1/package?domain=" + DOMAIN + "&repository=" + REPO + "&format=npm&package=does-not-exist")
.then().statusCode(404).body("__type", equalTo("ResourceNotFoundException"));
}
@Test
@@ -95,6 +95,11 @@ class CodeArtifactPypiDockerIntegrationTest {
.then().statusCode(200)
.extract().asByteArray();
assertEquals(new String(content, StandardCharsets.UTF_8), new String(fetched, StandardCharsets.UTF_8));
given().header("Authorization", AUTH)
.get("/v1/package?domain=" + DOMAIN + "&repository=" + REPO + "&format=pypi&package=" + PACKAGE_NAME)
.then().statusCode(200).body("package.name", equalTo(PACKAGE_NAME))
.body("package.originConfiguration.restrictions.publish", equalTo("ALLOW"));
}
/**
@@ -148,6 +153,10 @@ class CodeArtifactPypiDockerIntegrationTest {
given().header("Authorization", "Bearer " + bearerToken)
.get("/codeartifact/pypi/" + DOMAIN + "/no-such-repo/simple/does-not-exist/")
.then().statusCode(404);
given().header("Authorization", AUTH)
.get("/v1/package?domain=" + DOMAIN + "&repository=" + REPO + "&format=pypi&package=does-not-exist")
.then().statusCode(404).body("__type", equalTo("ResourceNotFoundException"));
}
@Test
@@ -1006,6 +1006,73 @@ class CodeArtifactServiceTest {
assertEquals("ResourceNotFoundException", e.getErrorCode());
}
@Test
void describePackageReportsTheDirectPublishDefaultsAndMatchesExactly() {
service.createDomain(REGION, "dom", null, Map.of());
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
byte[] content = "x".getBytes(StandardCharsets.UTF_8);
service.publishPackageVersion(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "1.0.0", "a.txt",
sha256Hex(content), "false", content);
service.publishPackageVersion(REGION, "dom", null, "repo", "generic", "ns", "my::pkg", "1.0.0", "a.txt",
sha256Hex(content), "false", content);
CodeArtifactService.PackageDescription described = service.describePackage(REGION, "dom", null, "repo",
"generic", "ns", "my-pkg");
assertEquals("generic", described.format());
assertEquals("ns", described.namespace());
assertEquals("my-pkg", described.packageName());
assertEquals("ALLOW", described.publishRestriction());
assertEquals("BLOCK", described.upstreamRestriction());
AwsException prefixOfAnotherPackage = assertThrows(AwsException.class, () -> service.describePackage(REGION,
"dom", null, "repo", "generic", "ns", "my"));
assertEquals("ResourceNotFoundException", prefixOfAnotherPackage.getErrorCode());
AwsException wrongNamespace = assertThrows(AwsException.class, () -> service.describePackage(REGION, "dom",
null, "repo", "generic", "other", "my-pkg"));
assertEquals("ResourceNotFoundException", wrongNamespace.getErrorCode());
}
@Test
void describePackageValidatesPackageAndNamespaceShapeBeforeTouchingRepositoryState() {
AwsException badPackageName = assertThrows(AwsException.class, () -> service.describePackage(REGION,
"no-such-domain", null, "repo", "generic", "ns", "has/slash"));
assertEquals("ValidationException", badPackageName.getErrorCode());
service.createDomain(REGION, "dom", null, Map.of());
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
AwsException badNamespace = assertThrows(AwsException.class, () -> service.describePackage(REGION, "dom",
null, "repo", "generic", "has#hash", "my-pkg"));
assertEquals("ValidationException", badNamespace.getErrorCode());
AwsException missingNamespaceForGeneric = assertThrows(AwsException.class, () -> service.describePackage(
REGION, "dom", null, "repo", "generic", null, "my-pkg"));
assertEquals("ValidationException", missingNamespaceForGeneric.getErrorCode());
AwsException missingNamespaceForMaven = assertThrows(AwsException.class, () -> service.describePackage(
REGION, "dom", null, "repo", "maven", null, "my-artifact"));
assertEquals("ValidationException", missingNamespaceForMaven.getErrorCode());
}
/**
* pypi packages have no namespace at all (confirmed against the API reference): the sidecar
* check genuinely ignores whatever namespace is supplied, so without this rejection the response
* would echo a namespace back as if it were real, describing a package that does not exist the
* way the caller asked.
*/
@Test
void describePackageRejectsANamespaceSuppliedForPypiRatherThanEchoingAFabricatedOne() {
service.createDomain(REGION, "dom", null, Map.of());
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
when(pypiserverClient.packageExists(anyString(), eq("dom"), eq("repo"), isNull(), eq("real-pkg")))
.thenReturn(true);
AwsException e = assertThrows(AwsException.class, () -> service.describePackage(REGION, "dom", null, "repo",
"pypi", "bogus-namespace", "real-pkg"));
assertEquals("ValidationException", e.getErrorCode());
}
@Test
void getPackageVersionAssetReturnsExactBytesAndValidatesRevision() {
service.createDomain(REGION, "dom", null, Map.of());
@@ -561,6 +561,23 @@ class ReposiliteSidecarClientTest {
assertFalse(client.artifactExists("dom--repo", "absent.jar"));
}
@Test
void packageExistsReflectsAGetResponseOnTheGroupArtifactDirectory() {
server.createContext("/dom--repo/com/example/present/", exchange -> respond(exchange, 200, ""));
server.createContext("/dom--repo/com/example/absent/", exchange -> respond(exchange, 404, ""));
assertTrue(client.packageExists("dom--repo", "dom", "repo", "com.example", "present"));
assertFalse(client.packageExists("dom--repo", "dom", "repo", "com.example", "absent"));
}
@Test
void packageExistsThrowsRatherThanReportingAbsentOnASidecarServerError() {
server.createContext("/dom--repo/com/example/broken/", exchange -> respond(exchange, 500, ""));
assertThrows(IllegalStateException.class, () -> client.packageExists("dom--repo", "dom", "repo",
"com.example", "broken"));
}
private static void respond(HttpExchange exchange, int status, String body) throws IOException {
byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
exchange.sendResponseHeaders(status, bytes.length);