mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(codeartifact): bridge GetPackageVersionAsset to Maven, npm, and pypi sidecars (#5019)
This commit is contained in:
1 parent
2e87534941
commit
583b2baf7f
13 files changed
+1613
-24
No files matched your search
+39
@@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -358,6 +359,44 @@ class CodeArtifactMavenDockerIntegrationTest {
|
||||
assertEquals(repositoryCountBeforeDelete - 1, reposiliteSettingsRepositoryCount());
|
||||
}
|
||||
|
||||
/**
|
||||
* The real-world gap this closes: {@code GetPackageVersionAsset} used to 404 for every
|
||||
* Maven-deployed artifact since Floci's generic-format package-version store never had a
|
||||
* record for it (Maven publishing goes straight to Reposilite, bypassing it entirely). Proves
|
||||
* the JSON API now bridges to the same artifact {@link #deployThenFetchRoundTripsTheExactBytes}
|
||||
* already confirmed is really there, through the real sidecar, not a mock.
|
||||
*/
|
||||
@Test
|
||||
@Order(12)
|
||||
void getPackageVersionAssetBridgesToTheRealReposiliteSidecar() {
|
||||
byte[] fetched = given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version/asset?domain=" + DOMAIN + "&repository=" + REPO + "&format=maven"
|
||||
+ "&namespace=com.example&package=spike&version=1.0.0&asset=spike-1.0.0.jar")
|
||||
.then().statusCode(200)
|
||||
.header("X-AssetName", equalTo("spike-1.0.0.jar"))
|
||||
.header("X-PackageVersion", equalTo("1.0.0"))
|
||||
.extract().asByteArray();
|
||||
assertEquals("real-jar-bytes", new String(fetched, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void getPackageVersionAssetRequiresANamespaceForMaven() {
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version/asset?domain=" + DOMAIN + "&repository=" + REPO + "&format=maven"
|
||||
+ "&package=spike&version=1.0.0&asset=spike-1.0.0.jar")
|
||||
.then().statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void getPackageVersionAssetReturns404ForAMavenAssetThatWasNeverDeployed() {
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version/asset?domain=" + DOMAIN + "&repository=" + REPO + "&format=maven"
|
||||
+ "&namespace=com.example&package=spike&version=1.0.0&asset=does-not-exist.jar")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the real Reposilite instance's own {@code maven} settings domain directly (the same
|
||||
* shared container {@link ReposiliteSidecarManager} started for every test in this class).
|
||||
|
||||
+29
@@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.anyOf;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
@@ -284,6 +285,34 @@ class CodeArtifactNpmDockerIntegrationTest {
|
||||
.then().statusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* The real-world gap this closes: {@code GetPackageVersionAsset} used to 404 for every
|
||||
* npm-published package since Floci's generic-format package-version store never had a
|
||||
* record for it (npm publishing goes straight to Verdaccio, bypassing it entirely). Proves the
|
||||
* JSON API now bridges to the same tarball {@link #publishThenFetchRoundTripsTheRealNpmEnvelope}
|
||||
* already confirmed is really there, through the real sidecar, not a mock.
|
||||
*/
|
||||
@Test
|
||||
@Order(9)
|
||||
void getPackageVersionAssetBridgesToTheRealVerdaccioSidecar() throws IOException {
|
||||
byte[] fetched = given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version/asset?domain=" + DOMAIN + "&repository=" + REPO + "&format=npm"
|
||||
+ "&package=" + PACKAGE_NAME + "&version=1.0.0&asset=" + PACKAGE_NAME + "-1.0.0.tgz")
|
||||
.then().statusCode(200)
|
||||
.header("X-AssetName", equalTo(PACKAGE_NAME + "-1.0.0.tgz"))
|
||||
.extract().asByteArray();
|
||||
assertArrayEquals(expectedTarballBytes, fetched);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void getPackageVersionAssetReturns404ForAnNpmAssetThatWasNeverPublished() {
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version/asset?domain=" + DOMAIN + "&repository=" + REPO + "&format=npm"
|
||||
+ "&package=" + PACKAGE_NAME + "&version=1.0.0&asset=does-not-exist.tgz")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* Proves the actual mechanism, not just that {@code VerdaccioSidecarManager} has a method
|
||||
* named right: {@code ContainerTeardowns.stopAll} runs every {@code ContainerTeardown} on
|
||||
|
||||
+30
@@ -20,6 +20,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -317,6 +318,35 @@ class CodeArtifactPypiDockerIntegrationTest {
|
||||
.then().statusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* The real-world gap this closes: {@code GetPackageVersionAsset} used to 404 for every
|
||||
* pypi-published file since Floci's generic-format package-version store never had a record
|
||||
* for it (pypi publishing goes straight to pypiserver, bypassing it entirely). Proves the JSON
|
||||
* API now bridges to the same file {@link #uploadThenDownloadRoundTripsTheExactBytesThroughTheSimpleIndex}
|
||||
* already confirmed is really there, through the real sidecar, not a mock. No namespace: pypi
|
||||
* packages don't have one.
|
||||
*/
|
||||
@Test
|
||||
@Order(12)
|
||||
void getPackageVersionAssetBridgesToTheRealPypiserverSidecar() {
|
||||
byte[] fetched = given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version/asset?domain=" + DOMAIN + "&repository=" + REPO + "&format=pypi"
|
||||
+ "&package=" + PACKAGE_NAME + "&version=1.0.0&asset=" + FILENAME)
|
||||
.then().statusCode(200)
|
||||
.header("X-AssetName", equalTo(FILENAME))
|
||||
.extract().asByteArray();
|
||||
assertEquals("real-sdist-bytes", new String(fetched, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void getPackageVersionAssetReturns404ForAPypiAssetThatWasNeverUploaded() {
|
||||
given().header("Authorization", AUTH)
|
||||
.get("/v1/package/version/asset?domain=" + DOMAIN + "&repository=" + REPO + "&format=pypi"
|
||||
+ "&package=" + PACKAGE_NAME + "&version=1.0.0&asset=does-not-exist.tar.gz")
|
||||
.then().statusCode(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* Proves the actual mechanism, not just that {@code PypiserverSidecarManager} has a method
|
||||
* named right: {@code ContainerTeardowns.stopAll} runs every {@code ContainerTeardown} on
|
||||
|
||||
+139
-1
@@ -36,6 +36,8 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -51,6 +53,7 @@ class CodeArtifactServiceTest {
|
||||
private AccountAwareStorageBackend<CodeArtifactRepository> repoStore;
|
||||
private VerdaccioSidecarManager verdaccioManager;
|
||||
private ReposiliteSidecarClient reposiliteClient;
|
||||
private PypiserverSidecarManager pypiserverManager;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
@@ -72,8 +75,11 @@ class CodeArtifactServiceTest {
|
||||
when(verdaccioManager.format()).thenReturn("npm");
|
||||
reposiliteClient = mock(ReposiliteSidecarClient.class);
|
||||
when(reposiliteClient.format()).thenReturn("maven");
|
||||
pypiserverManager = mock(PypiserverSidecarManager.class);
|
||||
when(pypiserverManager.format()).thenReturn("pypi");
|
||||
service = new CodeArtifactService(domainStore, repoStore, packageVersionStore, regionResolver, config,
|
||||
true, null, new CodeArtifactSidecarRegistry(List.of(verdaccioManager, reposiliteClient)));
|
||||
true, null, new CodeArtifactSidecarRegistry(
|
||||
List.of(verdaccioManager, reposiliteClient, pypiserverManager)));
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------- domains
|
||||
@@ -1027,6 +1033,138 @@ class CodeArtifactServiceTest {
|
||||
assertEquals("package-version", wrongRevision.getExtendedData().get("resourceType"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPackageVersionAssetBridgesToReposiliteForMavenSinceNoGenericRecordCanExist() {
|
||||
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");
|
||||
byte[] content = "jar bytes".getBytes(StandardCharsets.UTF_8);
|
||||
when(reposiliteClient.fetchPackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
|
||||
eq("my-artifact"), eq("1.0.0"), eq("my-artifact-1.0.0.jar"))).thenReturn(Optional.of(content));
|
||||
|
||||
PackageVersionAssetResult result = service.getPackageVersionAsset(REGION, "dom", null, "repo", "maven",
|
||||
"com.example", "my-artifact", "1.0.0", "my-artifact-1.0.0.jar", null);
|
||||
|
||||
assertEquals("jar bytes", new String(result.asset().getContent(), StandardCharsets.UTF_8));
|
||||
assertEquals(sha256Hex((repoId + "/com.example/my-artifact/1.0.0").getBytes(StandardCharsets.UTF_8)),
|
||||
result.packageVersionRevision());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPackageVersionAssetSynthesizesADifferentRevisionForTheSameCoordinatesInADifferentRepository() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo-a", null, null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo-b", null, null, Map.of());
|
||||
byte[] content = "jar bytes".getBytes(StandardCharsets.UTF_8);
|
||||
when(reposiliteClient.fetchPackageVersionAsset(anyString(), eq("dom"), anyString(), eq("com.example"),
|
||||
eq("my-artifact"), eq("1.0.0"), eq("my-artifact-1.0.0.jar"))).thenReturn(Optional.of(content));
|
||||
|
||||
PackageVersionAssetResult fromA = service.getPackageVersionAsset(REGION, "dom", null, "repo-a", "maven",
|
||||
"com.example", "my-artifact", "1.0.0", "my-artifact-1.0.0.jar", null);
|
||||
PackageVersionAssetResult fromB = service.getPackageVersionAsset(REGION, "dom", null, "repo-b", "maven",
|
||||
"com.example", "my-artifact", "1.0.0", "my-artifact-1.0.0.jar", null);
|
||||
|
||||
assertTrue(!fromA.packageVersionRevision().equals(fromB.packageVersionRevision()),
|
||||
"identical coordinates in two different repositories must not synthesize the same revision");
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPackageVersionAssetSynthesizesTheSameRevisionForEveryAssetOfOneMavenVersion() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
when(reposiliteClient.fetchPackageVersionAsset(anyString(), eq("dom"), eq("repo"), eq("com.example"),
|
||||
eq("my-artifact"), eq("1.0.0"), eq("my-artifact-1.0.0.jar")))
|
||||
.thenReturn(Optional.of("jar bytes".getBytes(StandardCharsets.UTF_8)));
|
||||
when(reposiliteClient.fetchPackageVersionAsset(anyString(), eq("dom"), eq("repo"), eq("com.example"),
|
||||
eq("my-artifact"), eq("1.0.0"), eq("my-artifact-1.0.0.pom")))
|
||||
.thenReturn(Optional.of("pom bytes".getBytes(StandardCharsets.UTF_8)));
|
||||
|
||||
PackageVersionAssetResult jar = service.getPackageVersionAsset(REGION, "dom", null, "repo", "maven",
|
||||
"com.example", "my-artifact", "1.0.0", "my-artifact-1.0.0.jar", null);
|
||||
String jarRevision = jar.packageVersionRevision();
|
||||
|
||||
// A client that described the version once and now fetches a second asset pinned to that
|
||||
// same revision must not get a spurious not-found just because this asset's own bytes
|
||||
// differ from the first one's.
|
||||
PackageVersionAssetResult pom = service.getPackageVersionAsset(REGION, "dom", null, "repo", "maven",
|
||||
"com.example", "my-artifact", "1.0.0", "my-artifact-1.0.0.pom", jarRevision);
|
||||
|
||||
assertEquals(jarRevision, pom.packageVersionRevision());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPackageVersionAssetRequiresNamespaceForMaven() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.getPackageVersionAsset(REGION, "dom", null,
|
||||
"repo", "maven", null, "my-artifact", "1.0.0", "my-artifact-1.0.0.jar", null));
|
||||
assertEquals("ValidationException", e.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPackageVersionAssetBridgesToVerdaccioForNpm() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
byte[] content = "tarball bytes".getBytes(StandardCharsets.UTF_8);
|
||||
when(verdaccioManager.fetchPackageVersionAsset(anyString(), eq("dom"), eq("repo"), eq("myscope"),
|
||||
eq("my-pkg"), eq("1.0.0"), eq("my-pkg-1.0.0.tgz"))).thenReturn(Optional.of(content));
|
||||
|
||||
PackageVersionAssetResult result = service.getPackageVersionAsset(REGION, "dom", null, "repo", "npm",
|
||||
"myscope", "my-pkg", "1.0.0", "my-pkg-1.0.0.tgz", null);
|
||||
|
||||
assertEquals("tarball bytes", new String(result.asset().getContent(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPackageVersionAssetBridgesToPypiserver() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
byte[] content = "wheel bytes".getBytes(StandardCharsets.UTF_8);
|
||||
when(pypiserverManager.fetchPackageVersionAsset(anyString(), eq("dom"), eq("repo"), isNull(),
|
||||
eq("my-pkg"), eq("1.0.0"), eq("my_pkg-1.0.0-py3-none-any.whl"))).thenReturn(Optional.of(content));
|
||||
|
||||
PackageVersionAssetResult result = service.getPackageVersionAsset(REGION, "dom", null, "repo", "pypi",
|
||||
null, "my-pkg", "1.0.0", "my_pkg-1.0.0-py3-none-any.whl", null);
|
||||
|
||||
assertEquals("wheel bytes", new String(result.asset().getContent(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPackageVersionAssetReturns404WhenTheSidecarHasNoSuchAssetForAContainerBackedFormat() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
when(pypiserverManager.fetchPackageVersionAsset(anyString(), eq("dom"), eq("repo"), isNull(),
|
||||
eq("my-pkg"), eq("1.0.0"), eq("missing.whl"))).thenReturn(Optional.empty());
|
||||
|
||||
AwsException e = assertThrows(AwsException.class, () -> service.getPackageVersionAsset(REGION, "dom", null,
|
||||
"repo", "pypi", null, "my-pkg", "1.0.0", "missing.whl", null));
|
||||
assertEquals("ResourceNotFoundException", e.getErrorCode());
|
||||
assertEquals("missing.whl", e.getExtendedData().get("resourceId"));
|
||||
assertEquals("asset", e.getExtendedData().get("resourceType"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPackageVersionAssetValidatesTheCallerProvidedRevisionForAContainerBackedFormatToo() {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
|
||||
byte[] content = "wheel bytes".getBytes(StandardCharsets.UTF_8);
|
||||
when(pypiserverManager.fetchPackageVersionAsset(anyString(), eq("dom"), eq("repo"), isNull(),
|
||||
eq("my-pkg"), eq("1.0.0"), eq("my_pkg-1.0.0.whl"))).thenReturn(Optional.of(content));
|
||||
String realRevision = service.getPackageVersionAsset(REGION, "dom", null, "repo", "pypi", null, "my-pkg",
|
||||
"1.0.0", "my_pkg-1.0.0.whl", null).packageVersionRevision();
|
||||
|
||||
PackageVersionAssetResult matching = service.getPackageVersionAsset(REGION, "dom", null, "repo", "pypi",
|
||||
null, "my-pkg", "1.0.0", "my_pkg-1.0.0.whl", realRevision);
|
||||
assertEquals("wheel bytes", new String(matching.asset().getContent(), StandardCharsets.UTF_8));
|
||||
|
||||
AwsException wrongRevision = assertThrows(AwsException.class, () -> service.getPackageVersionAsset(REGION,
|
||||
"dom", null, "repo", "pypi", null, "my-pkg", "1.0.0", "my_pkg-1.0.0.whl", "not-the-real-revision"));
|
||||
assertEquals("ResourceNotFoundException", wrongRevision.getErrorCode());
|
||||
assertEquals("package-version", wrongRevision.getExtendedData().get("resourceType"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void concurrentUnfinishedPublishesOfDifferentAssetsBothPersist() throws InterruptedException {
|
||||
service.createDomain(REGION, "dom", null, Map.of());
|
||||
|
||||
+367
-5
@@ -1,16 +1,26 @@
|
||||
package io.github.hectorvent.floci.services.codeartifact;
|
||||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.ContainerTeardown;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
|
||||
import io.github.hectorvent.floci.core.common.docker.PerKeyContainerPool;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
@@ -27,16 +37,368 @@ class PypiserverSidecarManagerTest {
|
||||
private final ContainerLifecycleManager lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
private final EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
|
||||
private HttpServer backend;
|
||||
private String backendUrl;
|
||||
|
||||
@BeforeEach
|
||||
void setUpBackend() throws Exception {
|
||||
backend = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
|
||||
backend.createContext("/health", exchange -> {
|
||||
exchange.sendResponseHeaders(200, -1);
|
||||
exchange.close();
|
||||
});
|
||||
backend.start();
|
||||
backendUrl = "http://127.0.0.1:" + backend.getAddress().getPort();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDownBackend() {
|
||||
backend.stop(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void implementsContainerTeardownSoStateResetAndNukeCanFindIt() {
|
||||
assertInstanceOf(ContainerTeardown.class, manager());
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchPackageVersionAssetGetsTheFlatPackagesPath() throws Exception {
|
||||
PypiserverSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "pypi-repo-1", "tracked-pypiserver-1", backendUrl);
|
||||
respondWithSimpleIndex("demo-pkg", "demo_pkg-1.0.0.tar.gz");
|
||||
backend.createContext("/packages/demo_pkg-1.0.0.tar.gz", exchange -> {
|
||||
byte[] body = "sdist bytes".getBytes(StandardCharsets.UTF_8);
|
||||
exchange.sendResponseHeaders(200, body.length);
|
||||
exchange.getResponseBody().write(body);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("pypi-repo-1", "dom", "repo", null, "demo-pkg",
|
||||
"1.0.0", "demo_pkg-1.0.0.tar.gz");
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals("sdist bytes", new String(result.get(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding: the filename alone was trusted as proof of version, so a caller
|
||||
* could request a different (even nonexistent) version and still get back a real file that
|
||||
* actually belongs to a version it never named.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetReturnsEmptyWhenTheRequestedVersionDoesNotMatchTheFilename() throws Exception {
|
||||
PypiserverSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "pypi-repo-1", "tracked-pypiserver-1", backendUrl);
|
||||
respondWithSimpleIndex("demo-pkg", "demo_pkg-1.0.0.tar.gz");
|
||||
backend.createContext("/packages/demo_pkg-1.0.0.tar.gz", exchange -> {
|
||||
byte[] body = "should never be served".getBytes(StandardCharsets.UTF_8);
|
||||
exchange.sendResponseHeaders(200, body.length);
|
||||
exchange.getResponseBody().write(body);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("pypi-repo-1", "dom", "repo", null, "demo-pkg",
|
||||
"9.9.9", "demo_pkg-1.0.0.tar.gz");
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding: a plain substring check on {@code "-" + version} would wrongly
|
||||
* accept this, since {@code pkg-1.0.1-...} literally contains the text {@code -1.0.} even
|
||||
* though the file's real version is {@code 1.0.1}, not {@code 1.0}.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetRejectsAVersionThatIsOnlyAPrefixOfTheFilenamesRealVersion() throws Exception {
|
||||
PypiserverSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "pypi-repo-1", "tracked-pypiserver-1", backendUrl);
|
||||
respondWithSimpleIndex("demo-pkg", "demo_pkg-1.0.1-py3-none-any.whl");
|
||||
backend.createContext("/packages/demo_pkg-1.0.1-py3-none-any.whl", exchange -> {
|
||||
byte[] body = "should never be served".getBytes(StandardCharsets.UTF_8);
|
||||
exchange.sendResponseHeaders(200, body.length);
|
||||
exchange.getResponseBody().write(body);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("pypi-repo-1", "dom", "repo", null, "demo-pkg",
|
||||
"1.0", "demo_pkg-1.0.1-py3-none-any.whl");
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding on top of the previous one: a PEP 440 pre/post/dev-release
|
||||
* suffix also starts right after the matched version text with a letter, not a digit, so the
|
||||
* first boundary fix (reject only when followed by another digit) still wrongly accepted
|
||||
* {@code 1.0.post1}, {@code 1.0.dev1}, and {@code 1.0.rc1} as if they were plain {@code 1.0}.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetRejectsAVersionThatIsOnlyAPrefixOfAPostReleaseSuffix() throws Exception {
|
||||
assertRequestedVersionRejectedAgainstRealVersion("1.0.post1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchPackageVersionAssetRejectsAVersionThatIsOnlyAPrefixOfADevReleaseSuffix() throws Exception {
|
||||
assertRequestedVersionRejectedAgainstRealVersion("1.0.dev1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchPackageVersionAssetRejectsAVersionThatIsOnlyAPrefixOfAReleaseCandidateSuffix() throws Exception {
|
||||
assertRequestedVersionRejectedAgainstRealVersion("1.0.rc1");
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding: {@code +} introduces a PEP 440 local-version segment, so
|
||||
* whatever follows it is always part of a longer, different version. {@code 1.0+linux} is
|
||||
* not {@code 1.0}, but a {@code +} used to be treated the same as a wheel tag's {@code -} and
|
||||
* accepted as ending the version field right there.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetRejectsAVersionThatIsOnlyAPrefixOfALocalVersionSegment() throws Exception {
|
||||
assertRequestedVersionRejectedAgainstRealVersion("1.0+linux");
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding: PEP 440 allows a bare {@code -<digits>} right after a release
|
||||
* segment, with no keyword at all, as a legacy, implicit way of writing a post-release
|
||||
* ({@code 1.0-1} means {@code 1.0.post1}). The old check treated every {@code -} right after
|
||||
* a matched version as an unconditional boundary, so this legacy form wasn't recognized as a
|
||||
* continuation.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetRejectsAVersionThatIsOnlyAPrefixOfAnImplicitPostRelease() throws Exception {
|
||||
assertRequestedVersionRejectedAgainstRealVersion("1.0-1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Same finding, the explicit-keyword form of a legacy post-release separator: PEP 440 also
|
||||
* allows {@code -} (not just {@code .}) directly before {@code post}/{@code dev}/{@code rc}.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetRejectsAVersionThatIsOnlyAPrefixOfAHyphenSeparatedPostRelease() throws Exception {
|
||||
assertRequestedVersionRejectedAgainstRealVersion("1.0-post1");
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding: {@code pre}, {@code preview}, and {@code c} are all PEP 440
|
||||
* aliases for {@code rc}, and weren't in the continuation list, so a filename using one of
|
||||
* them could sail through as if it were the plain requested version.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetRejectsAVersionThatIsOnlyAPrefixOfAPreReleaseAlias() throws Exception {
|
||||
assertRequestedVersionRejectedAgainstRealVersion("1.0.pre1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchPackageVersionAssetRejectsAVersionThatIsOnlyAPrefixOfAPreviewReleaseAlias() throws Exception {
|
||||
assertRequestedVersionRejectedAgainstRealVersion("1.0.preview1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchPackageVersionAssetRejectsAVersionThatIsOnlyAPrefixOfAShorthandReleaseCandidateAlias() throws Exception {
|
||||
assertRequestedVersionRejectedAgainstRealVersion("1.0.c1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Same finding, the post-release side: {@code r} is a PEP 440 alias for {@code post}/{@code
|
||||
* rev}, wasn't recognized either, and sits one character shorter than {@code rev} so it needs
|
||||
* its own coverage.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetRejectsAVersionThatIsOnlyAPrefixOfAShorthandPostReleaseAlias() throws Exception {
|
||||
assertRequestedVersionRejectedAgainstRealVersion("1.0-r1");
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding on the opposite side of the same area: a PEP 427 wheel build tag
|
||||
* ({@code digit+ letter*}, placed between the version and the python/abi/platform tags) looks
|
||||
* exactly like PEP 440's implicit post-release numeral at the point this check inspects, but
|
||||
* actually ends the version right there rather than continuing it. {@code demo_pkg-1.0-1-py3-
|
||||
* none-any.whl} is version {@code 1.0} with build tag {@code 1}, not version {@code 1.0.post1}.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetAcceptsAWheelBuildTagRatherThanTreatingItAsAPostRelease() throws Exception {
|
||||
PypiserverSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "pypi-repo-1", "tracked-pypiserver-1", backendUrl);
|
||||
respondWithSimpleIndex("demo-pkg", "demo_pkg-1.0-1-py3-none-any.whl");
|
||||
backend.createContext("/packages/demo_pkg-1.0-1-py3-none-any.whl", exchange -> {
|
||||
byte[] body = "wheel bytes".getBytes(StandardCharsets.UTF_8);
|
||||
exchange.sendResponseHeaders(200, body.length);
|
||||
exchange.getResponseBody().write(body);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("pypi-repo-1", "dom", "repo", null, "demo-pkg",
|
||||
"1.0", "demo_pkg-1.0-1-py3-none-any.whl");
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals("wheel bytes", new String(result.get(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding: a package name can itself contain a run of digits that looks
|
||||
* like a version, and a legacy sdist filename (pre-dating the PEP 625 escaping modern
|
||||
* {@code demo_pkg-1.0.0.tar.gz}-style filenames in this test class use) keeps the project
|
||||
* name's own hyphens literal rather than underscoring them. A package literally named {@code
|
||||
* foo-1.0-bar} at version {@code 2.0} then produces the filename {@code
|
||||
* foo-1.0-bar-2.0.tar.gz}; the old check only looked at what followed a {@code -<version>}
|
||||
* match, so the {@code -1.0-} inside the name portion looked like a complete, valid version
|
||||
* {@code 1.0} on its own, serving the version-2.0 asset for a request asking for 1.0. Fixed
|
||||
* by also requiring that what precedes the match is exactly the requested package name,
|
||||
* normalized the same way the simple-index lookup normalizes it; this filenameEmbedsVersion
|
||||
* check now fails before any request is even sent.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetRejectsAVersionThatOnlyMatchesInsideThePackageNamePortion() throws Exception {
|
||||
PypiserverSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "pypi-repo-1", "tracked-pypiserver-1", backendUrl);
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("pypi-repo-1", "dom", "repo", null, "foo-1.0-bar",
|
||||
"1.0", "foo-1.0-bar-2.0.tar.gz");
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
private void assertRequestedVersionRejectedAgainstRealVersion(String realVersion) throws Exception {
|
||||
PypiserverSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "pypi-repo-1", "tracked-pypiserver-1", backendUrl);
|
||||
String filename = "demo_pkg-" + realVersion + ".tar.gz";
|
||||
respondWithSimpleIndex("demo-pkg", filename);
|
||||
backend.createContext("/packages/" + filename, exchange -> {
|
||||
byte[] body = "should never be served".getBytes(StandardCharsets.UTF_8);
|
||||
exchange.sendResponseHeaders(200, body.length);
|
||||
exchange.getResponseBody().write(body);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("pypi-repo-1", "dom", "repo", null, "demo-pkg",
|
||||
"1.0", filename);
|
||||
|
||||
assertTrue(result.isEmpty(), "version 1.0 must not match " + filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding: the package-index check used to be a plain substring search,
|
||||
* which a shorter real filename that happens to be a substring of a different, longer real
|
||||
* filename could pass incorrectly.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetRequiresAnExactIndexEntryNotASubstringMatch() throws Exception {
|
||||
PypiserverSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "pypi-repo-1", "tracked-pypiserver-1", backendUrl);
|
||||
// The index genuinely lists a longer filename that contains the requested, shorter one as
|
||||
// a substring; the shorter one was never actually published on its own.
|
||||
respondWithSimpleIndex("demo-pkg", "demo_pkg-1.0.0.tar.gz.asc");
|
||||
backend.createContext("/packages/demo_pkg-1.0.0.tar.gz", exchange -> {
|
||||
byte[] body = "should never be served".getBytes(StandardCharsets.UTF_8);
|
||||
exchange.sendResponseHeaders(200, body.length);
|
||||
exchange.getResponseBody().write(body);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("pypi-repo-1", "dom", "repo", null, "demo-pkg",
|
||||
"1.0.0", "demo_pkg-1.0.0.tar.gz");
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchPackageVersionAssetReturnsEmptyWhenThePackageWasNeverUploaded() throws Exception {
|
||||
PypiserverSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "pypi-repo-1", "tracked-pypiserver-1", backendUrl);
|
||||
backend.createContext("/simple/demo-pkg/", exchange -> {
|
||||
exchange.sendResponseHeaders(404, -1);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("pypi-repo-1", "dom", "repo", null, "demo-pkg",
|
||||
"1.0.0", "missing.whl");
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding: pypiserver serves every file it holds flatly, regardless of
|
||||
* which package it belongs to, so without checking the named package's own simple index first,
|
||||
* a caller could name a real file that belongs to a different package in the same repository
|
||||
* and get it back under the wrong package's name.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetReturnsEmptyWhenTheFileBelongsToADifferentPackage() throws Exception {
|
||||
PypiserverSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "pypi-repo-1", "tracked-pypiserver-1", backendUrl);
|
||||
respondWithSimpleIndex("demo-pkg", "demo_pkg-1.0.0.tar.gz");
|
||||
backend.createContext("/packages/other_pkg-1.0.0.tar.gz", exchange -> {
|
||||
byte[] body = "should never be served".getBytes(StandardCharsets.UTF_8);
|
||||
exchange.sendResponseHeaders(200, body.length);
|
||||
exchange.getResponseBody().write(body);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("pypi-repo-1", "dom", "repo", null, "demo-pkg",
|
||||
"1.0.0", "other_pkg-1.0.0.tar.gz");
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchPackageVersionAssetThrowsRatherThanReportingNotFoundOnASidecarServerError() throws Exception {
|
||||
PypiserverSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "pypi-repo-1", "tracked-pypiserver-1", backendUrl);
|
||||
backend.createContext("/simple/demo-pkg/", exchange -> {
|
||||
exchange.sendResponseHeaders(500, -1);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> manager.fetchPackageVersionAsset("pypi-repo-1", "dom",
|
||||
"repo", null, "demo-pkg", "1.0.0", "demo_pkg-1.0.0.tar.gz"));
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding: the normalized package name used to be spliced straight into
|
||||
* {@code /simple/<normalized>/}. A {@code /} inside {@code packageName} would then be
|
||||
* indistinguishable from the real separators around it and could splice in extra path
|
||||
* segments. Fixed by percent-encoding the normalized name via {@code encodeSegment} before
|
||||
* it's placed in the path, so a {@code /} inside it survives only as a literal {@code %2F}
|
||||
* within that one segment. {@code packageName} is {@code a/../b}, not a cleaner {@code ../..}:
|
||||
* the PEP 503 normalization this method already applies collapses runs of {@code -_.} to a
|
||||
* single {@code -} first, which would otherwise quietly absorb a pure dot-segment attempt
|
||||
* before it ever reached the encoding this test is checking.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetTreatsASlashInThePackageNameAsLiteralNotAStructuralSeparator() throws Exception {
|
||||
PypiserverSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "pypi-repo-1", "tracked-pypiserver-1", backendUrl);
|
||||
AtomicReference<String> observedRawPath = new AtomicReference<>();
|
||||
backend.createContext("/", exchange -> {
|
||||
observedRawPath.set(exchange.getRequestURI().getRawPath());
|
||||
exchange.sendResponseHeaders(404, -1);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("pypi-repo-1", "dom", "repo", null, "a/../b",
|
||||
"1.0.0", "a/-/b-1.0.0.tar.gz");
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
assertEquals("/simple/a%2F-%2Fb/", observedRawPath.get());
|
||||
}
|
||||
|
||||
private void respondWithSimpleIndex(String packageName, String filename) {
|
||||
String html = "<a href=\"/packages/" + filename + "\">" + filename + "</a>";
|
||||
backend.createContext("/simple/" + packageName + "/", exchange -> {
|
||||
byte[] bytes = html.getBytes(StandardCharsets.UTF_8);
|
||||
exchange.getResponseHeaders().set("Content-Type", "text/html");
|
||||
exchange.sendResponseHeaders(200, bytes.length);
|
||||
exchange.getResponseBody().write(bytes);
|
||||
exchange.close();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void stopManagedContainersStopsEveryContainerThePoolIsTracking() throws Exception {
|
||||
PypiserverSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "pypi-repo-1", "tracked-pypiserver-1");
|
||||
seedPooledContainer(manager, "pypi-repo-2", "tracked-pypiserver-2");
|
||||
seedPooledContainer(manager, "pypi-repo-1", "tracked-pypiserver-1", "http://127.0.0.1:1");
|
||||
seedPooledContainer(manager, "pypi-repo-2", "tracked-pypiserver-2", "http://127.0.0.1:1");
|
||||
|
||||
manager.stopManagedContainers();
|
||||
|
||||
@@ -58,8 +420,8 @@ class PypiserverSidecarManagerTest {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void seedPooledContainer(PypiserverSidecarManager manager, String key, String containerId)
|
||||
throws Exception {
|
||||
private static void seedPooledContainer(PypiserverSidecarManager manager, String key, String containerId,
|
||||
String url) throws Exception {
|
||||
Field poolField = PypiserverSidecarManager.class.getDeclaredField("pool");
|
||||
poolField.setAccessible(true);
|
||||
PerKeyContainerPool pool = (PerKeyContainerPool) poolField.get(manager);
|
||||
@@ -68,6 +430,6 @@ class PypiserverSidecarManagerTest {
|
||||
containersField.setAccessible(true);
|
||||
ConcurrentHashMap<String, PerKeyContainerPool.StartedContainer> containers =
|
||||
(ConcurrentHashMap<String, PerKeyContainerPool.StartedContainer>) containersField.get(pool);
|
||||
containers.put(key, new PerKeyContainerPool.StartedContainer(containerId, "http://127.0.0.1:1"));
|
||||
containers.put(key, new PerKeyContainerPool.StartedContainer(containerId, url));
|
||||
}
|
||||
}
|
||||
+194
@@ -10,7 +10,9 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -23,6 +25,7 @@ import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
@@ -358,6 +361,197 @@ class ReposiliteSidecarClientTest {
|
||||
assertTrue(artifact.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchPackageVersionAssetBuildsTheGavPathFromTheGroupIdArtifactIdVersionAndFilename() {
|
||||
settingsBody.set("{\"repositories\":[{\"id\":\"dom--repo\",\"visibility\":\"PUBLIC\",\"redeployment\":false}]}");
|
||||
server.createContext("/api/settings/domain/maven", exchange -> respond(exchange, 200, settingsBody.get()));
|
||||
server.createContext("/dom--repo/com/example/nested/a/1.0/a-1.0.jar", exchange -> respond(exchange, 200, "jar-bytes"));
|
||||
|
||||
Optional<byte[]> result = client.fetchPackageVersionAsset("dom--repo", "dom", "repo", "com.example.nested",
|
||||
"a", "1.0", "a-1.0.jar");
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertArrayEquals("jar-bytes".getBytes(StandardCharsets.UTF_8), result.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding: building the request URI with a plain string concatenation
|
||||
* would let a {@code #} in a caller-supplied asset name get interpreted as a URI fragment and
|
||||
* silently dropped from the actual wire request, truncating it to a shorter, real filename.
|
||||
* Checks the path the backend actually receives, not just the outcome: {@code com.sun.net.
|
||||
* httpserver.HttpServer}'s own context matching turns out to be looser than a real HTTP
|
||||
* server's (it matches a registered {@code .../b-1.0.jar} against a request path of
|
||||
* {@code .../b-1.0.jar#forged} too), so asserting on the response alone wouldn't actually
|
||||
* distinguish the fixed behavior from the bug this is checking for.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetDoesNotTreatAHashInTheAssetNameAsAUriFragment() {
|
||||
settingsBody.set("{\"repositories\":[{\"id\":\"dom--repo\",\"visibility\":\"PUBLIC\",\"redeployment\":false}]}");
|
||||
server.createContext("/api/settings/domain/maven", exchange -> respond(exchange, 200, settingsBody.get()));
|
||||
AtomicReference<String> observedPath = new AtomicReference<>();
|
||||
server.createContext("/dom--repo/com/example/b/1.0/b-1.0.jar", exchange -> {
|
||||
observedPath.set(exchange.getRequestURI().getPath());
|
||||
respond(exchange, 404, "");
|
||||
});
|
||||
|
||||
client.fetchPackageVersionAsset("dom--repo", "dom", "repo", "com.example", "b", "1.0", "b-1.0.jar#forged");
|
||||
|
||||
assertThat(observedPath.get(), equalTo("/dom--repo/com/example/b/1.0/b-1.0.jar#forged"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchPackageVersionAssetDoesNotTreatAQuestionMarkInTheAssetNameAsAQueryString() {
|
||||
settingsBody.set("{\"repositories\":[{\"id\":\"dom--repo\",\"visibility\":\"PUBLIC\",\"redeployment\":false}]}");
|
||||
server.createContext("/api/settings/domain/maven", exchange -> respond(exchange, 200, settingsBody.get()));
|
||||
AtomicReference<String> observedPath = new AtomicReference<>();
|
||||
AtomicReference<String> observedQuery = new AtomicReference<>();
|
||||
server.createContext("/dom--repo/com/example/b/1.0/b-1.0.jar", exchange -> {
|
||||
observedPath.set(exchange.getRequestURI().getPath());
|
||||
observedQuery.set(exchange.getRequestURI().getQuery());
|
||||
respond(exchange, 404, "");
|
||||
});
|
||||
|
||||
client.fetchPackageVersionAsset("dom--repo", "dom", "repo", "com.example", "b", "1.0", "b-1.0.jar?evil=1");
|
||||
|
||||
assertThat(observedPath.get(), equalTo("/dom--repo/com/example/b/1.0/b-1.0.jar?evil=1"));
|
||||
assertThat(observedQuery.get(), is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchPackageVersionAssetReturnsEmptyWhenTheBackendHasNoSuchFile() {
|
||||
settingsBody.set("{\"repositories\":[{\"id\":\"dom--repo\",\"visibility\":\"PUBLIC\",\"redeployment\":false}]}");
|
||||
server.createContext("/api/settings/domain/maven", exchange -> respond(exchange, 200, settingsBody.get()));
|
||||
server.createContext("/dom--repo/com/example/a/1.0/missing.jar", exchange -> respond(exchange, 404, ""));
|
||||
|
||||
Optional<byte[]> result = client.fetchPackageVersionAsset("dom--repo", "dom", "repo", "com.example", "a",
|
||||
"1.0", "missing.jar");
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding: building the request URI from only the base URL's scheme and
|
||||
* authority, dropping any path it has, would break a pre-configured
|
||||
* {@code FLOCI_SERVICES_CODEARTIFACT_MAVEN_URL} that points at Reposilite behind its own path
|
||||
* prefix. Setup still used the full configured URL in that case, but every subsequent GET/PUT
|
||||
* would go to the server root instead and fail.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetPreservesABaseUrlPathPrefix() {
|
||||
when(manager.ensureReady()).thenReturn("http://127.0.0.1:" + server.getAddress().getPort() + "/reposilite-prefix");
|
||||
settingsBody.set("{\"repositories\":[{\"id\":\"dom--repo\",\"visibility\":\"PUBLIC\",\"redeployment\":false}]}");
|
||||
server.createContext("/reposilite-prefix/api/settings/domain/maven",
|
||||
exchange -> respond(exchange, 200, settingsBody.get()));
|
||||
server.createContext("/reposilite-prefix/dom--repo/com/example/a/1.0/a-1.0.jar",
|
||||
exchange -> respond(exchange, 200, "jar-bytes"));
|
||||
|
||||
Optional<byte[]> result = client.fetchPackageVersionAsset("dom--repo", "dom", "repo", "com.example", "a",
|
||||
"1.0", "a-1.0.jar");
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertArrayEquals("jar-bytes".getBytes(StandardCharsets.UTF_8), result.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding on top of the previous one: decoding the configured prefix with
|
||||
* {@code getPath()} and handing it to the URI constructor alongside the new path would
|
||||
* re-encode the whole thing together, turning a deliberately-escaped {@code %2F} (one opaque
|
||||
* segment containing a literal slash) back into a real {@code /}. Something in front of the
|
||||
* sidecar that treats those two differently would then see a different path than the one that
|
||||
* was actually configured. Checks the raw path the backend receives on the wire, since by the
|
||||
* time {@code com.sun.net.httpserver.HttpServer} hands back a matched context, its own
|
||||
* {@code getPath()} would already show the decoded form either way.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetPreservesAPercentEncodedCharacterInTheBaseUrlPrefix() {
|
||||
when(manager.ensureReady())
|
||||
.thenReturn("http://127.0.0.1:" + server.getAddress().getPort() + "/reposilite%2Fv1");
|
||||
settingsBody.set("{\"repositories\":[{\"id\":\"dom--repo\",\"visibility\":\"PUBLIC\",\"redeployment\":false}]}");
|
||||
server.createContext("/reposilite/v1/api/settings/domain/maven",
|
||||
exchange -> respond(exchange, 200, settingsBody.get()));
|
||||
AtomicReference<String> observedRawPath = new AtomicReference<>();
|
||||
server.createContext("/reposilite/v1/dom--repo/com/example/a/1.0/a-1.0.jar", exchange -> {
|
||||
observedRawPath.set(exchange.getRequestURI().getRawPath());
|
||||
respond(exchange, 200, "jar-bytes");
|
||||
});
|
||||
|
||||
Optional<byte[]> result = client.fetchPackageVersionAsset("dom--repo", "dom", "repo", "com.example", "a",
|
||||
"1.0", "a-1.0.jar");
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertThat(observedRawPath.get(), equalTo("/reposilite%2Fv1/dom--repo/com/example/a/1.0/a-1.0.jar"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Same class of bug as the path-prefix case above, but for the authority component: a
|
||||
* percent-encoded character within userinfo (e.g. {@code user%2Ftenant@host}) must survive
|
||||
* untouched. {@code getAuthority()} decodes it before the URI is rebuilt, which would send
|
||||
* the request to a different authority than the one actually configured. Unlike the path
|
||||
* case, this isn't observable over the wire through a live HTTP call (userinfo never reaches
|
||||
* the server), so this calls the private helper directly via reflection.
|
||||
*/
|
||||
@Test
|
||||
void requestUriPreservesAPercentEncodedCharacterInTheBaseUrlAuthority() throws Exception {
|
||||
Method requestUri = ReposiliteSidecarClient.class.getDeclaredMethod("requestUri", String.class, String.class);
|
||||
requestUri.setAccessible(true);
|
||||
|
||||
URI uri = (URI) requestUri.invoke(null, "http://user%2Ftenant@example.com", "/dom--repo/a-1.0.jar");
|
||||
|
||||
assertThat(uri.getRawAuthority(), equalTo("user%2Ftenant@example.com"));
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding: {@code fetchPackageVersionAsset} used to build its GAV path
|
||||
* with a plain {@code +} concatenation of four independently caller-supplied coordinates. A
|
||||
* {@code /} inside {@code assetName} would then be indistinguishable from one of the real
|
||||
* separators between groupId/artifactId/version/filename, letting it splice in extra path
|
||||
* segments. Fixed by percent-encoding each coordinate on its own before joining them, so a
|
||||
* {@code /} inside one of them survives only as a literal {@code %2F} within one segment.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetTreatsASlashInTheAssetNameAsLiteralNotAStructuralSeparator() {
|
||||
settingsBody.set("{\"repositories\":[{\"id\":\"dom--repo\",\"visibility\":\"PUBLIC\",\"redeployment\":false}]}");
|
||||
server.createContext("/api/settings/domain/maven", exchange -> respond(exchange, 200, settingsBody.get()));
|
||||
AtomicReference<String> observedRawPath = new AtomicReference<>();
|
||||
server.createContext("/", exchange -> {
|
||||
if (exchange.getRequestURI().getRawPath().startsWith("/dom--repo/")) {
|
||||
observedRawPath.set(exchange.getRequestURI().getRawPath());
|
||||
}
|
||||
respond(exchange, 404, "");
|
||||
});
|
||||
|
||||
Optional<byte[]> result = client.fetchPackageVersionAsset("dom--repo", "dom", "repo", "com.example", "a",
|
||||
"1.0", "../other.jar");
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
assertThat(observedRawPath.get(), equalTo("/dom--repo/com/example/a/1.0/..%2Fother.jar"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Same finding, the other half of it: a coordinate that is exactly {@code ..} (no slash at
|
||||
* all, so the fix above wouldn't catch it on its own) would sit as a real dot-segment between
|
||||
* two of this method's own {@code /} separators. Fixed by also escaping the dots themselves
|
||||
* whenever a coordinate's entire value is {@code .} or {@code ..}.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetTreatsADotDotVersionAsLiteralNotADotSegment() {
|
||||
settingsBody.set("{\"repositories\":[{\"id\":\"dom--repo\",\"visibility\":\"PUBLIC\",\"redeployment\":false}]}");
|
||||
server.createContext("/api/settings/domain/maven", exchange -> respond(exchange, 200, settingsBody.get()));
|
||||
AtomicReference<String> observedRawPath = new AtomicReference<>();
|
||||
server.createContext("/", exchange -> {
|
||||
if (exchange.getRequestURI().getRawPath().startsWith("/dom--repo/")) {
|
||||
observedRawPath.set(exchange.getRequestURI().getRawPath());
|
||||
}
|
||||
respond(exchange, 404, "");
|
||||
});
|
||||
|
||||
Optional<byte[]> result = client.fetchPackageVersionAsset("dom--repo", "dom", "repo", "com.example", "a",
|
||||
"..", "a-1.0.jar");
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
assertThat(observedRawPath.get(), equalTo("/dom--repo/com/example/a/%2E%2E/a-1.0.jar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void artifactExistsReflectsAHeadResponse() {
|
||||
server.createContext("/dom--repo/present.jar", exchange -> respond(exchange, 200, ""));
|
||||
|
||||
+192
-6
@@ -1,16 +1,27 @@
|
||||
package io.github.hectorvent.floci.services.codeartifact;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.ContainerTeardown;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerLifecycleManager;
|
||||
import io.github.hectorvent.floci.core.common.docker.PerKeyContainerPool;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
@@ -33,16 +44,191 @@ class VerdaccioSidecarManagerTest {
|
||||
private final ContainerLifecycleManager lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
private final EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
|
||||
private HttpServer backend;
|
||||
private String backendUrl;
|
||||
|
||||
@BeforeEach
|
||||
void setUpBackend() throws Exception {
|
||||
backend = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
|
||||
backend.createContext("/-/ping", exchange -> {
|
||||
exchange.sendResponseHeaders(200, -1);
|
||||
exchange.close();
|
||||
});
|
||||
backend.start();
|
||||
backendUrl = "http://127.0.0.1:" + backend.getAddress().getPort();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDownBackend() {
|
||||
backend.stop(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void implementsContainerTeardownSoStateResetAndNukeCanFindIt() {
|
||||
assertInstanceOf(ContainerTeardown.class, manager());
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchPackageVersionAssetGetsTheUnscopedTarballPath() 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");
|
||||
backend.createContext("/demo-pkg/-/demo-pkg-1.0.0.tgz", exchange -> {
|
||||
byte[] body = "tarball bytes".getBytes(StandardCharsets.UTF_8);
|
||||
exchange.sendResponseHeaders(200, body.length);
|
||||
exchange.getResponseBody().write(body);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("npm-repo-1", "dom", "repo", null, "demo-pkg",
|
||||
"1.0.0", "demo-pkg-1.0.0.tgz");
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals("tarball bytes", new String(result.get(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirmed against a live Verdaccio container: a scoped package's tarball path keeps the
|
||||
* {@code @scope/} segment in the URL even though the filename itself never includes it
|
||||
* (unlike the local tarball the npm CLI builds when packing, which does).
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetGetsTheScopedTarballPathWithTheFilenameUnprefixed() throws Exception {
|
||||
VerdaccioSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "npm-repo-1", "tracked-verdaccio-1", backendUrl);
|
||||
respondWithMetadata("/@myscope/demo-pkg", "2.0.0", "/@myscope/demo-pkg/-/demo-pkg-2.0.0.tgz");
|
||||
backend.createContext("/@myscope/demo-pkg/-/demo-pkg-2.0.0.tgz", exchange -> {
|
||||
byte[] body = "scoped tarball bytes".getBytes(StandardCharsets.UTF_8);
|
||||
exchange.sendResponseHeaders(200, body.length);
|
||||
exchange.getResponseBody().write(body);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("npm-repo-1", "dom", "repo", "myscope",
|
||||
"demo-pkg", "2.0.0", "demo-pkg-2.0.0.tgz");
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
assertEquals("scoped tarball bytes", new String(result.get(), StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchPackageVersionAssetReturnsEmptyWhenThePackageWasNeverPublished() throws Exception {
|
||||
VerdaccioSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "npm-repo-1", "tracked-verdaccio-1", backendUrl);
|
||||
backend.createContext("/demo-pkg", exchange -> {
|
||||
exchange.sendResponseHeaders(404, -1);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("npm-repo-1", "dom", "repo", null, "demo-pkg",
|
||||
"1.0.0", "missing.tgz");
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding: without checking the package's own metadata first, a caller
|
||||
* naming a real tarball filename under a version that was never actually published to it
|
||||
* would get that file's bytes back anyway, since the tarball route is keyed by filename alone.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetReturnsEmptyWhenTheVersionWasNeverPublishedEvenIfTheFilenameExists() 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");
|
||||
backend.createContext("/demo-pkg/-/demo-pkg-9.9.9.tgz", exchange -> {
|
||||
byte[] body = "should never be served".getBytes(StandardCharsets.UTF_8);
|
||||
exchange.sendResponseHeaders(200, body.length);
|
||||
exchange.getResponseBody().write(body);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("npm-repo-1", "dom", "repo", null, "demo-pkg",
|
||||
"9.9.9", "demo-pkg-9.9.9.tgz");
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchPackageVersionAssetThrowsRatherThanReportingNotFoundOnASidecarServerError() throws Exception {
|
||||
VerdaccioSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "npm-repo-1", "tracked-verdaccio-1", backendUrl);
|
||||
backend.createContext("/demo-pkg", exchange -> {
|
||||
exchange.sendResponseHeaders(500, -1);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> manager.fetchPackageVersionAsset("npm-repo-1", "dom", "repo",
|
||||
null, "demo-pkg", "1.0.0", "demo-pkg-1.0.0.tgz"));
|
||||
}
|
||||
|
||||
/**
|
||||
* The fix for a real finding: {@code packagePath} used to splice the npm scope straight into
|
||||
* the URL. A {@code /} inside {@code namespace} (the scope) would then be indistinguishable
|
||||
* from one of the real separators between the scope, the package name, and {@code -}, letting
|
||||
* it splice in extra path segments. Fixed by percent-encoding each coordinate on its own
|
||||
* before joining them, so a {@code /} inside one of them survives only as a literal
|
||||
* {@code %2F} within one segment.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetTreatsASlashInTheNamespaceAsLiteralNotAStructuralSeparator() throws Exception {
|
||||
VerdaccioSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "npm-repo-1", "tracked-verdaccio-1", backendUrl);
|
||||
AtomicReference<String> observedRawPath = new AtomicReference<>();
|
||||
backend.createContext("/", exchange -> {
|
||||
observedRawPath.set(exchange.getRequestURI().getRawPath());
|
||||
exchange.sendResponseHeaders(404, -1);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("npm-repo-1", "dom", "repo", "../../escape",
|
||||
"demo-pkg", "1.0.0", "demo-pkg-1.0.0.tgz");
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
assertEquals("/@..%2F..%2Fescape/demo-pkg", observedRawPath.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Same finding, the other half of it: a coordinate that is exactly {@code ..} (no slash at
|
||||
* all, so the fix above wouldn't catch it on its own) would sit as a real dot-segment between
|
||||
* two of this method's own {@code /} separators. Fixed by also escaping the dots themselves
|
||||
* whenever a coordinate's entire value is {@code .} or {@code ..}.
|
||||
*/
|
||||
@Test
|
||||
void fetchPackageVersionAssetTreatsADotDotPackageNameAsLiteralNotADotSegment() throws Exception {
|
||||
VerdaccioSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "npm-repo-1", "tracked-verdaccio-1", backendUrl);
|
||||
AtomicReference<String> observedRawPath = new AtomicReference<>();
|
||||
backend.createContext("/", exchange -> {
|
||||
observedRawPath.set(exchange.getRequestURI().getRawPath());
|
||||
exchange.sendResponseHeaders(404, -1);
|
||||
exchange.close();
|
||||
});
|
||||
|
||||
Optional<byte[]> result = manager.fetchPackageVersionAsset("npm-repo-1", "dom", "repo", null, "..",
|
||||
"1.0.0", "demo-pkg-1.0.0.tgz");
|
||||
|
||||
assertTrue(result.isEmpty());
|
||||
assertEquals("/%2E%2E", observedRawPath.get());
|
||||
}
|
||||
|
||||
private void respondWithMetadata(String packagePath, String version, String tarballPath) {
|
||||
String body = "{\"versions\":{\"" + version + "\":{\"dist\":{\"tarball\":\"http://ignored" + tarballPath
|
||||
+ "\"}}}}";
|
||||
backend.createContext(packagePath, exchange -> {
|
||||
byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
|
||||
exchange.getResponseHeaders().set("Content-Type", "application/json");
|
||||
exchange.sendResponseHeaders(200, bytes.length);
|
||||
exchange.getResponseBody().write(bytes);
|
||||
exchange.close();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void stopManagedContainersStopsEveryContainerThePoolIsTracking() throws Exception {
|
||||
VerdaccioSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "npm-repo-1", "tracked-verdaccio-1");
|
||||
seedPooledContainer(manager, "npm-repo-2", "tracked-verdaccio-2");
|
||||
seedPooledContainer(manager, "npm-repo-1", "tracked-verdaccio-1", "http://127.0.0.1:1");
|
||||
seedPooledContainer(manager, "npm-repo-2", "tracked-verdaccio-2", "http://127.0.0.1:1");
|
||||
|
||||
manager.stopManagedContainers();
|
||||
|
||||
@@ -60,12 +246,12 @@ class VerdaccioSidecarManagerTest {
|
||||
}
|
||||
|
||||
private VerdaccioSidecarManager manager() {
|
||||
return new VerdaccioSidecarManager(containerBuilder, lifecycleManager, config);
|
||||
return new VerdaccioSidecarManager(containerBuilder, lifecycleManager, config, new ObjectMapper());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void seedPooledContainer(VerdaccioSidecarManager manager, String key, String containerId)
|
||||
throws Exception {
|
||||
private static void seedPooledContainer(VerdaccioSidecarManager manager, String key, String containerId,
|
||||
String url) throws Exception {
|
||||
Field poolField = VerdaccioSidecarManager.class.getDeclaredField("pool");
|
||||
poolField.setAccessible(true);
|
||||
PerKeyContainerPool pool = (PerKeyContainerPool) poolField.get(manager);
|
||||
@@ -74,6 +260,6 @@ class VerdaccioSidecarManagerTest {
|
||||
containersField.setAccessible(true);
|
||||
ConcurrentHashMap<String, PerKeyContainerPool.StartedContainer> containers =
|
||||
(ConcurrentHashMap<String, PerKeyContainerPool.StartedContainer>) containersField.get(pool);
|
||||
containers.put(key, new PerKeyContainerPool.StartedContainer(containerId, "http://127.0.0.1:1"));
|
||||
containers.put(key, new PerKeyContainerPool.StartedContainer(containerId, url));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user