mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(codeartifact): block Archived version downloads on native per-format routes (#6782)
GetPackageVersionAsset already 404s an Archived or Disposed version's bytes, but the native per-format passthroughs (Maven's GAV path, npm's tarball route, pypi's filename route, nuget's content route) proxied straight to their own sidecar with no awareness of that override, so a plain mvn/npm/ pip/nuget client could still download an Archived version's real bytes. Disposed already self-resolves: DisposePackageVersions genuinely deletes the sidecar's own bytes, so those routes already 404 for the real reason, nothing to add there. Archived is the real gap, closed the same way for all four formats via one new CodeArtifactService#requireContainerBackedVersionDownloadable check, called right before each controller's own proxy: - Maven and nuget already carry namespace/package/version as path params, so this is a direct call. - npm's tarball GET has no version as its own path segment, only embedded in the filename; detected with the same `/-/` marker-splitting technique nativeUnpublishTarget already uses for its own `/-rev/` marker. - pypi's download route is a bare filename with no package name or version anywhere in the URL at all, so the coordinate is resolved by matching the filename against this repository's own Archived/Disposed status overrides, the same way the upload-side guard already does. Whichever path put the file there (a native upload or CopyPackageVersions), a later status override is found the same way. - npm resolves the requested tarball's real version against Verdaccio's own packument (dist.tarball), and only when the package has a status override at all. Verified live against all four real sidecar containers (Reposilite, Verdaccio, pypiserver, BaGetter): archive a version, confirm the download 404s while the real file is still present, then un-archive and confirm the exact same bytes come back unchanged.
This commit is contained in:
1 parent
4f9dcf049c
commit
74a313a587
14 files changed
+715
-35
No files matched your search
+54
@@ -695,6 +695,60 @@ class CodeArtifactMavenDockerIntegrationTest {
|
||||
assertEquals("com.example.nested", namespaces.get(names.indexOf("listpkgsprobe")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes 10-NATIVE-STATUS for Maven: a plain {@code mvn dependency:get} fetch of an Archived
|
||||
* version's real GAV path must 404 against the real Reposilite sidecar, even though the jar's
|
||||
* own bytes are still sitting there untouched (unlike {@link
|
||||
* #disposePackageVersionsDeletesTheRealReposiliteAssetsAndKeepsListingTheVersionAsDisposed}'s
|
||||
* own 404, which comes from Reposilite genuinely no longer having the file).
|
||||
*/
|
||||
@Test
|
||||
@Order(24)
|
||||
void deployThenArchiveBlocksBothGetAndHeadAgainstTheRealReposiliteSidecarWhileLeavingTheBytesInPlace() {
|
||||
byte[] content = "archive-me-bytes".getBytes(StandardCharsets.UTF_8);
|
||||
String gav = "com/example/archiveme/1.0.0/archiveme-1.0.0.jar";
|
||||
given().header("Authorization", "Bearer " + bearerToken).body(content)
|
||||
.put("/codeartifact/maven/" + DOMAIN + "/" + REPO + "/" + gav)
|
||||
.then().statusCode(200);
|
||||
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"versions\":[\"1.0.0\"],\"targetStatus\":\"Archived\"}")
|
||||
.post("/v1/package/versions/update_status?domain=" + DOMAIN + "&repository=" + REPO
|
||||
+ "&format=maven&namespace=com.example&package=archiveme")
|
||||
.then().statusCode(200)
|
||||
.body("successfulVersions['1.0.0'].status", equalTo("Archived"));
|
||||
|
||||
given().header("Authorization", "Bearer " + bearerToken)
|
||||
.get("/codeartifact/maven/" + DOMAIN + "/" + REPO + "/" + gav)
|
||||
.then().statusCode(404);
|
||||
given().header("Authorization", "Bearer " + bearerToken)
|
||||
.head("/codeartifact/maven/" + DOMAIN + "/" + REPO + "/" + gav)
|
||||
.then().statusCode(404);
|
||||
|
||||
given().header("Authorization", AUTH)
|
||||
.post("/v1/package/versions?domain=" + DOMAIN + "&repository=" + REPO + "&format=maven"
|
||||
+ "&namespace=com.example&package=archiveme&status=Archived")
|
||||
.then().statusCode(200)
|
||||
.body("versions[0].version", equalTo("1.0.0"))
|
||||
.body("versions[0].status", equalTo("Archived"));
|
||||
|
||||
// Proves the block above is this check's own override, not Reposilite having genuinely
|
||||
// lost the file the way the dispose test's 404 does: un-archiving must make the exact
|
||||
// same bytes fetchable again, with nothing re-deployed in between.
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"versions\":[\"1.0.0\"],\"targetStatus\":\"Published\"}")
|
||||
.post("/v1/package/versions/update_status?domain=" + DOMAIN + "&repository=" + REPO
|
||||
+ "&format=maven&namespace=com.example&package=archiveme")
|
||||
.then().statusCode(200)
|
||||
.body("successfulVersions['1.0.0'].status", equalTo("Published"));
|
||||
byte[] fetchedAfterUnarchive = given().header("Authorization", "Bearer " + bearerToken)
|
||||
.get("/codeartifact/maven/" + DOMAIN + "/" + REPO + "/" + gav)
|
||||
.then().statusCode(200)
|
||||
.extract().asByteArray();
|
||||
assertEquals(new String(content, StandardCharsets.UTF_8),
|
||||
new String(fetchedAfterUnarchive, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
* A throwaway groupId/artifactId, not {@link #GAV}: deleting it exercises Reposilite's real
|
||||
* directory delete (confirmed live before this was built: a single {@code DELETE} on the
|
||||
|
||||
+157
@@ -45,6 +45,7 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -899,6 +900,162 @@ class CodeArtifactNpmDataPlaneTest {
|
||||
assertEquals(true, upstreamReceivedPut.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes 10-NATIVE-STATUS for npm: a plain {@code npm install} download of a tarball whose
|
||||
* version this service has Archived must 404 without ever reaching Verdaccio, the same way a
|
||||
* publish to that coordinate is already refused above.
|
||||
*/
|
||||
@Test
|
||||
void aTarballDownloadOfAnArchivedVersionIsBlockedWithoutForwarding() throws Exception {
|
||||
AtomicReference<Boolean> upstreamReceivedGet = new AtomicReference<>(false);
|
||||
upstream = vertx.createHttpServer()
|
||||
.requestHandler(request -> {
|
||||
if (request.method() == HttpMethod.GET) {
|
||||
upstreamReceivedGet.set(true);
|
||||
}
|
||||
request.response().setStatusCode(200).end("tarball bytes");
|
||||
})
|
||||
.listen(0, "127.0.0.1")
|
||||
.toCompletionStage().toCompletableFuture().get(2, TimeUnit.SECONDS);
|
||||
|
||||
CodeArtifactService service = mock(CodeArtifactService.class);
|
||||
when(service.resolveAuthorizationToken("good-token", DOMAIN))
|
||||
.thenReturn(Optional.of(new AuthorizationTokenScope("000000000000", "us-east-1")));
|
||||
when(service.ensureFormatContainerId("npm", "us-east-1", DOMAIN, "000000000000", REPOSITORY))
|
||||
.thenReturn(NPM_REPOSITORY_ID);
|
||||
doReturn(Map.of("1.0.0", new Object())).when(service).containerBackedOverridesForPackage(
|
||||
eq("000000000000"), eq("us-east-1"), eq(DOMAIN), eq(REPOSITORY), eq("npm"), isNull(),
|
||||
eq("my-pkg"));
|
||||
doThrow(new AwsException("ResourceNotFoundException", "Package version '1.0.0' was not found.", 404))
|
||||
.when(service).requireContainerBackedVersionDownloadable(eq("000000000000"), eq("us-east-1"),
|
||||
eq(DOMAIN), eq(REPOSITORY), eq("npm"), isNull(), eq("my-pkg"), eq("1.0.0"),
|
||||
eq(NPM_REPOSITORY_ID));
|
||||
VerdaccioSidecarClient verdaccioClient = mock(VerdaccioSidecarClient.class);
|
||||
when(verdaccioClient.ensureReady(eq(NPM_REPOSITORY_ID), anyString()))
|
||||
.thenReturn("http://127.0.0.1:" + upstream.actualPort());
|
||||
when(verdaccioClient.versionForTarballFilename(eq(NPM_REPOSITORY_ID), eq(DOMAIN), eq(REPOSITORY), isNull(),
|
||||
eq("my-pkg"), eq("my-pkg-1.0.0.tgz"))).thenReturn(Optional.of("1.0.0"));
|
||||
startDataPlane(service, verdaccioClient);
|
||||
|
||||
HttpResponse response = get("/codeartifact/npm/" + DOMAIN + "/" + REPOSITORY + "/my-pkg/-/my-pkg-1.0.0.tgz",
|
||||
"good-token");
|
||||
|
||||
assertEquals(404, response.statusCode());
|
||||
assertEquals(false, upstreamReceivedGet.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Raised by Greptile's review: a real npm {@code dist.tarball} filename is not required to
|
||||
* embed its version at all, so this must resolve the real coordinate against Verdaccio's own
|
||||
* packument, not by stripping a {@code <packageName>-<version>.tgz} shape out of the filename
|
||||
* text. A tarball literally named {@code bundle.tgz} for version {@code 1.0.0} must still be
|
||||
* blocked once that version is Archived.
|
||||
*/
|
||||
@Test
|
||||
void aTarballDownloadWhoseFilenameDoesNotEmbedItsVersionIsStillBlockedWhenArchived() throws Exception {
|
||||
AtomicReference<Boolean> upstreamReceivedGet = new AtomicReference<>(false);
|
||||
upstream = vertx.createHttpServer()
|
||||
.requestHandler(request -> {
|
||||
if (request.method() == HttpMethod.GET) {
|
||||
upstreamReceivedGet.set(true);
|
||||
}
|
||||
request.response().setStatusCode(200).end("tarball bytes");
|
||||
})
|
||||
.listen(0, "127.0.0.1")
|
||||
.toCompletionStage().toCompletableFuture().get(2, TimeUnit.SECONDS);
|
||||
|
||||
CodeArtifactService service = mock(CodeArtifactService.class);
|
||||
when(service.resolveAuthorizationToken("good-token", DOMAIN))
|
||||
.thenReturn(Optional.of(new AuthorizationTokenScope("000000000000", "us-east-1")));
|
||||
when(service.ensureFormatContainerId("npm", "us-east-1", DOMAIN, "000000000000", REPOSITORY))
|
||||
.thenReturn(NPM_REPOSITORY_ID);
|
||||
doReturn(Map.of("1.0.0", new Object())).when(service).containerBackedOverridesForPackage(
|
||||
eq("000000000000"), eq("us-east-1"), eq(DOMAIN), eq(REPOSITORY), eq("npm"), isNull(),
|
||||
eq("my-pkg"));
|
||||
doThrow(new AwsException("ResourceNotFoundException", "Package version '1.0.0' was not found.", 404))
|
||||
.when(service).requireContainerBackedVersionDownloadable(eq("000000000000"), eq("us-east-1"),
|
||||
eq(DOMAIN), eq(REPOSITORY), eq("npm"), isNull(), eq("my-pkg"), eq("1.0.0"),
|
||||
eq(NPM_REPOSITORY_ID));
|
||||
VerdaccioSidecarClient verdaccioClient = mock(VerdaccioSidecarClient.class);
|
||||
when(verdaccioClient.ensureReady(eq(NPM_REPOSITORY_ID), anyString()))
|
||||
.thenReturn("http://127.0.0.1:" + upstream.actualPort());
|
||||
when(verdaccioClient.versionForTarballFilename(eq(NPM_REPOSITORY_ID), eq(DOMAIN), eq(REPOSITORY), isNull(),
|
||||
eq("my-pkg"), eq("bundle.tgz"))).thenReturn(Optional.of("1.0.0"));
|
||||
startDataPlane(service, verdaccioClient);
|
||||
|
||||
HttpResponse response = get("/codeartifact/npm/" + DOMAIN + "/" + REPOSITORY + "/my-pkg/-/bundle.tgz",
|
||||
"good-token");
|
||||
|
||||
assertEquals(404, response.statusCode());
|
||||
assertEquals(false, upstreamReceivedGet.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* The scope has to be decoded off the path and passed through as the namespace before the
|
||||
* check even runs, the same {@code %2F}/{@code %2f} decoding {@link
|
||||
* CodeArtifactNpmDataPlane#packageIdentityFromPath} already does for a publish; an
|
||||
* unarchived version still proxies through once the check passes.
|
||||
*/
|
||||
@Test
|
||||
void aTarballDownloadOfAScopedPackageParsesTheNamespaceBeforeCheckingTheOverride() throws Exception {
|
||||
upstream = vertx.createHttpServer()
|
||||
.requestHandler(request -> request.response().setStatusCode(200).end("tarball bytes"))
|
||||
.listen(0, "127.0.0.1")
|
||||
.toCompletionStage().toCompletableFuture().get(2, TimeUnit.SECONDS);
|
||||
|
||||
CodeArtifactService service = mock(CodeArtifactService.class);
|
||||
when(service.resolveAuthorizationToken("good-token", DOMAIN))
|
||||
.thenReturn(Optional.of(new AuthorizationTokenScope("000000000000", "us-east-1")));
|
||||
when(service.ensureFormatContainerId("npm", "us-east-1", DOMAIN, "000000000000", REPOSITORY))
|
||||
.thenReturn(NPM_REPOSITORY_ID);
|
||||
doReturn(Map.of("1.0.0", new Object())).when(service).containerBackedOverridesForPackage(
|
||||
eq("000000000000"), eq("us-east-1"), eq(DOMAIN), eq(REPOSITORY), eq("npm"), eq("myscope"),
|
||||
eq("my-pkg"));
|
||||
VerdaccioSidecarClient verdaccioClient = mock(VerdaccioSidecarClient.class);
|
||||
when(verdaccioClient.ensureReady(eq(NPM_REPOSITORY_ID), anyString()))
|
||||
.thenReturn("http://127.0.0.1:" + upstream.actualPort());
|
||||
when(verdaccioClient.versionForTarballFilename(eq(NPM_REPOSITORY_ID), eq(DOMAIN), eq(REPOSITORY),
|
||||
eq("myscope"), eq("my-pkg"), eq("my-pkg-1.0.0.tgz"))).thenReturn(Optional.of("1.0.0"));
|
||||
startDataPlane(service, verdaccioClient);
|
||||
|
||||
HttpResponse response = get("/codeartifact/npm/" + DOMAIN + "/" + REPOSITORY
|
||||
+ "/@myscope%2fmy-pkg/-/my-pkg-1.0.0.tgz", "good-token");
|
||||
|
||||
assertEquals(200, response.statusCode());
|
||||
verify(service).requireContainerBackedVersionDownloadable(eq("000000000000"), eq("us-east-1"), eq(DOMAIN),
|
||||
eq(REPOSITORY), eq("npm"), eq("myscope"), eq("my-pkg"), eq("1.0.0"), eq(NPM_REPOSITORY_ID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Guards against the marker detection over-triggering: a plain packument fetch (no {@code /-/}
|
||||
* in the path at all) must never reach the download guard, the same way {@link
|
||||
* CodeArtifactNpmDataPlane#nativeUnpublishTarget} only matches its own {@code /-rev/} marker
|
||||
* and leaves every other shape alone.
|
||||
*/
|
||||
@Test
|
||||
void aPlainPackageMetadataGetNeverConsultsTheDownloadGuard() throws Exception {
|
||||
upstream = vertx.createHttpServer()
|
||||
.requestHandler(request -> request.response().setStatusCode(200).end("{}"))
|
||||
.listen(0, "127.0.0.1")
|
||||
.toCompletionStage().toCompletableFuture().get(2, TimeUnit.SECONDS);
|
||||
|
||||
CodeArtifactService service = mock(CodeArtifactService.class);
|
||||
when(service.resolveAuthorizationToken("good-token", DOMAIN))
|
||||
.thenReturn(Optional.of(new AuthorizationTokenScope("000000000000", "us-east-1")));
|
||||
when(service.ensureFormatContainerId("npm", "us-east-1", DOMAIN, "000000000000", REPOSITORY))
|
||||
.thenReturn(NPM_REPOSITORY_ID);
|
||||
VerdaccioSidecarClient verdaccioClient = mock(VerdaccioSidecarClient.class);
|
||||
when(verdaccioClient.ensureReady(eq(NPM_REPOSITORY_ID), anyString()))
|
||||
.thenReturn("http://127.0.0.1:" + upstream.actualPort());
|
||||
startDataPlane(service, verdaccioClient);
|
||||
|
||||
HttpResponse response = get("/codeartifact/npm/" + DOMAIN + "/" + REPOSITORY + "/my-pkg", "good-token");
|
||||
|
||||
assertEquals(200, response.statusCode());
|
||||
verify(service, never()).requireContainerBackedVersionDownloadable(any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any());
|
||||
}
|
||||
|
||||
private void startDataPlane(CodeArtifactService service, VerdaccioSidecarClient verdaccioClient)
|
||||
throws Exception {
|
||||
startDataPlane(service, verdaccioClient, true);
|
||||
|
||||
+49
@@ -824,6 +824,55 @@ class CodeArtifactNpmDockerIntegrationTest {
|
||||
assertEquals("myscope", namespaces.get(names.indexOf(scopedPackage)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes 10-NATIVE-STATUS for npm: a plain {@code npm install} download of an Archived
|
||||
* version's real tarball must 404 against the live Verdaccio sidecar, even though the tarball
|
||||
* itself is still sitting there untouched. Its own package, not {@link #PACKAGE_NAME}, so
|
||||
* archiving it can't disturb any other ordered test in this class.
|
||||
*/
|
||||
@Test
|
||||
@Order(22)
|
||||
void archivingAVersionBlocksItsRealVerdaccioTarballDownloadWhileLeavingTheBytesInPlace() {
|
||||
String packageName = "archive-download-pkg";
|
||||
byte[] tarball = "archive download 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().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"versions\":[\"1.0.0\"],\"targetStatus\":\"Archived\"}")
|
||||
.post("/v1/package/versions/update_status?domain=" + DOMAIN + "&repository=" + REPO
|
||||
+ "&format=npm&package=" + packageName)
|
||||
.then().statusCode(200)
|
||||
.body("successfulVersions['1.0.0'].status", equalTo("Archived"));
|
||||
|
||||
given().header("Authorization", "Bearer " + bearerToken)
|
||||
.get("/codeartifact/npm/" + DOMAIN + "/" + REPO + "/" + packageName + "/-/" + packageName
|
||||
+ "-1.0.0.tgz")
|
||||
.then().statusCode(404);
|
||||
|
||||
// Proves the block above is this check's own override, not Verdaccio having genuinely
|
||||
// lost the tarball: un-archiving must make the exact same bytes fetchable again, with
|
||||
// nothing re-published in between.
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"versions\":[\"1.0.0\"],\"targetStatus\":\"Published\"}")
|
||||
.post("/v1/package/versions/update_status?domain=" + DOMAIN + "&repository=" + REPO
|
||||
+ "&format=npm&package=" + packageName)
|
||||
.then().statusCode(200)
|
||||
.body("successfulVersions['1.0.0'].status", equalTo("Published"));
|
||||
byte[] fetchedAfterUnarchive = given().header("Authorization", "Bearer " + bearerToken)
|
||||
.get("/codeartifact/npm/" + DOMAIN + "/" + REPO + "/" + packageName + "/-/" + packageName
|
||||
+ "-1.0.0.tgz")
|
||||
.then().statusCode(200)
|
||||
.extract().asByteArray();
|
||||
assertArrayEquals(tarball, fetchedAfterUnarchive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Proves the actual mechanism, not just that {@code VerdaccioSidecarManager} has a method
|
||||
* named right: {@code ContainerTeardowns.stopAll} runs every {@code ContainerTeardown} on
|
||||
|
||||
+47
@@ -514,6 +514,53 @@ class CodeArtifactNuGetDockerIntegrationTest {
|
||||
+ packageId.toLowerCase(Locale.ROOT) + " among " + names);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes 10-NATIVE-STATUS for nuget: a plain {@code dotnet restore}/{@code nuget install}
|
||||
* download of an Archived version's real {@code .nupkg} must 404 against the live BaGetter
|
||||
* sidecar, even though the file itself is still sitting there untouched. Its own package, not
|
||||
* {@link #PACKAGE_ID}, so archiving it can't disturb any other ordered test in this class.
|
||||
*/
|
||||
@Test
|
||||
@Order(17)
|
||||
void archivingAVersionBlocksItsRealBagetterContentDownloadWhileLeavingTheBytesInPlace() {
|
||||
String packageId = "Archive.Download.Package";
|
||||
String lowerId = packageId.toLowerCase(Locale.ROOT);
|
||||
byte[] nupkg = buildNupkg(packageId, VERSION, "Archive download throwaway.", null, null);
|
||||
given().header("Authorization", "Bearer " + bearerToken)
|
||||
.contentType("multipart/form-data; boundary=boundary123")
|
||||
.body(pushBody("boundary123", nupkg))
|
||||
.put("/codeartifact/nuget/" + DOMAIN + "/" + REPO + "/api/v2/package")
|
||||
.then().statusCode(201);
|
||||
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"versions\":[\"" + VERSION + "\"],\"targetStatus\":\"Archived\"}")
|
||||
.post("/v1/package/versions/update_status?domain=" + DOMAIN + "&repository=" + REPO
|
||||
+ "&format=nuget&package=" + packageId)
|
||||
.then().statusCode(200)
|
||||
.body("successfulVersions['" + VERSION + "'].status", equalTo("Archived"));
|
||||
|
||||
given().header("Authorization", "Bearer " + bearerToken)
|
||||
.get("/codeartifact/nuget/" + DOMAIN + "/" + REPO + "/v3/package/" + lowerId + "/" + VERSION + "/"
|
||||
+ lowerId + "." + VERSION + ".nupkg")
|
||||
.then().statusCode(404);
|
||||
|
||||
// Proves the block above is this check's own override, not BaGetter having genuinely
|
||||
// lost the file: un-archiving must make the exact same bytes fetchable again, with
|
||||
// nothing re-pushed in between.
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"versions\":[\"" + VERSION + "\"],\"targetStatus\":\"Published\"}")
|
||||
.post("/v1/package/versions/update_status?domain=" + DOMAIN + "&repository=" + REPO
|
||||
+ "&format=nuget&package=" + packageId)
|
||||
.then().statusCode(200)
|
||||
.body("successfulVersions['" + VERSION + "'].status", equalTo("Published"));
|
||||
byte[] fetchedAfterUnarchive = given().header("Authorization", "Bearer " + bearerToken)
|
||||
.get("/codeartifact/nuget/" + DOMAIN + "/" + REPO + "/v3/package/" + lowerId + "/" + VERSION + "/"
|
||||
+ lowerId + "." + VERSION + ".nupkg")
|
||||
.then().statusCode(200)
|
||||
.extract().asByteArray();
|
||||
assertArrayEquals(nupkg, fetchedAfterUnarchive);
|
||||
}
|
||||
|
||||
private static long describeDomainAssetSizeBytes() {
|
||||
return given().header("Authorization", AUTH)
|
||||
.get("/v1/domain?domain=" + DOMAIN)
|
||||
|
||||
+61
@@ -77,6 +77,11 @@ class CodeArtifactPypiControllerTest {
|
||||
.thenReturn(Optional.of(new AuthorizationTokenScope(OWNER, REGION)));
|
||||
when(service.ensureFormatContainerId(eq("pypi"), eq(REGION), eq(DOMAIN), eq(OWNER), eq(REPOSITORY)))
|
||||
.thenReturn("pypi-repo-id");
|
||||
// Matches a real repository with no UpdatePackageVersionsStatus/DisposePackageVersions
|
||||
// call ever made against it: archivedOrDisposedVersionFromFilename's own scan has nothing
|
||||
// to check, so downloadFile proxies straight through unless a test below overrides this.
|
||||
when(service.containerBackedOverriddenVersionStatusesByRepository(eq(REGION), eq(DOMAIN), eq(OWNER),
|
||||
eq(REPOSITORY), eq("pypi"))).thenReturn(Map.of());
|
||||
when(pypiserver.ensureReady(eq("pypi-repo-id"), any())).thenReturn(backendUrl);
|
||||
|
||||
HttpClient httpClient = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build();
|
||||
@@ -183,6 +188,62 @@ class CodeArtifactPypiControllerTest {
|
||||
assertEquals("/packages/..%2Fsecret.tar.gz", observedRawPath.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes 10-NATIVE-STATUS for pypi: {@code downloadFile}'s own route is a bare filename with
|
||||
* no package name or version anywhere in the URL, unlike Maven's GAV path or nuget's content
|
||||
* route, so the coordinate {@code requireContainerBackedVersionDownloadable} needs is resolved
|
||||
* by matching the filename against this repository's own Archived/Disposed status overrides
|
||||
* (see {@code archivedOrDisposedVersionFromFilename}), not a separate map recorded only at
|
||||
* upload time: raised by Greptile's review, that earlier mechanism was never populated by a
|
||||
* version {@code CopyPackageVersions} wrote straight to the destination sidecar, so archiving
|
||||
* a copied version never blocked its download. Resolving against the override records
|
||||
* instead works regardless of how the real file got there.
|
||||
*/
|
||||
@Test
|
||||
void downloadFileBlocksAFileWhoseVersionIsArchived() {
|
||||
// No controller.upload call at all, deliberately: proves this resolves against the
|
||||
// override records themselves, not anything an upload would have recorded, the exact
|
||||
// case a version CopyPackageVersions wrote straight to the destination sidecar is in.
|
||||
when(service.containerBackedOverriddenVersionStatusesByRepository(eq(REGION), eq(DOMAIN), eq(OWNER),
|
||||
eq(REPOSITORY), eq("pypi"))).thenReturn(Map.of("my-pkg", Map.of("1.0.0", "Archived")));
|
||||
|
||||
AtomicBoolean downloadReceived = new AtomicBoolean();
|
||||
backend.createContext("/packages/my_pkg-1.0.0.tar.gz", exchange -> {
|
||||
downloadReceived.set(true);
|
||||
respond(exchange, 200, "application/octet-stream", "new content");
|
||||
});
|
||||
doThrow(new AwsException("ResourceNotFoundException", "Package version '1.0.0' was not found.", 404))
|
||||
.when(service).requireContainerBackedVersionDownloadable(eq(OWNER), eq(REGION), eq(DOMAIN),
|
||||
eq(REPOSITORY), eq("pypi"), isNull(), eq("my-pkg"), eq("1.0.0"), eq("pypi-repo-id"));
|
||||
|
||||
Response response = controller.downloadFile(headers("Bearer good"), DOMAIN, REPOSITORY,
|
||||
"my_pkg-1.0.0.tar.gz");
|
||||
|
||||
assertEquals(404, response.getStatus());
|
||||
assertEquals(false, downloadReceived.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* The overwhelmingly common case: a repository nothing has ever called {@code
|
||||
* UpdatePackageVersionsStatus}/{@code DisposePackageVersions} against has no overrides at all
|
||||
* (the default this class's own {@code setUp} already stubs), so {@code
|
||||
* archivedOrDisposedVersionFromFilename} finds nothing to match and the download proxies
|
||||
* straight through without ever consulting {@code requireContainerBackedVersionDownloadable}.
|
||||
*/
|
||||
@Test
|
||||
void downloadFileOfAnUntrackedFilenameSkipsTheCheckAndStillProxies() {
|
||||
byte[] content = "package bytes".getBytes(StandardCharsets.UTF_8);
|
||||
backend.createContext("/packages/never-uploaded-1.0.tar.gz",
|
||||
exchange -> respond(exchange, 200, "application/octet-stream", content));
|
||||
|
||||
Response response = controller.downloadFile(headers("Bearer good"), DOMAIN, REPOSITORY,
|
||||
"never-uploaded-1.0.tar.gz");
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
verify(service, never()).requireContainerBackedVersionDownloadable(any(), any(), any(), any(), any(), any(),
|
||||
any(), any(), any());
|
||||
}
|
||||
|
||||
/**
|
||||
* Same finding again, via the other wire-protocol route that shares the same {@code proxyGet}
|
||||
* helper: the package name in {@code GET /simple/{package}/} is just as caller-supplied as
|
||||
|
||||
+50
@@ -798,6 +798,56 @@ class CodeArtifactPypiDockerIntegrationTest {
|
||||
assertTrue(names.contains("list-packages-probe"), "expected list-packages-probe among " + names);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes 10-NATIVE-STATUS for pypi: a plain {@code pip install} download of an Archived
|
||||
* version's real file must 404 against the live pypiserver sidecar, even though the file
|
||||
* itself is still sitting there untouched. This is the one format whose download route is a
|
||||
* bare filename with no package name or version in the URL at all (see {@code
|
||||
* CodeArtifactPypiController#fileIdentitiesByRepo}'s own javadoc), so this also proves the
|
||||
* identity this test's own upload recorded is what the download route resolved the coordinate
|
||||
* from. Its own package, not {@link #PACKAGE_NAME}, so archiving it can't disturb any other
|
||||
* ordered test in this class.
|
||||
*/
|
||||
@Test
|
||||
@Order(22)
|
||||
void archivingAVersionBlocksItsRealPypiserverFileDownloadWhileLeavingTheBytesInPlace() {
|
||||
String packageName = "archive-download-pypi-pkg";
|
||||
String filename = "archive_download_pypi_pkg-1.0.0.tar.gz";
|
||||
byte[] content = "archive download throwaway sdist".getBytes(StandardCharsets.UTF_8);
|
||||
given().header("Authorization", "Bearer " + bearerToken)
|
||||
.contentType("multipart/form-data; boundary=boundary123")
|
||||
.body(twineUploadBody("boundary123", packageName, filename, content))
|
||||
.post("/codeartifact/pypi/" + DOMAIN + "/" + REPO + "/")
|
||||
.then().statusCode(200);
|
||||
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"versions\":[\"1.0.0\"],\"targetStatus\":\"Archived\"}")
|
||||
.post("/v1/package/versions/update_status?domain=" + DOMAIN + "&repository=" + REPO
|
||||
+ "&format=pypi&package=" + packageName)
|
||||
.then().statusCode(200)
|
||||
.body("successfulVersions['1.0.0'].status", equalTo("Archived"));
|
||||
|
||||
given().header("Authorization", "Bearer " + bearerToken)
|
||||
.get("/codeartifact/pypi/" + DOMAIN + "/" + REPO + "/packages/" + filename)
|
||||
.then().statusCode(404);
|
||||
|
||||
// Proves the block above is this check's own override, not pypiserver having genuinely
|
||||
// lost the file: un-archiving must make the exact same bytes fetchable again, with
|
||||
// nothing re-uploaded in between.
|
||||
given().contentType("application/json").header("Authorization", AUTH)
|
||||
.body("{\"versions\":[\"1.0.0\"],\"targetStatus\":\"Published\"}")
|
||||
.post("/v1/package/versions/update_status?domain=" + DOMAIN + "&repository=" + REPO
|
||||
+ "&format=pypi&package=" + packageName)
|
||||
.then().statusCode(200)
|
||||
.body("successfulVersions['1.0.0'].status", equalTo("Published"));
|
||||
byte[] fetchedAfterUnarchive = given().header("Authorization", "Bearer " + bearerToken)
|
||||
.get("/codeartifact/pypi/" + DOMAIN + "/" + REPO + "/packages/" + filename)
|
||||
.then().statusCode(200)
|
||||
.extract().asByteArray();
|
||||
assertEquals(new String(content, StandardCharsets.UTF_8),
|
||||
new String(fetchedAfterUnarchive, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
* Proves the actual mechanism, not just that {@code PypiserverSidecarManager} has a method
|
||||
* named right: {@code ContainerTeardowns.stopAll} runs every {@code ContainerTeardown} on
|
||||
|
||||
+46
@@ -4768,6 +4768,52 @@ class CodeArtifactServiceTest {
|
||||
"repo", "maven", "com.example", "a", "4.0-never-touched"));
|
||||
}
|
||||
|
||||
/**
|
||||
* The download-side counterpart: every native per-format proxy controller (Maven, npm, nuget,
|
||||
* pypi) calls this before serving bytes straight from its own sidecar, the mechanism that
|
||||
* closes 10-NATIVE-STATUS. Must block only {@code Archived} (the status whose real sidecar
|
||||
* bytes are deliberately left in place, unlike {@code Disposed}, which already deletes them)
|
||||
* and let every other status, including a version never touched at all, through unchanged,
|
||||
* the exact same four-way split {@link #requireContainerBackedVersionNotArchivedOrDisposedBlocksOnlyThoseTwoStatuses}
|
||||
* already proves for the upload side, with {@code Disposed} included here too even though a
|
||||
* real native download of a disposed version would already 404 against the sidecar itself for
|
||||
* an unrelated reason (its bytes are gone), since this method's own contract blocks both
|
||||
* statuses regardless of whether the sidecar would have caught it anyway.
|
||||
*/
|
||||
@Test
|
||||
void requireContainerBackedVersionDownloadableBlocksOnlyArchivedAndDisposed() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
String repoId = created.getSidecarContainerIds().get("maven");
|
||||
when(reposiliteClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
|
||||
eq("a"))).thenReturn(List.of(
|
||||
new RepositorySidecarManager.PackageVersionTimestamp("1.0", Instant.ofEpochSecond(1000)),
|
||||
new RepositorySidecarManager.PackageVersionTimestamp("2.0", Instant.ofEpochSecond(1000)),
|
||||
new RepositorySidecarManager.PackageVersionTimestamp("3.0", Instant.ofEpochSecond(1000))));
|
||||
|
||||
service.updatePackageVersionsStatus(REGION, "dom", null, "repo", "maven", "com.example", "a",
|
||||
List.of("1.0"), null, null, "Archived");
|
||||
AwsException archivedError = assertThrows(AwsException.class,
|
||||
() -> service.requireContainerBackedVersionDownloadable(ACCOUNT_ID, REGION, "dom", "repo", "maven",
|
||||
"com.example", "a", "1.0", repoId));
|
||||
assertEquals("ResourceNotFoundException", archivedError.getErrorCode());
|
||||
|
||||
service.disposePackageVersions(REGION, "dom", null, "repo", "maven", "com.example", "a", List.of("2.0"),
|
||||
null, null);
|
||||
AwsException disposedError = assertThrows(AwsException.class,
|
||||
() -> service.requireContainerBackedVersionDownloadable(ACCOUNT_ID, REGION, "dom", "repo", "maven",
|
||||
"com.example", "a", "2.0", repoId));
|
||||
assertEquals("ResourceNotFoundException", disposedError.getErrorCode());
|
||||
|
||||
service.updatePackageVersionsStatus(REGION, "dom", null, "repo", "maven", "com.example", "a",
|
||||
List.of("3.0"), null, null, "Unlisted");
|
||||
assertDoesNotThrow(() -> service.requireContainerBackedVersionDownloadable(ACCOUNT_ID, REGION, "dom", "repo",
|
||||
"maven", "com.example", "a", "3.0", repoId));
|
||||
|
||||
assertDoesNotThrow(() -> service.requireContainerBackedVersionDownloadable(ACCOUNT_ID, REGION, "dom", "repo",
|
||||
"maven", "com.example", "a", "4.0-never-touched", repoId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Raised by Greptile's review: {@code requireContainerBackedVersionNotArchivedOrDisposed}'s
|
||||
* guard, the real sidecar write, and this call are necessarily three separate steps (the
|
||||
|
||||
+32
@@ -275,6 +275,38 @@ class VerdaccioSidecarClientTest {
|
||||
assertTrue(packages.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Raised by Greptile's review: a real npm {@code dist.tarball} filename is not required to
|
||||
* embed its version at all, so resolving a download's archived-status check by guessing a
|
||||
* {@code <packageName>-<version>.tgz} shape out of the filename's own text can both miss a
|
||||
* real tarball named something else entirely and misread an unrelated version out of one
|
||||
* that happens to coincidentally fit that shape. This resolves against the packument's own
|
||||
* {@code dist.tarball} instead, confirmed here with a tarball named nothing like its version.
|
||||
*/
|
||||
@Test
|
||||
void versionForTarballFilenameResolvesAFilenameThatDoesNotEmbedItsVersion() throws Exception {
|
||||
VerdaccioSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "npm-repo-1", "tracked-verdaccio-1", backendUrl);
|
||||
respondWithMetadata("/demo-pkg", "1.0.0", "/demo-pkg/-/bundle.tgz");
|
||||
|
||||
Optional<String> version = client(manager).versionForTarballFilename("npm-repo-1", "dom", "repo", null,
|
||||
"demo-pkg", "bundle.tgz");
|
||||
|
||||
assertEquals(Optional.of("1.0.0"), version);
|
||||
}
|
||||
|
||||
@Test
|
||||
void versionForTarballFilenameIsEmptyWhenNoVersionsTarballMatches() throws Exception {
|
||||
VerdaccioSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "npm-repo-1", "tracked-verdaccio-1", backendUrl);
|
||||
respondWithMetadata("/demo-pkg", "1.0.0", "/demo-pkg/-/demo-pkg-1.0.0.tgz");
|
||||
|
||||
Optional<String> version = client(manager).versionForTarballFilename("npm-repo-1", "dom", "repo", null,
|
||||
"demo-pkg", "never-published.tgz");
|
||||
|
||||
assertEquals(Optional.empty(), version);
|
||||
}
|
||||
|
||||
private VerdaccioSidecarManager manager() {
|
||||
return new VerdaccioSidecarManager(containerBuilder, lifecycleManager, config);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user