mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(codeartifact): use HTTP/1.1 for the PyPI sidecar (#8946)
This commit is contained in:
1 parent
634073fb83
commit
5f38401fdd
6 files changed
+61
-30
No files matched your search
@@ -41,6 +41,7 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -131,6 +132,24 @@ class CodeArtifactPypiControllerTest {
|
||||
backend.stop(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultTransportDoesNotRequestAnH2cUpgrade() {
|
||||
AtomicReference<String> upgrade = new AtomicReference<>("request not received");
|
||||
backend.createContext("/simple/demo/", exchange -> {
|
||||
upgrade.set(exchange.getRequestHeaders().getFirst("Upgrade"));
|
||||
exchange.sendResponseHeaders(404, -1);
|
||||
exchange.close();
|
||||
});
|
||||
CodeArtifactPypiController defaultController = new CodeArtifactPypiController(
|
||||
service, pypiserver, externalConnectionImporter, upstreamRepositoryImporter);
|
||||
|
||||
try (Response response = defaultController.packageIndex(
|
||||
headers("Bearer token"), DOMAIN, REPOSITORY, "demo")) {
|
||||
assertEquals(404, response.getStatus());
|
||||
}
|
||||
assertNull(upgrade.get(), "the pinned pypiserver accepts HTTP/1.1 without an h2c upgrade");
|
||||
}
|
||||
|
||||
@Test
|
||||
void requireBaseUrlRejectsAMissingOrUnresolvableToken() {
|
||||
when(service.resolveAuthorizationToken(anyString(), eq(DOMAIN))).thenReturn(Optional.empty());
|
||||
|
||||
+19
-27
@@ -5,6 +5,7 @@ import io.floci.aws.core.common.Digests;
|
||||
import io.floci.aws.core.common.docker.ContainerStorageHelper;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.floci.aws.testing.SidecarContainersProfile;
|
||||
import io.floci.aws.testing.StartGate;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import io.restassured.path.json.JsonPath;
|
||||
@@ -19,21 +20,20 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
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.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@@ -258,32 +258,24 @@ class CodeArtifactPypiDockerIntegrationTest {
|
||||
.then().statusCode(200);
|
||||
|
||||
int attempts = 8;
|
||||
ExecutorService pool = Executors.newFixedThreadPool(attempts);
|
||||
CountDownLatch ready = new CountDownLatch(attempts);
|
||||
CountDownLatch go = new CountDownLatch(1);
|
||||
AtomicInteger notFoundResponses = new AtomicInteger();
|
||||
try {
|
||||
for (int i = 0; i < attempts; i++) {
|
||||
pool.submit(() -> {
|
||||
ready.countDown();
|
||||
try {
|
||||
go.await();
|
||||
given().header("Authorization", "Bearer " + bearerToken)
|
||||
.get("/codeartifact/pypi/" + DOMAIN + "/concurrent-repo/simple/does-not-exist/")
|
||||
.then().statusCode(404);
|
||||
notFoundResponses.incrementAndGet();
|
||||
} catch (InterruptedException ignored) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
});
|
||||
StartGate.Results<Integer> results = StartGate.runConcurrently(attempts, index -> {
|
||||
ready.countDown();
|
||||
try {
|
||||
assertTrue(ready.await(5, TimeUnit.SECONDS), "all request workers must be ready");
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IllegalStateException("request worker interrupted before admission", e);
|
||||
}
|
||||
ready.await(5, TimeUnit.SECONDS);
|
||||
go.countDown();
|
||||
} finally {
|
||||
pool.shutdown();
|
||||
assertTrue(pool.awaitTermination(30, TimeUnit.SECONDS));
|
||||
}
|
||||
assertEquals(attempts, notFoundResponses.get());
|
||||
given().header("Authorization", "Bearer " + bearerToken)
|
||||
.get("/codeartifact/pypi/" + DOMAIN + "/concurrent-repo/simple/does-not-exist/")
|
||||
.then().statusCode(404);
|
||||
return 404;
|
||||
});
|
||||
assertAll("concurrent PyPI requests", results.errors().stream().map(error -> () -> {
|
||||
throw error;
|
||||
}));
|
||||
assertEquals(Collections.nCopies(attempts, 404), results.values());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -29,6 +29,7 @@ import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -63,6 +64,23 @@ class PypiserverSidecarClientTest {
|
||||
backend.stop(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultTransportDoesNotRequestAnH2cUpgrade() throws Exception {
|
||||
PypiserverSidecarManager manager = manager();
|
||||
seedPooledContainer(manager, "pypi-repo-1", "tracked-pypiserver-1", backendUrl);
|
||||
AtomicReference<String> upgrade = new AtomicReference<>("request not received");
|
||||
backend.createContext("/simple/demo-pkg/", exchange -> {
|
||||
upgrade.set(exchange.getRequestHeaders().getFirst("Upgrade"));
|
||||
exchange.sendResponseHeaders(404, -1);
|
||||
exchange.close();
|
||||
});
|
||||
PypiserverSidecarClient defaultClient = new PypiserverSidecarClient(manager, new ObjectMapper());
|
||||
|
||||
assertTrue(defaultClient.fetchPackageVersionAsset("pypi-repo-1", "dom", "repo", null,
|
||||
"demo-pkg", "1.0.0", "demo_pkg-1.0.0.tar.gz").isEmpty());
|
||||
assertNull(upgrade.get(), "the pinned pypiserver accepts HTTP/1.1 without an h2c upgrade");
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchPackageVersionAssetGetsTheFlatPackagesPath() throws Exception {
|
||||
PypiserverSidecarManager manager = manager();
|
||||
|
||||
Reference in new issue
Block a user