Light, fluffy, and always free - The AWS Local Emulator alternative
feat(codeartifact): add ListPackageVersionAssets for every format (#5962)
Priamo Germosen60278720782b
diff --git a/docs/services/codeartifact.md b/docs/services/codeartifact.mdindex 674763dc9e..ec6a1008d8 100644--- a/docs/services/codeartifact.md+++ b/docs/services/codeartifact.md@@ -44,6 +44,7 @@ behind them yet.| `PutPackageOriginConfiguration` | Sets a package's `publish`/`upstream` origin-control restrictions; can create the package (with no versions) if it doesn't exist yet. || `DescribePackageVersion` | Returns a package version's status, revision, and origin. || `GetPackageVersionAsset` | Downloads one asset from a package version by name, optionally pinned to a specific revision. |+| `ListPackageVersionAssets` | Lists the assets of a package version, with size and hashes. || `GetPackageVersionReadme` | Returns the readme text for a package version; `npm`, `pypi`, and `nuget` only, matching AWS's own restriction for this action. || `CopyPackageVersions` | Copies one or more versions of a package from one repository to another in the same domain. || `TagResource` | Adds or updates tags on a domain or repository ARN. |@@ -252,11 +253,11 @@ state.that is not the caller's own account looks up that account's domain/repository with notrust-policy or permissions-policy enforcement, consistent with Floci's IAM enforcement beingopt-in elsewhere, but worth knowing if you rely on domain-sharing semantics.-- **Package management beyond publish/describe/get-asset isn't implemented.** `ListPackages`,- `ListPackageVersions`, `ListPackageVersionAssets`, `DeletePackageVersions`,- `DisposePackageVersions`, and `UpdatePackageVersionsStatus` don't exist yet; the only way to- move a version from `Unfinished` to `Published` today is a follow-up `PublishPackageVersion`- call that omits the `unfinished` flag.+- **Package management beyond publish/describe/get-asset/list-assets isn't implemented.**+ `ListPackages`, `ListPackageVersions`, `DeletePackageVersions`, `DisposePackageVersions`, and+ `UpdatePackageVersionsStatus` don't exist yet; the only way to move a version from `Unfinished`+ to `Published` today is a follow-up `PublishPackageVersion` call that omits the `unfinished`+ flag.- **`CopyPackageVersions` has no full cross-call rollback on a mid-copy sidecar failure.**(`generic`, `maven`, `npm`, `pypi`, and `nuget` are all supported — matching real AWS, whichplaces no `format` restriction on this action at all, unlike `PublishPackageVersion`'s owndiff --git a/docs/services/index.md b/docs/services/index.mdindex a893cec561..6891f2e7b8 100644--- a/docs/services/index.md+++ b/docs/services/index.md@@ -122,7 +122,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac| [AWS Backup](backup.md) | `/backup-vaults/*`, `/backup/plans/*`, `/backup-jobs/*`, `/supported-resource-types` | REST JSON | 20 || [AWS FIS](fis.md) | `/experimentTemplates/*`, `/experiments/*`, `/actions/*`, `/targetResourceTypes/*`, `/safetyLevers/*`, `/tags/*` | REST JSON | 26 || [CodeGuru Reviewer](codegurureviewer.md) | `/associations`, `/associations/{associationArn}`, `/tags/*` | REST JSON | 7 |-| [CodeArtifact](codeartifact.md) | `/v1/domain*`, `/v1/repository*`, `/v1/package`, `/v1/package/version*`, `/v1/tag*`, `/v1/authorization-token`, `/codeartifact/maven/*`, `/codeartifact/npm/*`, `/codeartifact/pypi/*` | REST JSON | 31 |+| [CodeArtifact](codeartifact.md) | `/v1/domain*`, `/v1/repository*`, `/v1/package`, `/v1/package/version*`, `/v1/tag*`, `/v1/authorization-token`, `/codeartifact/maven/*`, `/codeartifact/npm/*`, `/codeartifact/pypi/*` | REST JSON | 32 || [CloudFront](cloudfront.md) | `/2020-05-31/distribution/*`, `/2020-05-31/cache-policy/*`, `/2020-05-31/function/*` | REST XML | 50 || [Route53](route53.md) | `/2013-04-01/hostedzone/*`, `/2013-04-01/healthcheck/*`, `/2013-04-01/change/*` | REST XML | 27 || [Route 53 Resolver](route53resolver.md) | `POST /` + `X-Amz-Target: Route53Resolver.*` | JSON 1.1 | 19 |diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactController.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactController.javaindex 8a4e3d27c0..f9dca03c84 100644--- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactController.java+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactController.java@@ -414,6 +414,44 @@ public class CodeArtifactController {.build();}+ @POST+ @Path("/v1/package/version/assets")+ @Consumes(MediaType.WILDCARD)+ public Response listPackageVersionAssets(@Context HttpHeaders headers, @QueryParam("domain") String domain,+ @QueryParam("domain-owner") String domainOwner,+ @QueryParam("repository") String repository,+ @QueryParam("format") String format,+ @QueryParam("namespace") String namespace,+ @QueryParam("package") String packageName,+ @QueryParam("version") String version,+ @QueryParam("max-results") String maxResults,+ @QueryParam("next-token") String nextToken) {+ String region = regionResolver.resolveRegion(headers);+ CodeArtifactService.PackageVersionAssetsListResult result = service.listPackageVersionAssets(region, domain,+ domainOwner, repository, format, namespace, packageName, version,+ Pagination.parseMaxResults(maxResults, "ValidationException"), nextToken);+ ObjectNode response = objectMapper.createObjectNode();+ response.put("format", result.format());+ if (result.namespace() != null) {+ response.put("namespace", result.namespace());+ }+ response.put("package", result.packageName());+ response.put("version", result.version());+ response.put("versionRevision", result.versionRevision());+ ArrayNode assets = response.putArray("assets");+ result.assets().forEach(asset -> {+ ObjectNode node = assets.addObject();+ node.put("name", asset.name());+ node.put("size", asset.size());+ ObjectNode hashes = node.putObject("hashes");+ asset.hashes().forEach(hashes::put);+ });+ if (result.nextToken() != null) {+ response.put("nextToken", result.nextToken());+ }+ return ok(response);+ }+@GET@Path("/v1/package/version/readme")public Response getPackageVersionReadme(@Context HttpHeaders headers, @QueryParam("domain") String domain,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.javaindex 65c4e99116..45e6de6da6 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@@ -50,6 +50,7 @@ import java.util.Set;import java.util.UUID;import java.util.concurrent.ConcurrentHashMap;import java.util.concurrent.atomic.AtomicLong;+import java.util.function.Function;import java.util.regex.Pattern;import java.util.stream.Stream;@@ -134,6 +135,9 @@ public class CodeArtifactService implements Resettable {public record PackageVersionCopyFailure(String errorCode, String errorMessage) {}public record CopyPackageVersionsResult(Map<String, PackageVersionCopyOutcome> successfulVersions,Map<String, PackageVersionCopyFailure> failedVersions) {}+ public record AssetSummary(String name, long size, Map<String, String> hashes) {}+ public record PackageVersionAssetsListResult(String format, String namespace, String packageName,+ String version, String versionRevision, List<AssetSummary> assets, String nextToken) {}public record AuthorizationToken(String token, long expirationEpochSeconds) {}public record AuthorizationTokenScope(String owner, String region) {}private record AuthorizationTokenRecord(String owner, String region, String domain, Instant expiration) {}@@ -801,11 +805,90 @@ public class CodeArtifactService implements Resettable {+ "' was not found.", version, "package-version"));}+ /**+ * Lists every asset of one package version. For {@code generic}, reads straight from the+ * version's own stored {@link PackageAsset} map, the same source {@link+ * #getPackageVersionAsset} and {@link #copyGenericPackageVersionAssets} already trust.+ * Container-backed formats have no such record (same reason {@link #describePackageVersion}+ * bridges them), so this reuses {@link RepositorySidecarManager#listPackageVersionAssetNames}+ * ({@code CopyPackageVersions}' own enumeration primitive) and fetches each one to compute its+ * size and hash, the same way {@link #getContainerBackedPackageVersionAsset} already computes+ * a single asset's hash on the fly rather than trusting a stored value that doesn't exist.+ *+ * <p>{@code npm}/{@code pypi}/{@code nuget} genuinely have exactly one asset per version+ * (confirmed by {@link RepositorySidecarManager#listPackageVersionAssetNames}'s own+ * implementations for those three); only {@code maven} and {@code generic} can return more+ * than one.+ *+ * <p>For a container-backed format, only the names are enumerated up front; {@code+ * maxResults}/{@code nextToken} are applied to that name list before any byte is fetched, so+ * a page request only ever downloads and hashes the assets it actually returns, not every+ * asset the version has.+ */+ public PackageVersionAssetsListResult listPackageVersionAssets(String region, String domain, String domainOwner,+ String repository, String format, String namespace, String packageName, String version,+ Integer maxResults, String nextToken) {+ validatePackageCoordinates(format, namespace, packageName, "listing the assets of");+ requireNonBlank(domain, "domain");+ requireNonBlank(repository, "repository");+ requireNonBlank(version, "packageVersion");+ validatePackageToken("packageVersion", version);+ String owner = effectiveOwner(domainOwner);+ requireRepository(owner, repositoryKey(region, domain, repository), repository);++ PaginatedResult<AssetSummary> page;+ String revision;+ if (CONTAINER_BACKED_FORMATS.contains(format)) {+ String repoId = ensureFormatContainerId(format, region, domain, owner, repository);+ RepositorySidecarManager manager = sidecarRegistry.forFormat(format)+ .orElseThrow(() -> notFound("Package version '" + version + "' of package '" + packageName+ + "' was not found.", version, "package-version"));+ if (!manager.packageVersionExists(repoId, domain, repository, namespace, packageName, version)) {+ throw notFound("Package version '" + version + "' of package '" + packageName+ + "' was not found.", version, "package-version");+ }+ List<String> assetNames;+ try {+ assetNames = manager.listPackageVersionAssetNames(repoId, domain, repository, namespace,+ packageName, version);+ } catch (UnsupportedOperationException e) {+ throw new AwsException("InternalServerException", "Listing a " + format + " package version's "+ + "assets is not yet supported by this emulator.", 500);+ }+ PaginatedResult<String> namePage = Pagination.paginate(assetNames, Function.identity(), maxResults,+ nextToken, 100, 1000, "ValidationException");+ List<AssetSummary> pageAssets = new ArrayList<>();+ for (String assetName : namePage.items()) {+ byte[] content = manager.fetchPackageVersionAsset(repoId, domain, repository, namespace,+ packageName, version, assetName)+ .orElseThrow(() -> new AwsException("InternalServerException", "Could not list version '"+ + version + "' of package '" + packageName + "': its asset '" + assetName+ + "' disappeared between listing and fetching it.", 500));+ pageAssets.add(new AssetSummary(assetName, content.length, computeHashes(content)));+ }+ page = new PaginatedResult<>(pageAssets, namePage.nextToken());+ revision = synthesizeContainerBackedRevision(repoId, namespace, packageName, version);+ } else {+ String key = packageVersionKey(region, domain, repository, format, namespace, packageName, version);+ CodeArtifactPackageVersion pv = packageVersions.getForAccount(owner, key)+ .orElseThrow(() -> notFound("Package version '" + version + "' of package '" + packageName+ + "' was not found.", version, "package-version"));+ List<AssetSummary> allAssets = pv.getAssets().values().stream()+ .map(a -> new AssetSummary(a.getName(), a.getSize(), a.getHashes()))+ .toList();+ page = Pagination.paginate(allAssets, AssetSummary::name, maxResults, nextToken, 100, 1000,+ "ValidationException");+ revision = pv.getRevision();+ }+ return new PackageVersionAssetsListResult(format, namespace, packageName, version, revision, page.items(),+ page.nextToken());+ }+/*** Unlike {@code GetPackageVersionAsset}, real CodeArtifact's {@code DescribePackageVersion}* response has no asset listing at all (confirmed against the wire model: {@code- * PackageVersionDescription} has no such member; enumerating a version's files is {@code- * ListPackageVersionAssets}'s job, a separate, still-unimplemented action). All this needs+ * PackageVersionDescription} has no such member; enumerating a version's files is {@link+ * #listPackageVersionAssets}'s job, a separate action). All this needs* from a sidecar is a yes/no answer to "does this exact version exist," which is cheap for* every one of the three: Verdaccio's packument already lists every version it holds,* Reposilite's own details API answers directory existence the same way {@linkdiff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenDockerIntegrationTest.javaindex e7cfece17e..6a79c17e93 100644--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenDockerIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenDockerIntegrationTest.java@@ -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 thediff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDockerIntegrationTest.javaindex b2337c1658..ce84d2f396 100644--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDockerIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDockerIntegrationTest.java@@ -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} ondiff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNuGetDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNuGetDockerIntegrationTest.javaindex 861971451a..85a5c14af5 100644--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNuGetDockerIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNuGetDockerIntegrationTest.java@@ -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)diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiDockerIntegrationTest.javaindex 53bdc59458..7ffa627260 100644--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiDockerIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiDockerIntegrationTest.java@@ -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} ondiff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactServiceTest.javaindex 8258a6efcd..22f9341adf 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@@ -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