mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(codeartifact): implement GetPackageVersionReadme (#5644)
Supports npm, pypi, and nuget, matching AWS's own documented restriction for this action (not maven, Swift, generic, Ruby, or Cargo, which carry no readme in real CodeArtifact). Neither npm nor pypi can answer this live after the fact. A real Verdaccio packument GET hoists readme to the top level only, for the single most-recently-published version, and drops the per-version field from its own response entirely, even though a real npm client's publish envelope genuinely sends one per version (confirmed against a live Verdaccio 6.10.4 container with a captured real npm-publish fixture). pypiserver has no description field anywhere in its model or its RPC2 route (confirmed by reading pypiserver's own source at the pinned version), so it never had a live path to begin with. Both formats are therefore captured at publish/upload time instead: npm's per-version readme field is read off the real publish envelope by NpmPublishEnvelopeScanner and recorded after a successful forward to the Verdaccio sidecar, and pypi's is read off the upload form's description field the same way it already was. Both go through the same recordPublishedPackageVersionReadme method and the same packageVersionReadmes account-scoped store, cleaned up on DeleteRepository and DeletePackage the same way packageOriginConfigs already is. nuget is accepted as a valid format but always 404s, since nothing in Floci implements the real NuGet wire protocol and no nuget package version can ever exist here. Refactors validatePackageToken to delegate to a new non-throwing isValidPackageToken, reused by the readme capture path (fed raw publish/upload input, never through the JSON API's own validation) to guard the same escape-collision invariant escapeKeySegment depends on. Extracts the container-backed revision synthesis already used by GetPackageVersionAsset into a shared helper so GetPackageVersionReadme reports a consistent revision for the same version coordinate.
This commit is contained in:
1 parent
29ead624f8
commit
8f907023b2
11 files changed
+849
-64
No files matched your search
+119
@@ -435,6 +435,125 @@ class CodeArtifactNpmDockerIntegrationTest {
|
||||
assertEquals(assetSizeBytesBeforePublish, describeDomainAssetSizeBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* A second real finding found alongside the npm readme redesign itself: the native unpublish
|
||||
* path above cleans up the byte count and the deletion fence, but a first version of that same
|
||||
* fix left {@code packageVersionReadmes} untouched, so {@code GetPackageVersionReadme} would
|
||||
* keep answering for a package a real npm registry (and real CodeArtifact) now 404s on,
|
||||
* forever, since nothing else ever revisits that store once it's written. A throwaway
|
||||
* package, not {@link #PACKAGE_NAME}, for the same reason as the tests above.
|
||||
*/
|
||||
@Test
|
||||
@Order(13)
|
||||
void nativeNpmUnpublishCleansUpTheCapturedReadmeToo() {
|
||||
String packageName = "unpublish-readme-pkg";
|
||||
byte[] tarball = "unpublish readme throwaway tarball".getBytes(StandardCharsets.UTF_8);
|
||||
String envelope = "{\"name\":\"" + packageName + "\",\"versions\":{\"1.0.0\":{\"name\":\"" + packageName
|
||||
+ "\",\"version\":\"1.0.0\",\"readme\":\"# Soon to be unpublished\",\"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("# Soon to be unpublished"));
|
||||
|
||||
String rev = given().header("Authorization", "Bearer " + bearerToken)
|
||||
.get("/codeartifact/npm/" + DOMAIN + "/" + REPO + "/" + packageName)
|
||||
.then().statusCode(200)
|
||||
.extract().jsonPath().getString("_rev");
|
||||
|
||||
given().header("Authorization", "Bearer " + bearerToken)
|
||||
.delete("/codeartifact/npm/" + DOMAIN + "/" + REPO + "/" + packageName + "/-rev/" + rev)
|
||||
.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(404).body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Each of a multi-version npm package's versions is published in its own {@code PUT}, exactly
|
||||
* like a real {@code npm publish} (confirmed directly: an earlier draft of this test tried
|
||||
* publishing two versions in one envelope and Verdaccio itself rejected it outright, {@code 400
|
||||
* unsupported registry call}). Proves readme capture is genuinely per-version, not just
|
||||
* per-package: publishing the second version must not disturb the first's already-captured
|
||||
* readme.
|
||||
*
|
||||
* <p>Unpublishing a single version of a multi-version npm package (real wire shape confirmed
|
||||
* against npm/cli's own source: a {@code PUT} to the same {@code /-rev/<rev>} path the
|
||||
* whole-package {@code DELETE} unpublish already uses, carrying the packument with that one
|
||||
* version removed) is not detected anywhere in this proxy, deliberately: see
|
||||
* {@code CodeArtifactNpmDataPlane#nativeUnpublishTarget}'s own javadoc for why, left as a
|
||||
* documented, scoped-out limitation rather than fixed without the request-body-reading
|
||||
* plumbing a correct, narrower fix for it actually needs.
|
||||
*/
|
||||
@Test
|
||||
@Order(14)
|
||||
void publishingASecondVersionDoesNotDisturbTheFirstVersionsCapturedReadme() {
|
||||
String packageName = "multi-version-readme-pkg";
|
||||
byte[] tarballV1 = "multi version readme v1".getBytes(StandardCharsets.UTF_8);
|
||||
byte[] tarballV2 = "multi version readme v2".getBytes(StandardCharsets.UTF_8);
|
||||
String envelopeV1 = "{\"name\":\"" + packageName + "\",\"versions\":{\"1.0.0\":{\"name\":\""
|
||||
+ packageName + "\",\"version\":\"1.0.0\",\"readme\":\"# v1\",\"dist\":{\"tarball\":"
|
||||
+ "\"http://ignored/" + packageName + "-1.0.0.tgz\"}}},\"_attachments\":{\"" + packageName
|
||||
+ "-1.0.0.tgz\":{\"content_type\":\"application/octet-stream\",\"data\":\""
|
||||
+ Base64.getEncoder().encodeToString(tarballV1) + "\",\"length\":" + tarballV1.length + "}}}";
|
||||
String envelopeV2 = "{\"name\":\"" + packageName + "\",\"versions\":{\"2.0.0\":{\"name\":\""
|
||||
+ packageName + "\",\"version\":\"2.0.0\",\"readme\":\"# v2\",\"dist\":{\"tarball\":"
|
||||
+ "\"http://ignored/" + packageName + "-2.0.0.tgz\"}}},\"_attachments\":{\"" + packageName
|
||||
+ "-2.0.0.tgz\":{\"content_type\":\"application/octet-stream\",\"data\":\""
|
||||
+ Base64.getEncoder().encodeToString(tarballV2) + "\",\"length\":" + tarballV2.length + "}}}";
|
||||
|
||||
given().header("Authorization", "Bearer " + bearerToken).contentType("application/json").body(envelopeV1)
|
||||
.put("/codeartifact/npm/" + DOMAIN + "/" + REPO + "/" + packageName)
|
||||
.then().statusCode(anyOf201Or200());
|
||||
given().header("Authorization", "Bearer " + bearerToken).contentType("application/json").body(envelopeV2)
|
||||
.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("# v1"));
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version/readme?domain=" + DOMAIN + "&repository=" + REPO + "&format=npm&package="
|
||||
+ packageName + "&version=2.0.0")
|
||||
.then().statusCode(200).body("readme", equalTo("# v2"));
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding: a first implementation answered this live from Verdaccio's own
|
||||
* packument, which turned out, checked directly against this same live container, to hoist
|
||||
* {@code readme} to the top level only (the single most-recently-published version), dropping
|
||||
* the per-version field entirely from its own GET response — even though a real npm client's
|
||||
* publish envelope (the real fixture {@link #setUp} loads, captured from an actual {@code npm
|
||||
* publish}) genuinely sends one per version. This exercises the real capture-at-publish-time
|
||||
* path end to end against that same live container: the exact text the fixture's own
|
||||
* {@code versions["1.0.0"].readme} field carries ({@code "ERROR: No README data found!"},
|
||||
* npm's own literal placeholder for a package with no real {@code README.md}, not an absent
|
||||
* field) must come back unchanged.
|
||||
*/
|
||||
@Test
|
||||
@Order(15)
|
||||
void getPackageVersionReadmeReturnsWhatTheRealPublishEnvelopeSent() {
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version/readme?domain=" + DOMAIN + "&repository=" + REPO + "&format=npm&package="
|
||||
+ PACKAGE_NAME + "&version=1.0.0")
|
||||
.then().statusCode(200)
|
||||
.body("readme", equalTo("ERROR: No README data found!"))
|
||||
.body("package", equalTo(PACKAGE_NAME))
|
||||
.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
|
||||
|
||||
+44
@@ -403,6 +403,37 @@ class CodeArtifactPypiDockerIntegrationTest {
|
||||
.then().statusCode(404).body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
/**
|
||||
* The real-world gap this closes: the readme-capture call site inside {@code
|
||||
* CodeArtifactPypiController#upload} had never once been exercised by a real multipart body
|
||||
* against a live pypiserver container (every other readme test either called {@code
|
||||
* CodeArtifactService} directly or never sent a {@code description} field at all). A
|
||||
* throwaway package, not {@link #PACKAGE_NAME}, so it doesn't disturb the ordered sequence
|
||||
* above.
|
||||
*/
|
||||
@Test
|
||||
@Order(14)
|
||||
void getPackageVersionReadmeReturnsWhatARealTwineUploadSent() {
|
||||
String packageName = "floci-pypiserver-readme-spike";
|
||||
String filename = "floci_pypiserver_readme_spike-1.0.0.tar.gz";
|
||||
String description = "# Real Readme\n\nSent as the real twine upload's own description field.";
|
||||
|
||||
given().header("Authorization", "Bearer " + bearerToken)
|
||||
.contentType("multipart/form-data; boundary=boundary123")
|
||||
.body(twineUploadBody("boundary123", packageName, filename,
|
||||
"readme-spike-bytes".getBytes(StandardCharsets.UTF_8), description))
|
||||
.post("/codeartifact/pypi/" + DOMAIN + "/" + REPO + "/")
|
||||
.then().statusCode(200);
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version/readme?domain=" + DOMAIN + "&repository=" + REPO + "&format=pypi&package="
|
||||
+ packageName + "&version=1.0.0")
|
||||
.then().statusCode(200)
|
||||
.body("readme", equalTo(description))
|
||||
.body("package", equalTo(packageName))
|
||||
.body("version", equalTo("1.0.0"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Proves the actual mechanism, not just that {@code PypiserverSidecarManager} has a method
|
||||
* named right: {@code ContainerTeardowns.stopAll} runs every {@code ContainerTeardown} on
|
||||
@@ -458,6 +489,16 @@ class CodeArtifactPypiDockerIntegrationTest {
|
||||
* {@code name} and the {@code content} file part, so the rest are included for realism only.
|
||||
*/
|
||||
private static byte[] twineUploadBody(String boundary, String packageName, String filename, byte[] content) {
|
||||
return twineUploadBody(boundary, packageName, filename, content, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same real twine shape as the 4-argument overload above, with an optional {@code description}
|
||||
* field (the real PyPI legacy upload API's field for a distribution's long description) a real
|
||||
* {@code twine upload} also sends whenever the project's metadata carries one.
|
||||
*/
|
||||
private static byte[] twineUploadBody(String boundary, String packageName, String filename, byte[] content,
|
||||
String description) {
|
||||
String preamble = "--" + boundary + "\r\n"
|
||||
+ "Content-Disposition: form-data; name=\":action\"\r\n\r\n"
|
||||
+ "file_upload\r\n"
|
||||
@@ -473,6 +514,9 @@ class CodeArtifactPypiDockerIntegrationTest {
|
||||
+ "--" + boundary + "\r\n"
|
||||
+ "Content-Disposition: form-data; name=\"filetype\"\r\n\r\n"
|
||||
+ "sdist\r\n"
|
||||
+ (description == null ? "" : "--" + boundary + "\r\n"
|
||||
+ "Content-Disposition: form-data; name=\"description\"\r\n\r\n"
|
||||
+ description + "\r\n")
|
||||
+ "--" + boundary + "\r\n"
|
||||
+ "Content-Disposition: form-data; name=\"content\"; filename=\"" + filename + "\"\r\n"
|
||||
+ "Content-Type: application/octet-stream\r\n\r\n";
|
||||
|
||||
+257
@@ -311,6 +311,15 @@ class CodeArtifactServiceTest {
|
||||
bytes, fence);
|
||||
}
|
||||
|
||||
/** Same snapshot-then-report shape as {@link #recordBytes}, for readme capture instead. */
|
||||
private void recordReadme(String domain, String repository, String format, String namespace, String packageName,
|
||||
String version, String readme) {
|
||||
long fence = service.currentContainerBackedPackageFence(REGION, domain, null, repository, format, namespace,
|
||||
packageName);
|
||||
service.recordPublishedPackageVersionReadme(REGION, domain, null, repository, format, namespace, packageName,
|
||||
version, readme, fence);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code recordContainerBackedAssetBytes} is what each of the three sidecar-backed proxies
|
||||
* calls after a real (non-idempotent, non-rejected) write; this is the unit-level proof that
|
||||
@@ -2121,6 +2130,254 @@ class CodeArtifactServiceTest {
|
||||
assertEquals("package-version", wrongRevision.getExtendedData().get("resourceType"));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------- GetPackageVersionReadme
|
||||
|
||||
@Test
|
||||
void getPackageVersionReadmeRejectsAFormatAwsDoesNotSupportForThisAction() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
// AWS's own API reference restricts this one action's format parameter to npm/pypi/nuget,
|
||||
// narrower than every other package-version action here, which accepts the full 8-value
|
||||
// set: maven, swift, generic, ruby, and cargo package versions carry no readme in real
|
||||
// CodeArtifact at all, so every one of them is checked here, not just maven.
|
||||
for (String format : new String[] {"maven", "swift", "generic", "ruby", "cargo"}) {
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.getPackageVersionReadme(REGION, "dom",
|
||||
null, "repo", format, "com.example", "my-artifact", "1.0.0"), format);
|
||||
assertEquals("ValidationException", e.getErrorCode(), format);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* npm, like pypi, can only ever be answered from what was captured at publish time: confirmed
|
||||
* directly against a live Verdaccio container that it hoists {@code readme} to the top level
|
||||
* only (the single most-recently-published version), dropping the per-version field a real
|
||||
* npm client's own publish envelope actually sends. See
|
||||
* {@link CodeArtifactNpmDataPlane#forwardSpooled} for where this is captured for real.
|
||||
*/
|
||||
@Test
|
||||
void getPackageVersionReadmeReturnsWhatWasCapturedAtNpmPublishTime() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
recordReadme("dom", "repo", "npm", "myscope", "my-pkg", "1.0.0", "# My Package");
|
||||
|
||||
CodeArtifactService.PackageVersionReadmeResult result = service.getPackageVersionReadme(REGION, "dom", null,
|
||||
"repo", "npm", "myscope", "my-pkg", "1.0.0");
|
||||
|
||||
assertEquals("# My Package", result.readme());
|
||||
assertEquals("my-pkg", result.packageName());
|
||||
assertEquals("1.0.0", result.version());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPackageVersionReadme404sForNpmWhenNeverCaptured() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.getPackageVersionReadme(REGION, "dom", null,
|
||||
"repo", "npm", null, "my-pkg", "9.9.9"));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
assertEquals("package-version", e.getExtendedData().get("resourceType"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPackageVersionReadmeReturnsWhatWasCapturedAtPypiUploadTime() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
recordReadme("dom", "repo", "pypi", null, "my-pkg", "1.0.0", "Long description in reStructuredText.");
|
||||
|
||||
CodeArtifactService.PackageVersionReadmeResult result = service.getPackageVersionReadme(REGION, "dom", null,
|
||||
"repo", "pypi", null, "my-pkg", "1.0.0");
|
||||
|
||||
assertEquals("Long description in reStructuredText.", result.readme());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPackageVersionReadme404sForPypiWhenNeverCaptured() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.getPackageVersionReadme(REGION, "dom", null,
|
||||
"repo", "pypi", null, "never-published", "1.0.0"));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* nuget is a documented valid format for this action, but nothing in Floci implements the
|
||||
* real NuGet wire protocol, so no nuget package version can ever actually exist here; this
|
||||
* must 404 honestly rather than throwing some other error for a format it otherwise accepts.
|
||||
*/
|
||||
@Test
|
||||
void getPackageVersionReadme404sForNugetSinceNothingCanEverPublishOne() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.getPackageVersionReadme(REGION, "dom", null,
|
||||
"repo", "nuget", null, "my-pkg", "1.0.0"));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void recordPublishedPackageVersionReadmeSkipsAPackageNameContainingTheEscapeCharacterWithoutCorruptingOthers() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
// The escape character itself can never reach escapeKeySegment's own key building, the
|
||||
// same way validatePackageToken already keeps it out of every JSON-API coordinate: this
|
||||
// call is just dropped, logged, and never throws back into the sidecar upload it reports.
|
||||
recordReadme("dom", "repo", "pypi", null, "bad#name", "1.0.0", "bad text");
|
||||
recordReadme("dom", "repo", "pypi", null, "legit", "1.0.0", "legit text");
|
||||
|
||||
CodeArtifactService.PackageVersionReadmeResult result = service.getPackageVersionReadme(REGION, "dom", null,
|
||||
"repo", "pypi", null, "legit", "1.0.0");
|
||||
assertEquals("legit text", result.readme());
|
||||
}
|
||||
|
||||
@Test
|
||||
void recordPublishedPackageVersionReadmeAfterTheRepositoryIsAlreadyDeletedIsIgnored() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
service.deleteRepository(REGION, "dom", null, "repo");
|
||||
|
||||
recordReadme("dom", "repo", "pypi", null, "my-pkg", "1.0.0", "late text");
|
||||
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.getPackageVersionReadme(REGION, "dom", null,
|
||||
"repo", "pypi", null, "my-pkg", "1.0.0"));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteRepositoryRemovesItsCapturedPypiReadmesSoARecreatedRepositoryDoesNotInheritThem() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
recordReadme("dom", "repo", "pypi", null, "my-pkg", "1.0.0", "old text");
|
||||
|
||||
service.deleteRepository(REGION, "dom", null, "repo");
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.getPackageVersionReadme(REGION, "dom", null,
|
||||
"repo", "pypi", null, "my-pkg", "1.0.0"));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletePackageRemovesItsCapturedPypiReadmesSoARepublishedPackageDoesNotInheritThem() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
recordReadme("dom", "repo", "pypi", null, "my-pkg", "1.0.0", "old text");
|
||||
when(pypiserverClient.packageExists(anyString(), eq("dom"), eq("repo"), isNull(), eq("my-pkg")))
|
||||
.thenReturn(true);
|
||||
|
||||
service.deletePackage(REGION, "dom", null, "repo", "pypi", null, "my-pkg");
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.getPackageVersionReadme(REGION, "dom", null,
|
||||
"repo", "pypi", null, "my-pkg", "1.0.0"));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void forgetContainerBackedPackageRemovesItsCapturedNpmReadmeTooSoAReplacedPackageDoesNotInheritIt() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
recordReadme("dom", "repo", "npm", null, "my-pkg", "1.0.0", "old text");
|
||||
|
||||
service.forgetContainerBackedPackage(REGION, "dom", null, "repo", "npm", null, "my-pkg");
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.getPackageVersionReadme(REGION, "dom", null,
|
||||
"repo", "npm", null, "my-pkg", "1.0.0"));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code getPackageVersionReadmeRejectsAFormatAwsDoesNotSupportForThisAction} above only
|
||||
* covers the format check; a Qodo review found this method's other required-field validation
|
||||
* (domain/repository/package/version) had no regression coverage of its own, nor any proof
|
||||
* that a rejected request leaves a previously captured readme untouched.
|
||||
*/
|
||||
@Test
|
||||
void getPackageVersionReadmeRejectsMissingRequiredFieldsWithoutChangingStoredState() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
recordReadme("dom", "repo", "npm", null, "my-pkg", "1.0.0", "untouched text");
|
||||
|
||||
AwsException missingDomain = assertThrows(AwsException.class, () -> service.getPackageVersionReadme(REGION,
|
||||
null, null, "repo", "npm", null, "my-pkg", "1.0.0"));
|
||||
assertEquals("ValidationException", missingDomain.getErrorCode());
|
||||
AwsException missingRepository = assertThrows(AwsException.class, () -> service.getPackageVersionReadme(
|
||||
REGION, "dom", null, null, "npm", null, "my-pkg", "1.0.0"));
|
||||
assertEquals("ValidationException", missingRepository.getErrorCode());
|
||||
AwsException missingPackage = assertThrows(AwsException.class, () -> service.getPackageVersionReadme(REGION,
|
||||
"dom", null, "repo", "npm", null, null, "1.0.0"));
|
||||
assertEquals("ValidationException", missingPackage.getErrorCode());
|
||||
AwsException missingVersion = assertThrows(AwsException.class, () -> service.getPackageVersionReadme(REGION,
|
||||
"dom", null, "repo", "npm", null, "my-pkg", null));
|
||||
assertEquals("ValidationException", missingVersion.getErrorCode());
|
||||
|
||||
CodeArtifactService.PackageVersionReadmeResult result = service.getPackageVersionReadme(REGION, "dom", null,
|
||||
"repo", "npm", null, "my-pkg", "1.0.0");
|
||||
assertEquals("untouched text", result.readme());
|
||||
}
|
||||
|
||||
/**
|
||||
* Same race {@code recordContainerBackedAssetBytesAfterAConcurrentDeletePackageIsIgnored}
|
||||
* already closes for byte accounting, found again by Qodo review for readme capture: a delayed
|
||||
* npm callback's readme capture must not resurrect a readme for a package a concurrent
|
||||
* {@code DeletePackage} already removed.
|
||||
*/
|
||||
@Test
|
||||
void recordPublishedPackageVersionReadmeAfterAConcurrentDeletePackageIsIgnored() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
long fence = service.currentContainerBackedPackageFence(REGION, "dom", null, "repo", "npm", null, "late");
|
||||
when(verdaccioClient.packageExists(anyString(), eq("dom"), eq("repo"), isNull(), eq("late")))
|
||||
.thenReturn(true);
|
||||
service.deletePackage(REGION, "dom", null, "repo", "npm", null, "late");
|
||||
|
||||
service.recordPublishedPackageVersionReadme(REGION, "dom", null, "repo", "npm", null, "late", "1.0.0",
|
||||
"too late", fence);
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.getPackageVersionReadme(REGION, "dom", null,
|
||||
"repo", "npm", null, "late", "1.0.0"));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Found by Qodo review: pypi readme capture/lookup/deletion all used the package name exactly
|
||||
* as the caller spelled it, while {@code accountingPackageName} (and so byte accounting, the
|
||||
* fence, and sidecar resolution itself) treats case- and {@code -_.}-equivalent spellings as
|
||||
* the same pypi package. A readme captured under one spelling has to be answerable, and
|
||||
* deletable, under any PEP 503-equivalent spelling of the same name.
|
||||
*/
|
||||
@Test
|
||||
void getPackageVersionReadmeResolvesPypiSpellingVariantsToTheSameReadme() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
recordReadme("dom", "repo", "pypi", null, "My_Package", "1.0.0", "the readme");
|
||||
|
||||
CodeArtifactService.PackageVersionReadmeResult result = service.getPackageVersionReadme(REGION, "dom", null,
|
||||
"repo", "pypi", null, "my-package", "1.0.0");
|
||||
|
||||
assertEquals("the readme", result.readme());
|
||||
// Echoes the caller's own spelling back, not the normalized one used for the lookup.
|
||||
assertEquals("my-package", result.packageName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deletePackageRemovesAPypiReadmeCapturedUnderADifferentSpelling() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
recordReadme("dom", "repo", "pypi", null, "My.Package", "1.0.0", "the readme");
|
||||
when(pypiserverClient.packageExists(anyString(), eq("dom"), eq("repo"), isNull(), eq("my-package")))
|
||||
.thenReturn(true);
|
||||
|
||||
service.deletePackage(REGION, "dom", null, "repo", "pypi", null, "my-package");
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.getPackageVersionReadme(REGION, "dom", null,
|
||||
"repo", "pypi", null, "My_Package", "1.0.0"));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void concurrentUnfinishedPublishesOfDifferentAssetsBothPersist() throws InterruptedException {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
|
||||
+30
@@ -199,6 +199,36 @@ class NpmPublishEnvelopeScannerTest {
|
||||
assertInvalid("[1,2,3]");
|
||||
}
|
||||
|
||||
/**
|
||||
* Found by Qodo review: before this field was read at all, any shape here fell to the default
|
||||
* branch's plain {@code skipChildren()}; once it became a tracked field (for readme capture),
|
||||
* a value sent as anything but a string (a real client never would, but a hand-built or buggy
|
||||
* one might) must keep that same tolerance, not reject the whole envelope over one best-effort
|
||||
* field. {@code dist.integrity} on the same version, a field this scanner does require, proves
|
||||
* the rest of the version is still read correctly when {@code readme} is skipped.
|
||||
*/
|
||||
@Test
|
||||
void aNonStringPerVersionReadmeIsToleratedRatherThanRejectingTheWholeEnvelope() throws Exception {
|
||||
String json = "{\"versions\":{\"1.0.0\":{\"readme\":null,\"dist\":{\"tarball\":\"x/y-1.0.0.tgz\","
|
||||
+ "\"integrity\":\"sha512-abc\"}}}}";
|
||||
|
||||
NpmPublishEnvelopeScanner.Envelope envelope = scan(json);
|
||||
|
||||
NpmPublishEnvelopeScanner.Version version = envelope.versions().get("1.0.0");
|
||||
assertNull(version.readme());
|
||||
assertEquals("sha512-abc", version.integrity());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anObjectShapedPerVersionReadmeIsToleratedTheSameWay() throws Exception {
|
||||
String json = "{\"versions\":{\"1.0.0\":{\"readme\":{\"not\":\"a string\"},\"dist\":{\"tarball\":"
|
||||
+ "\"x/y-1.0.0.tgz\",\"integrity\":\"sha512-abc\"}}}}";
|
||||
|
||||
NpmPublishEnvelopeScanner.Envelope envelope = scan(json);
|
||||
|
||||
assertNull(envelope.versions().get("1.0.0").readme());
|
||||
}
|
||||
|
||||
private static NpmPublishEnvelopeScanner.Envelope scan(String json) throws IOException {
|
||||
InputStream in = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8));
|
||||
return NpmPublishEnvelopeScanner.scan(in);
|
||||
|
||||
Reference in new issue
Block a user