Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(codeartifact): capture an empty readme for npm versions published without one (#5683)

Priamo Germosen4be2b8b04313
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDataPlane.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDataPlane.java
index 843531a3b2..3dbeb66350 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDataPlane.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDataPlane.java
@@ -435,7 +435,13 @@ public class CodeArtifactNpmDataPlane {
* field, see {@link NpmPublishEnvelopeScanner.Version} for why this, not Verdaccio's own
* packument response, is the only place it is ever available), and the caller only ever
* records it on that same successful-forward path: a confirmed republish writes nothing new,
- * so there is nothing to capture a readme change for either.
+ * so there is nothing to capture a readme change for either. Every version in the envelope
+ * gets an entry here, even one whose {@code readme} field came back {@code null} (missing, or
+ * of a shape {@link NpmPublishEnvelopeScanner} ignores): {@link
+ * CodeArtifactService#recordPublishedPackageVersionReadme} already turns a {@code null} readme
+ * into {@code ""}, the same empty-string answer pypi's own upload path already records when
+ * twine sends no {@code description} field, so a published version without a readme is never
+ * mistaken for one that was never published at all.
*/
private record RepublishCheck(boolean confirmed, long totalAttachmentBytes, PackageIdentity identity,
Map<String, String> readmeByVersion) {}
@@ -454,11 +460,7 @@ public class CodeArtifactNpmDataPlane {
.mapToLong(NpmPublishEnvelopeScanner.Attachment::size)
.sum();
Map<String, String> readmeByVersion = new HashMap<>();
- envelope.versions().forEach((version, v) -> {
- if (v.readme() != null) {
- readmeByVersion.put(version, v.readme());
- }
- });
+ envelope.versions().forEach((version, v) -> readmeByVersion.put(version, v.readme()));
Optional<JsonNode> storedDocument;
try {
storedDocument = verdaccioClient.fetchPackageDocument(backendBaseUrl, identity.namespace(),
diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDockerIntegrationTest.java
index 01b1910659..7b27aa2a02 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
@@ -554,6 +554,41 @@ class CodeArtifactNpmDockerIntegrationTest {
.body("version", equalTo("1.0.0"));
}
+ /**
+ * The follow-up hectorvent asked for on #5644: a version published with no {@code readme}
+ * field at all (unlike {@link #getPackageVersionReadmeReturnsWhatTheRealPublishEnvelopeSent},
+ * whose fixture carries npm's own literal placeholder text, a real string) must still read back
+ * as an empty string, not 404 — the same empty-readme answer pypi's upload path already gives
+ * when twine sends no {@code description} field. Before the fix, {@code checkRepublish} only
+ * added a version to {@code readmeByVersion} when its {@code readme} field was non-null, so a
+ * version published without one was never recorded at all, and {@code GetPackageVersionReadme}
+ * answered {@code ResourceNotFoundException} for a version that genuinely exists on Verdaccio.
+ */
+ @Test
+ @Order(16)
+ void publishingWithNoReadmeFieldStillRecordsAnEmptyReadmeRatherThanNothing() {
+ String packageName = "no-readme-field-pkg";
+ byte[] tarball = "no readme field throwaway tarball".getBytes(StandardCharsets.UTF_8);
+ String envelope = "{\"name\":\"" + packageName + "\",\"versions\":{\"1.0.0\":{\"name\":\"" + packageName
+ + "\",\"version\":\"1.0.0\",\"dist\":{\"tarball\":"
+ + "\"http://ignored/" + packageName + "-1.0.0.tgz\""
+ + "}}},\"_attachments\":{\"" + packageName + "-1.0.0.tgz\":{\"content_type\":"
+ + "\"application/octet-stream\",\"data\":\""
+ + Base64.getEncoder().encodeToString(tarball) + "\",\"length\":" + tarball.length + "}}}";
+
+ given().header("Authorization", "Bearer " + bearerToken).contentType("application/json").body(envelope)
+ .put("/codeartifact/npm/" + DOMAIN + "/" + REPO + "/" + packageName)
+ .then().statusCode(anyOf201Or200());
+
+ given().header("Authorization", AUTH)
+ .get("/v1/package/version/readme?domain=" + DOMAIN + "&repository=" + REPO + "&format=npm&package="
+ + packageName + "&version=1.0.0")
+ .then().statusCode(200)
+ .body("readme", equalTo(""))
+ .body("package", equalTo(packageName))
+ .body("version", equalTo("1.0.0"));
+ }
+
/**
* Proves the actual mechanism, not just that {@code VerdaccioSidecarManager} has a method
* named right: {@code ContainerTeardowns.stopAll} runs every {@code ContainerTeardown} on