mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(elbv2): preserve repeated target response headers (#5628)
This commit is contained in:
1 parent
4ea7e3da23
commit
15f50cb68e
4 files changed
+67
-11
No files matched your search
+39
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.elbv2;
|
||||
import io.github.hectorvent.floci.testing.RealElbV2DataPlaneProfile;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import io.restassured.response.Response;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.buffer.Buffer;
|
||||
import io.vertx.core.http.HttpClientRequest;
|
||||
@@ -20,6 +21,7 @@ import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -41,6 +43,43 @@ class ElbV2PreserveHostHeaderIntegrationTest {
|
||||
@Inject
|
||||
Vertx vertx;
|
||||
|
||||
@Test
|
||||
void preservesRepeatedTargetResponseHeaders() throws Exception {
|
||||
HttpServer backend = vertx.createHttpServer().requestHandler(request -> {
|
||||
request.response().headers()
|
||||
.add("Set-Cookie", "a=1; Path=/")
|
||||
.add("Set-Cookie", "b=2; Path=/")
|
||||
.add("Set-Cookie", "c=3; Path=/")
|
||||
.add("X-Multi", "one")
|
||||
.add("X-Multi", "two")
|
||||
.add("Keep-Alive", "timeout=5");
|
||||
request.response().end("ok");
|
||||
}).listen(0, "127.0.0.1").toCompletionStage().toCompletableFuture().get(2, TimeUnit.SECONDS);
|
||||
String loadBalancerArn = null;
|
||||
String targetGroupArn = null;
|
||||
String listenerArn = null;
|
||||
try {
|
||||
loadBalancerArn = createLoadBalancer();
|
||||
targetGroupArn = createTargetGroup(backend.actualPort());
|
||||
registerTarget(targetGroupArn, backend.actualPort());
|
||||
listenerArn = createListener(loadBalancerArn, targetGroupArn);
|
||||
await().atMost(Duration.ofSeconds(3)).untilAsserted(() -> {
|
||||
Response response = given().baseUri("http://127.0.0.1").port(LISTENER_PORT).get("/headers");
|
||||
assertEquals(200, response.statusCode());
|
||||
assertEquals("ok", response.asString());
|
||||
assertEquals(List.of("a=1; Path=/", "b=2; Path=/", "c=3; Path=/"),
|
||||
response.headers().getValues("Set-Cookie"));
|
||||
assertEquals(List.of("one", "two"), response.headers().getValues("X-Multi"));
|
||||
assertEquals(List.of(), response.headers().getValues("Keep-Alive"));
|
||||
});
|
||||
} finally {
|
||||
deleteListener(listenerArn);
|
||||
deleteTargetGroup(targetGroupArn);
|
||||
deleteLoadBalancer(loadBalancerArn);
|
||||
backend.close().toCompletionStage().toCompletableFuture().get(2, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void preservesHostHeaderWhenLoadBalancerAttributeIsEnabled() throws Exception {
|
||||
HttpServer backend = vertx.createHttpServer()
|
||||
|
||||
+14
-1
@@ -18,6 +18,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -61,7 +62,14 @@ class ElbV2WebSocketIntegrationTest {
|
||||
if (!"websocket".equalsIgnoreCase(request.getHeader("Upgrade"))) {
|
||||
request.response().setStatusCode(400).end("not an upgrade");
|
||||
} else if (!request.path().startsWith("/socket.io/")) {
|
||||
request.response().setStatusCode(404).end();
|
||||
request.response().headers()
|
||||
.add("Set-Cookie", "a=1; Path=/")
|
||||
.add("Set-Cookie", "b=2; Path=/")
|
||||
.add("Set-Cookie", "c=3; Path=/")
|
||||
.add("X-Multi", "one")
|
||||
.add("X-Multi", "two")
|
||||
.add("Keep-Alive", "timeout=5");
|
||||
request.response().setStatusCode(404).end("upgrade refused");
|
||||
} else {
|
||||
String query = request.query();
|
||||
request.toWebSocket().onSuccess(socket -> socket.textMessageHandler(
|
||||
@@ -137,6 +145,11 @@ class ElbV2WebSocketIntegrationTest {
|
||||
|
||||
UpgradeRejectedException rejected = assertInstanceOf(UpgradeRejectedException.class, failure.getCause());
|
||||
assertEquals(404, rejected.getStatus());
|
||||
assertEquals(List.of("a=1; Path=/", "b=2; Path=/", "c=3; Path=/"),
|
||||
rejected.getHeaders().getAll("Set-Cookie"));
|
||||
assertEquals(List.of("one", "two"), rejected.getHeaders().getAll("X-Multi"));
|
||||
assertEquals(List.of(), rejected.getHeaders().getAll("Keep-Alive"));
|
||||
assertEquals("upgrade refused", rejected.getBody().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user