mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(codeartifact): pypi can have more than one asset per version in ListPackageVersionAssets (#6259)
hectorvent's #5962 follow-up: the javadoc claimed npm/pypi/nuget each have exactly one asset per version, but a pypi release can hold both a source distribution and a wheel. listPackageVersionAssets already lists both correctly; only the comment was wrong. Added a Docker-gated test confirming both files list with their own correct size and hash.
This commit is contained in:
1 parent
107da3e75a
commit
49ed87c815
2 files changed
+64
-8
No files matched your search
+4
-4
@@ -829,10 +829,10 @@ public class CodeArtifactService implements Resettable {
|
||||
* 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>{@code npm}/{@code nuget} genuinely have exactly one asset per version. {@code pypi} does
|
||||
* not: a single release can hold both a source distribution and a wheel, and {@link
|
||||
* PypiserverSidecarClient#listPackageVersionAssetNames} already lists every filename
|
||||
* pypiserver's own per-project JSON reports for that version, not just 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
|
||||
|
||||
+60
-4
@@ -620,11 +620,13 @@ class CodeArtifactPypiDockerIntegrationTest {
|
||||
|
||||
/**
|
||||
* 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
|
||||
* Confirms the bridge enumerates a single-asset pypi version 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.
|
||||
* no republish afterward, unlike this format's sibling test classes. {@link
|
||||
* #listPackageVersionAssetsListsBothTheSdistAndTheWheelOfOneVersion} covers the multi-asset
|
||||
* case this one doesn't.
|
||||
*/
|
||||
@Test
|
||||
@Order(18)
|
||||
@@ -672,6 +674,60 @@ class CodeArtifactPypiDockerIntegrationTest {
|
||||
.body("versions[0].origin.originType", equalTo("INTERNAL"));
|
||||
}
|
||||
|
||||
/**
|
||||
* The bug this fixes: {@code CodeArtifactService#listPackageVersionAssets}'s own javadoc used
|
||||
* to claim {@code pypi} genuinely has exactly one asset per version, the same wrong assumption
|
||||
* {@link #listPackageVersionAssetsBridgesToTheRealPypiserverSidecar}'s javadoc made. A real
|
||||
* pypi release commonly carries both a source distribution and a wheel for the same version
|
||||
* (the exact shape {@link #copyPackageVersionsOverwriteKeepsEveryAssetWhenAPypiReleaseHasBothAnSdistAndAWheel}
|
||||
* already uploads for its own purpose), so this confirms the real pypiserver sidecar lists
|
||||
* both, each with its own correct size and hash, not just one of them.
|
||||
*/
|
||||
@Test
|
||||
@Order(20)
|
||||
@SuppressWarnings("unchecked")
|
||||
void listPackageVersionAssetsListsBothTheSdistAndTheWheelOfOneVersion() {
|
||||
String packageName = "list-assets-multi-pypi-pkg";
|
||||
String sdistFilename = "list_assets_multi_pypi_pkg-1.0.0.tar.gz";
|
||||
String wheelFilename = "list_assets_multi_pypi_pkg-1.0.0-py3-none-any.whl";
|
||||
byte[] sdistContent = "list-assets-multi-sdist-bytes".getBytes(StandardCharsets.UTF_8);
|
||||
byte[] wheelContent = "list-assets-multi-wheel-bytes".getBytes(StandardCharsets.UTF_8);
|
||||
given().header("Authorization", "Bearer " + bearerToken)
|
||||
.contentType("multipart/form-data; boundary=boundary123")
|
||||
.body(twineUploadBody("boundary123", packageName, sdistFilename, sdistContent))
|
||||
.post("/codeartifact/pypi/" + DOMAIN + "/" + REPO + "/")
|
||||
.then().statusCode(200);
|
||||
given().header("Authorization", "Bearer " + bearerToken)
|
||||
.contentType("multipart/form-data; boundary=boundary123")
|
||||
.body(twineUploadBody("boundary123", packageName, wheelFilename, wheelContent))
|
||||
.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(2))
|
||||
.extract().jsonPath();
|
||||
List<Map<String, Object>> assets = (List<Map<String, Object>>) (List<?>) body.getList("assets");
|
||||
Map<String, Object> sdistAsset = findAssetByName(assets, sdistFilename);
|
||||
assertEquals(sdistContent.length, sdistAsset.get("size"));
|
||||
assertEquals(Digests.sha256Hex(sdistContent), ((Map<?, ?>) sdistAsset.get("hashes")).get("SHA-256"));
|
||||
Map<String, Object> wheelAsset = findAssetByName(assets, wheelFilename);
|
||||
assertEquals(wheelContent.length, wheelAsset.get("size"));
|
||||
assertEquals(Digests.sha256Hex(wheelContent), ((Map<?, ?>) wheelAsset.get("hashes")).get("SHA-256"));
|
||||
}
|
||||
|
||||
private static Map<String, Object> findAssetByName(List<Map<String, Object>> assets, String name) {
|
||||
for (Map<String, Object> asset : assets) {
|
||||
if (name.equals(asset.get("name"))) {
|
||||
return asset;
|
||||
}
|
||||
}
|
||||
throw new AssertionError("expected an asset named " + name + " among " + assets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Proves the actual mechanism, not just that {@code PypiserverSidecarManager} has a method
|
||||
* named right: {@code ContainerTeardowns.stopAll} runs every {@code ContainerTeardown} on
|
||||
|
||||
Reference in new issue
Block a user