feat(codeartifact): add ListPackageVersionAssets for every format (#5962)

Lists a package version's assets with size and SHA-256 hash, for generic
(from its own packageVersions record) and maven/npm/pypi/nuget (bridged to
each sidecar, reusing the listPackageVersionAssetNames/fetchPackageVersionAsset
primitives CopyPackageVersions already built). Confirmed live against all
four sidecars with Docker-gated tests; real AWS places no format restriction
on this action either.

First of the six list/lifecycle actions (item 10 in the design plan).

Fixes caught by Qodo's review after opening the PR, verified against the
wire model and the sidecar code before applying: the endpoint was registered
as GET, but real CodeArtifact's ListPackageVersionAssets is a bodyless POST
with query parameters, like every other List* action in this service (the
Describe*/Get* actions are the ones that use GET) - switched the controller
and its Docker-gated tests to POST. Also stopped fetching and hashing every
asset in a container-backed version before paginating: asset names are now
paginated first, and only the page actually being returned gets fetched and
hashed. Added regression tests for the validation paths (missing fields,
invalid format, and namespace requirements) that had none.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-18 20:43:44 -05:00
1 parent 9c205f7654
commit 6027872078
9 files changed
+403 -8

No files matched your search

@@ -1,10 +1,12 @@
package io.github.hectorvent.floci.services.codeartifact;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.Digests;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.github.hectorvent.floci.testing.SidecarContainersProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.path.json.JsonPath;
import jakarta.inject.Inject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
@@ -18,6 +20,7 @@ import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -545,6 +548,28 @@ class CodeArtifactMavenDockerIntegrationTest {
assertEquals("new-overwrite-jar-bytes", new String(copied, StandardCharsets.UTF_8));
}
/**
* The real-world gap this closes: {@code ListPackageVersionAssets} used to not exist at all.
* Confirms the bridge enumerates {@link #GAV}'s own version directory against the real
* Reposilite sidecar (not a mock) and reports the exact byte size and hash of the asset
* already deployed to it in {@link #deployThenFetchRoundTripsTheExactBytes}.
*/
@Test
@Order(20)
void listPackageVersionAssetsBridgesToTheRealReposiliteSidecar() {
JsonPath body = given().header("Authorization", AUTH)
.post("/v1/package/version/assets?domain=" + DOMAIN + "&repository=" + REPO + "&format=maven"
+ "&namespace=com.example&package=spike&version=1.0.0")
.then().statusCode(200)
.body("package", equalTo("spike"))
.body("assets.size()", equalTo(1))
.body("assets[0].name", equalTo("spike-1.0.0.jar"))
.body("assets[0].size", equalTo("real-jar-bytes".getBytes(StandardCharsets.UTF_8).length))
.extract().jsonPath();
Map<String, String> hashes = body.getMap("assets[0].hashes");
assertEquals(Digests.sha256Hex("real-jar-bytes".getBytes(StandardCharsets.UTF_8)), hashes.get("SHA-256"));
}
/**
* A throwaway groupId/artifactId, not {@link #GAV}: deleting it exercises Reposilite's real
* directory delete (confirmed live before this was built: a single {@code DELETE} on the
@@ -3,11 +3,13 @@ package io.github.hectorvent.floci.services.codeartifact;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.Digests;
import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.github.hectorvent.floci.testing.SidecarContainersProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.path.json.JsonPath;
import jakarta.inject.Inject;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.BeforeAll;
@@ -20,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -744,6 +747,28 @@ class CodeArtifactNpmDockerIntegrationTest {
+ copiedVersion.path("dist").path("tarball").asText());
}
/**
* The real-world gap this closes: {@code ListPackageVersionAssets} used to not exist at all.
* Confirms the bridge enumerates npm's one-asset-per-version packument entry against the real
* Verdaccio sidecar (not a mock) and reports the exact byte size and hash of the tarball
* already published in {@link #publishThenFetchRoundTripsTheRealNpmEnvelope}.
*/
@Test
@Order(20)
void listPackageVersionAssetsBridgesToTheRealVerdaccioSidecar() {
JsonPath body = given().header("Authorization", AUTH)
.post("/v1/package/version/assets?domain=" + DOMAIN + "&repository=" + REPO + "&format=npm"
+ "&package=" + PACKAGE_NAME + "&version=1.0.0")
.then().statusCode(200)
.body("package", equalTo(PACKAGE_NAME))
.body("assets.size()", equalTo(1))
.body("assets[0].name", equalTo(PACKAGE_NAME + "-1.0.0.tgz"))
.body("assets[0].size", equalTo(expectedTarballBytes.length))
.extract().jsonPath();
Map<String, String> hashes = body.getMap("assets[0].hashes");
assertEquals(Digests.sha256Hex(expectedTarballBytes), hashes.get("SHA-256"));
}
/**
* Proves the actual mechanism, not just that {@code VerdaccioSidecarManager} has a method
* named right: {@code ContainerTeardowns.stopAll} runs every {@code ContainerTeardown} on
@@ -1,9 +1,11 @@
package io.github.hectorvent.floci.services.codeartifact;
import io.github.hectorvent.floci.core.common.Digests;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.github.hectorvent.floci.testing.SidecarContainersProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.path.json.JsonPath;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
@@ -13,6 +15,7 @@ import org.junit.jupiter.api.TestMethodOrder;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@@ -423,6 +426,41 @@ class CodeArtifactNuGetDockerIntegrationTest {
assertArrayEquals(newNupkg, copied);
}
/**
* The real-world gap this closes: {@code ListPackageVersionAssets} used to not exist at all.
* Confirms the bridge enumerates NuGet's one-asset-per-version flat container against the
* real BaGetter sidecar (not a mock) and reports the exact byte size and hash of a freshly
* pushed {@code .nupkg}. Self-contained, own package id, rather than reusing {@link
* #PACKAGE_ID}: that fixture is re-pushed by {@link
* #deletePackageRemovesTheFileFromTheRealBagetterSidecarAndAllowsARepublish} with a freshly
* built (not necessarily byte-identical) zip, so asserting against it here would depend on
* exactly what that unrelated test last wrote.
*/
@Test
@Order(15)
void listPackageVersionAssetsBridgesToTheRealBagetterSidecar() {
String packageId = "ListAssets.Package";
String lowerId = packageId.toLowerCase(Locale.ROOT);
byte[] nupkg = buildNupkg(packageId, VERSION, "list assets description", null, null);
given().header("Authorization", "Bearer " + bearerToken)
.contentType("multipart/form-data; boundary=boundary123")
.body(pushBody("boundary123", nupkg))
.put("/codeartifact/nuget/" + DOMAIN + "/" + REPO + "/api/v2/package")
.then().statusCode(201);
JsonPath body = given().header("Authorization", AUTH)
.post("/v1/package/version/assets?domain=" + DOMAIN + "&repository=" + REPO + "&format=nuget"
+ "&package=" + packageId + "&version=" + VERSION)
.then().statusCode(200)
.body("package", equalTo(packageId))
.body("assets.size()", equalTo(1))
.body("assets[0].name", equalTo(lowerId + "." + VERSION + ".nupkg"))
.body("assets[0].size", equalTo(nupkg.length))
.extract().jsonPath();
Map<String, String> hashes = body.getMap("assets[0].hashes");
assertEquals(Digests.sha256Hex(nupkg), hashes.get("SHA-256"));
}
private static long describeDomainAssetSizeBytes() {
return given().header("Authorization", AUTH)
.get("/v1/domain?domain=" + DOMAIN)
@@ -1,11 +1,13 @@
package io.github.hectorvent.floci.services.codeartifact;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.Digests;
import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.github.hectorvent.floci.testing.SidecarContainersProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.path.json.JsonPath;
import jakarta.inject.Inject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
@@ -17,6 +19,7 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -615,6 +618,39 @@ class CodeArtifactPypiDockerIntegrationTest {
assertEquals("new-multi-pypi-wheel", new String(copiedWheel, StandardCharsets.UTF_8));
}
/**
* The real-world gap this closes: {@code ListPackageVersionAssets} used to not exist at all.
* Confirms the bridge enumerates pypi's one-asset-per-version simple index entry against the
* real pypiserver sidecar (not a mock) and reports the exact byte size and hash of a freshly
* uploaded file. A throwaway package, not {@link #PACKAGE_NAME}: {@link
* #deletePackageRemovesTheFileFromTheRealPypiserverSidecar} deletes that fixture for good with
* no republish afterward, unlike this format's sibling test classes.
*/
@Test
@Order(18)
void listPackageVersionAssetsBridgesToTheRealPypiserverSidecar() {
String packageName = "list-assets-pypi-pkg";
String filename = "list_assets_pypi_pkg-1.0.0.tar.gz";
byte[] content = "list-assets-sdist-bytes".getBytes(StandardCharsets.UTF_8);
given().header("Authorization", "Bearer " + bearerToken)
.contentType("multipart/form-data; boundary=boundary123")
.body(twineUploadBody("boundary123", packageName, filename, content))
.post("/codeartifact/pypi/" + DOMAIN + "/" + REPO + "/")
.then().statusCode(200);
JsonPath body = given().header("Authorization", AUTH)
.post("/v1/package/version/assets?domain=" + DOMAIN + "&repository=" + REPO + "&format=pypi"
+ "&package=" + packageName + "&version=1.0.0")
.then().statusCode(200)
.body("package", equalTo(packageName))
.body("assets.size()", equalTo(1))
.body("assets[0].name", equalTo(filename))
.body("assets[0].size", equalTo(content.length))
.extract().jsonPath();
Map<String, String> hashes = body.getMap("assets[0].hashes");
assertEquals(Digests.sha256Hex(content), hashes.get("SHA-256"));
}
/**
* Proves the actual mechanism, not just that {@code PypiserverSidecarManager} has a method
* named right: {@code ContainerTeardowns.stopAll} runs every {@code ContainerTeardown} on
@@ -3102,6 +3102,155 @@ class CodeArtifactServiceTest {
assertEquals("package-version", wrongRevision.getExtendedData().get("resourceType"));
}
// ------------------------------------------------------ ListPackageVersionAssets
@Test
void listPackageVersionAssetsReturnsEveryAssetForAGenericVersion() {
service.createDomain(REGION, "dom", null, Map.of());
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
byte[] content = "generic-asset-bytes".getBytes(StandardCharsets.UTF_8);
publishGeneric("repo", "my-pkg", "1.0.0", content);
CodeArtifactService.PackageVersionAssetsListResult result = service.listPackageVersionAssets(REGION, "dom",
null, "repo", "generic", "ns", "my-pkg", "1.0.0", null, null);
assertEquals(1, result.assets().size());
assertEquals("a.txt", result.assets().get(0).name());
assertEquals(content.length, result.assets().get(0).size());
assertEquals(Digests.sha256Hex(content), result.assets().get(0).hashes().get("SHA-256"));
assertTrue(result.versionRevision() != null && !result.versionRevision().isBlank());
}
@Test
void listPackageVersionAssetsFailsNotFoundForAGenericVersionThatWasNeverPublished() {
service.createDomain(REGION, "dom", null, Map.of());
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
AwsException e = assertThrows(AwsException.class, () -> service.listPackageVersionAssets(REGION, "dom",
null, "repo", "generic", "ns", "my-pkg", "1.0.0", null, null));
assertEquals("ResourceNotFoundException", e.getErrorCode());
}
@Test
void listPackageVersionAssetsPaginatesGenericAssets() {
service.createDomain(REGION, "dom", null, Map.of());
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
service.publishPackageVersion(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "1.0.0", "a.txt",
Digests.sha256Hex("a".getBytes(StandardCharsets.UTF_8)), "true",
"a".getBytes(StandardCharsets.UTF_8));
service.publishPackageVersion(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "1.0.0", "b.txt",
Digests.sha256Hex("b".getBytes(StandardCharsets.UTF_8)), "true",
"b".getBytes(StandardCharsets.UTF_8));
CodeArtifactService.PackageVersionAssetsListResult page1 = service.listPackageVersionAssets(REGION, "dom",
null, "repo", "generic", "ns", "my-pkg", "1.0.0", 1, null);
assertEquals(1, page1.assets().size());
assertTrue(page1.nextToken() != null);
CodeArtifactService.PackageVersionAssetsListResult page2 = service.listPackageVersionAssets(REGION, "dom",
null, "repo", "generic", "ns", "my-pkg", "1.0.0", 1, page1.nextToken());
assertEquals(1, page2.assets().size());
assertTrue(page2.nextToken() == null);
assertTrue(!page1.assets().get(0).name().equals(page2.assets().get(0).name()));
}
@Test
void listPackageVersionAssetsBridgesToReposiliteForMaven() {
service.createDomain(REGION, "dom", null, Map.of());
CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
String repoId = created.getSidecarContainerIds().get("maven");
byte[] jarBytes = "jar-bytes".getBytes(StandardCharsets.UTF_8);
byte[] pomBytes = "pom-bytes".getBytes(StandardCharsets.UTF_8);
when(reposiliteClient.packageVersionExists(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
eq("a"), eq("1.0"))).thenReturn(true);
when(reposiliteClient.listPackageVersionAssetNames(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
eq("a"), eq("1.0"))).thenReturn(List.of("a-1.0.jar", "a-1.0.pom"));
when(reposiliteClient.fetchPackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
eq("a"), eq("1.0"), eq("a-1.0.jar"))).thenReturn(Optional.of(jarBytes));
when(reposiliteClient.fetchPackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
eq("a"), eq("1.0"), eq("a-1.0.pom"))).thenReturn(Optional.of(pomBytes));
CodeArtifactService.PackageVersionAssetsListResult result = service.listPackageVersionAssets(REGION, "dom",
null, "repo", "maven", "com.example", "a", "1.0", null, null);
assertEquals(2, result.assets().size());
assertEquals("a-1.0.jar", result.assets().get(0).name());
assertEquals(jarBytes.length, result.assets().get(0).size());
assertEquals(Digests.sha256Hex(jarBytes), result.assets().get(0).hashes().get("SHA-256"));
}
@Test
void listPackageVersionAssetsFailsNotFoundForAMavenVersionThatWasNeverPublished() {
service.createDomain(REGION, "dom", null, Map.of());
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
AwsException e = assertThrows(AwsException.class, () -> service.listPackageVersionAssets(REGION, "dom",
null, "repo", "maven", "com.example", "a", "1.0", null, null));
assertEquals("ResourceNotFoundException", e.getErrorCode());
}
@Test
void listPackageVersionAssetsRoutesEveryContainerBackedFormatToTheSidecarBridge() {
service.createDomain(REGION, "dom", null, Map.of());
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
for (String format : List.of("npm", "pypi", "nuget")) {
AwsException e = assertThrows(AwsException.class, () -> service.listPackageVersionAssets(REGION, "dom",
null, "repo", format, null, "my-pkg", "1.0.0", null, null));
assertEquals("ResourceNotFoundException", e.getErrorCode());
}
}
@Test
void listPackageVersionAssetsRejectsAFormatAwsDoesNotSupport() {
service.createDomain(REGION, "dom", null, Map.of());
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
AwsException e = assertThrows(AwsException.class, () -> service.listPackageVersionAssets(REGION, "dom",
null, "repo", "not-a-real-format", null, "my-pkg", "1.0.0", null, null));
assertEquals("ValidationException", e.getErrorCode());
}
@Test
void listPackageVersionAssetsRequiresANamespaceForMaven() {
service.createDomain(REGION, "dom", null, Map.of());
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
AwsException e = assertThrows(AwsException.class, () -> service.listPackageVersionAssets(REGION, "dom",
null, "repo", "maven", null, "a", "1.0", null, null));
assertEquals("ValidationException", e.getErrorCode());
}
@Test
void listPackageVersionAssetsRejectsANamespaceForPypiAndNuGet() {
service.createDomain(REGION, "dom", null, Map.of());
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
for (String format : List.of("pypi", "nuget")) {
AwsException e = assertThrows(AwsException.class, () -> service.listPackageVersionAssets(REGION, "dom",
null, "repo", format, "a-namespace", "my-pkg", "1.0.0", null, null));
assertEquals("ValidationException", e.getErrorCode());
}
}
@Test
void listPackageVersionAssetsRequiresDomainRepositoryAndVersion() {
service.createDomain(REGION, "dom", null, Map.of());
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
AwsException missingDomain = assertThrows(AwsException.class, () -> service.listPackageVersionAssets(REGION,
null, null, "repo", "generic", "ns", "my-pkg", "1.0.0", null, null));
assertEquals("ValidationException", missingDomain.getErrorCode());
AwsException missingRepository = assertThrows(AwsException.class, () -> service.listPackageVersionAssets(
REGION, "dom", null, null, "generic", "ns", "my-pkg", "1.0.0", null, null));
assertEquals("ValidationException", missingRepository.getErrorCode());
AwsException missingVersion = assertThrows(AwsException.class, () -> service.listPackageVersionAssets(REGION,
"dom", null, "repo", "generic", "ns", "my-pkg", null, null, null));
assertEquals("ValidationException", missingVersion.getErrorCode());
}
// ---------------------------------------------------------- GetPackageVersionReadme
@Test