mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(codeartifact): capture an empty readme for npm versions published without one (#5683)
A version published with no readme field was silently skipped in checkRepublish's readmeByVersion map, so GetPackageVersionReadme answered ResourceNotFoundException for a version that genuinely exists on Verdaccio. pypi already records an empty string in the equivalent case (twine uploads with no description field), so npm now does the same: every version in the publish envelope gets an entry, with recordPublishedPackageVersionReadme's existing null-to-"" normalization doing the rest. Follow-up requested on #5644's approval.
This commit is contained in:
1 parent
425cd3167d
commit
4be2b8b043
2 files changed
+43
-6
No files matched your search
+8
-6
@@ -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(),
|
||||
|
||||
+35
@@ -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
|
||||
|
||||
Reference in new issue
Block a user