feat(codeartifact): support publishing and reading generic-format package versions (#3839)

Adds PublishPackageVersion, DescribePackageVersion, and GetPackageVersionAsset
for CodeArtifact's generic package format, matching AWS's own wire restriction
that PublishPackageVersion accepts only the generic format. Includes real
asset hashing (MD5, SHA-1, SHA-256, SHA-512), SHA-256 integrity verification
against the caller's x-amz-content-sha256 header, correct Unfinished/Published
status transitions, and the documented AWS quotas for this action (350 assets
per version, 5 GB max asset size), all returning ServiceQuotaExceededException
when exceeded.

Asset bytes are kept out of the JSON/WAL-backed package-version store
(@JsonIgnore on PackageAsset.content) and instead go through a dedicated
asset store, a disk file in persistent/hybrid/wal mode or a side map in
memory mode, the same split S3Object/S3Service already uses for object
bytes. Without this, a publish rewrote every asset of every package version
on disk each time, growing quadratically under this action's own
350-asset/5GB quotas. The asset name is also validated against the wire
model's AssetName pattern (no control characters), not just its length,
since it is echoed back verbatim in the X-AssetName response header on
GetPackageVersionAsset.

Verified against the real botocore service-2.json wire model and the AWS
CodeArtifact User Guide (including its PDF for the quotas table, since the
HTML quotas page is JS-rendered). Live-verified with the real AWS CLI and
the AWS SDK for Java v2 against a running Floci instance, including an exact
byte-for-byte asset round-trip and the real ConflictException when
republishing an already-Published version.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-09-18 23:49:21 -05:00
1 parent e190f7d340
commit bbaf3568c5
10 files changed
+1158 -19

No files matched your search

@@ -2,11 +2,16 @@ package com.floci.test;
import org.jboss.logging.Logger;
import org.junit.jupiter.api.*;
import software.amazon.awssdk.core.ResponseBytes;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.codeartifact.CodeartifactClient;
import software.amazon.awssdk.services.codeartifact.model.*;
// Explicit import: this file's Tag usage is the CodeArtifact model type, not JUnit's @Tag.
import software.amazon.awssdk.services.codeartifact.model.Tag;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@@ -219,6 +224,76 @@ class CodeArtifactTest {
assertThat(disassoc.repository().externalConnections()).isEmpty();
}
@Test
@Order(70)
@DisplayName("PublishPackageVersion - publishes a generic asset and verifies its hashes")
void publishPackageVersion() {
byte[] content = "hello from the compat suite".getBytes(StandardCharsets.UTF_8);
String sha256 = sha256Hex(content);
PublishPackageVersionResponse resp = codeArtifact.publishPackageVersion(r -> r
.domain(DOMAIN)
.repository(REPO)
.format(PackageFormat.GENERIC)
.namespace("compat-ns")
.packageValue("compat-pkg")
.packageVersion("1.0.0")
.assetName("asset.txt")
.assetSHA256(sha256),
RequestBody.fromBytes(content));
assertThat(resp.status()).isEqualTo(PackageVersionStatus.PUBLISHED);
assertThat(resp.asset().name()).isEqualTo("asset.txt");
assertThat(resp.asset().size()).isEqualTo(content.length);
assertThat(resp.asset().hashes().get(HashAlgorithm.SHA_256)).isEqualTo(sha256);
}
// No SDK-level bad-assetSHA256 test: the Java SDK overwrites that header during SigV4 signing; see CodeArtifactServiceTest instead.
@Test
@Order(72)
@DisplayName("DescribePackageVersion / GetPackageVersionAsset - round-trip exact bytes")
void describeAndDownloadPackageVersionAsset() {
DescribePackageVersionResponse described = codeArtifact.describePackageVersion(r -> r
.domain(DOMAIN)
.repository(REPO)
.format(PackageFormat.GENERIC)
.namespace("compat-ns")
.packageValue("compat-pkg")
.packageVersion("1.0.0"));
assertThat(described.packageVersion().status()).isEqualTo(PackageVersionStatus.PUBLISHED);
assertThat(described.packageVersion().origin().originType()).isEqualTo(PackageVersionOriginType.INTERNAL);
ResponseBytes<GetPackageVersionAssetResponse> downloaded = codeArtifact.getPackageVersionAssetAsBytes(r -> r
.domain(DOMAIN)
.repository(REPO)
.format(PackageFormat.GENERIC)
.namespace("compat-ns")
.packageValue("compat-pkg")
.packageVersion("1.0.0")
.asset("asset.txt"));
assertThat(downloaded.response().assetName()).isEqualTo("asset.txt");
assertThat(downloaded.asByteArray()).isEqualTo("hello from the compat suite".getBytes(StandardCharsets.UTF_8));
}
@Test
@Order(73)
@DisplayName("PublishPackageVersion - a second publish to a Published version conflicts")
void republishingAPublishedVersionConflicts() {
byte[] content = "won't land".getBytes(StandardCharsets.UTF_8);
assertThatThrownBy(() -> codeArtifact.publishPackageVersion(r -> r
.domain(DOMAIN)
.repository(REPO)
.format(PackageFormat.GENERIC)
.namespace("compat-ns")
.packageValue("compat-pkg")
.packageVersion("1.0.0")
.assetName("another.txt")
.assetSHA256(sha256Hex(content)),
RequestBody.fromBytes(content)))
.isInstanceOf(ConflictException.class);
}
@Test
@Order(90)
@DisplayName("DeleteDomain - fails while repositories still exist")
@@ -226,4 +301,17 @@ class CodeArtifactTest {
assertThatThrownBy(() -> codeArtifact.deleteDomain(r -> r.domain(DOMAIN)))
.isInstanceOf(ConflictException.class);
}
private static String sha256Hex(byte[] content) {
try {
byte[] digest = MessageDigest.getInstance("SHA-256").digest(content);
StringBuilder sb = new StringBuilder(digest.length * 2);
for (byte b : digest) {
sb.append(String.format("%02x", b));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
throw new IllegalStateException(e);
}
}
}