Light, fluffy, and always free - The AWS Local Emulator alternative
test(elbv2): use loopback transport for Lambda target fixtures (#6476)
Andre Kurait35b76d2d940e
diff --git a/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2LambdaTargetDataPlaneIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2LambdaTargetDataPlaneIntegrationTest.javaindex b4c1f64f68..bf2505bf67 100644--- a/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2LambdaTargetDataPlaneIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/elbv2/ElbV2LambdaTargetDataPlaneIntegrationTest.java@@ -5,6 +5,7 @@ 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.restassured.specification.RequestSpecification;import org.junit.jupiter.api.MethodOrderer;import org.junit.jupiter.api.Order;import org.junit.jupiter.api.Test;@@ -49,6 +50,13 @@ class ElbV2LambdaTargetDataPlaneIntegrationTest {private static String listenerArn;private static String functionArn;+ private static RequestSpecification listenerRequest(String host) {+ return given()+ .baseUri("http://127.0.0.1")+ .header("Host", host)+ .port(LISTENER_PORT);+ }+private static String makeZipBase64() throws Exception {// Matches the reproduction script in the bug report (Python 3.11 / index.handler).ByteArrayOutputStream baos = new ByteArrayOutputStream();@@ -153,8 +161,10 @@ class ElbV2LambdaTargetDataPlaneIntegrationTest {.formParam("LoadBalancerArn", lbArn).formParam("Protocol", "HTTP").formParam("Port", String.valueOf(LISTENER_PORT))- .formParam("DefaultActions.member.1.Type", "forward")- .formParam("DefaultActions.member.1.TargetGroupArn", tgArn)+ .formParam("DefaultActions.member.1.Type", "fixed-response")+ .formParam("DefaultActions.member.1.FixedResponseConfig.StatusCode", "421")+ .formParam("DefaultActions.member.1.FixedResponseConfig.ContentType", "text/plain")+ .formParam("DefaultActions.member.1.FixedResponseConfig.MessageBody", "unexpected host").header("Authorization", AUTH).when().post("/")@@ -162,6 +172,20 @@ class ElbV2LambdaTargetDataPlaneIntegrationTest {.statusCode(200).extract().path("CreateListenerResponse.CreateListenerResult.Listeners.member.ListenerArn");++ given()+ .formParam("Action", "CreateRule")+ .formParam("ListenerArn", listenerArn)+ .formParam("Priority", "1")+ .formParam("Conditions.member.1.Field", "host-header")+ .formParam("Conditions.member.1.HostHeaderConfig.Values.member.1", lbDnsName)+ .formParam("Actions.member.1.Type", "forward")+ .formParam("Actions.member.1.TargetGroupArn", tgArn)+ .header("Authorization", AUTH)+ .when()+ .post("/")+ .then()+ .statusCode(200);}/**@@ -169,14 +193,12 @@ class ElbV2LambdaTargetDataPlaneIntegrationTest {* must be forwarded to the Lambda and the Lambda's response must be returned* to the HTTP client. If `invokeLambdaTarget` blocks the Vert.x event loop* (the pre-fix behaviour), the Lambda Runtime API hosted on the same event- * loop is starved and the function times out — this assertion catches that.+ * loop is starved and the function times out: this assertion catches that.*/@Test@Order(5)void httpRequestThroughListenerInvokesLambda() {- given()- .baseUri("http://" + lbDnsName)- .port(LISTENER_PORT)+ listenerRequest(lbDnsName).contentType("text/plain").body("hello").when()@@ -191,9 +213,7 @@ class ElbV2LambdaTargetDataPlaneIntegrationTest {void requestBodyAtOneMiBIsAccepted() {byte[] exactLimit = new byte[1024 * 1024];- given()- .baseUri("http://" + lbDnsName)- .port(LISTENER_PORT)+ listenerRequest(lbDnsName).contentType("application/octet-stream").body(exactLimit).when()@@ -207,9 +227,7 @@ class ElbV2LambdaTargetDataPlaneIntegrationTest {@Order(7)void oversizedRequestBodyIsRejectedBeforeLambdaInvocation() {byte[] oversized = new byte[1024 * 1024 + 1];- int invocationCountBefore = Integer.parseInt(given()- .baseUri("http://" + lbDnsName)- .port(LISTENER_PORT)+ int invocationCountBefore = Integer.parseInt(listenerRequest(lbDnsName).when().get("/invocation-count").then()@@ -217,9 +235,7 @@ class ElbV2LambdaTargetDataPlaneIntegrationTest {.extract().asString());- given()- .baseUri("http://" + lbDnsName)- .port(LISTENER_PORT)+ listenerRequest(lbDnsName).contentType("application/octet-stream").body(oversized).when()@@ -227,9 +243,7 @@ class ElbV2LambdaTargetDataPlaneIntegrationTest {.then().statusCode(413);- int invocationCountAfter = Integer.parseInt(given()- .baseUri("http://" + lbDnsName)- .port(LISTENER_PORT)+ int invocationCountAfter = Integer.parseInt(listenerRequest(lbDnsName).when().get("/invocation-count").then()@@ -242,9 +256,7 @@ class ElbV2LambdaTargetDataPlaneIntegrationTest {@Test@Order(8)void lambdaResponseBodyAtOneMiBIsAccepted() {- given()- .baseUri("http://" + lbDnsName)- .port(LISTENER_PORT)+ listenerRequest(lbDnsName).when().get("/response-at-limit").then()@@ -255,9 +267,7 @@ class ElbV2LambdaTargetDataPlaneIntegrationTest {@Test@Order(9)void oversizedLambdaResponseIsRejected() {- Response response = given()- .baseUri("http://" + lbDnsName)- .port(LISTENER_PORT)+ Response response = listenerRequest(lbDnsName).when().get("/response-oversized");@@ -265,6 +275,17 @@ class ElbV2LambdaTargetDataPlaneIntegrationTest {assertNotEquals("1048577", response.getHeader("Content-Length"));}+ @Test+ @Order(10)+ void listenerRejectsUnexpectedHost() {+ listenerRequest("unmatched.example.test")+ .when()+ .get("/check")+ .then()+ .statusCode(421)+ .body(equalTo("unexpected host"));+ }+/*** Cleanup. Lives as the highest-ordered @Test rather than {@code @AfterAll} because* Quarkus tears the test endpoint down before JUnit's @AfterAll runs, so HTTP-based