Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(apigatewayv2): include authorizerId on Route management API responses (#887)

Yoshiyuki Ohtabecbbea5f914
diff --git a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.java b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.java
index e3fc15fe8f..0ec610fe5d 100644
--- a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayController.java
@@ -1567,6 +1567,7 @@ public class ApiGatewayController {
node.put("routeId", r.getRouteId());
node.put("routeKey", r.getRouteKey());
node.put("authorizationType", r.getAuthorizationType());
+ if (r.getAuthorizerId() != null) node.put("authorizerId", r.getAuthorizerId());
if (r.getTarget() != null) node.put("target", r.getTarget());
if (r.getRouteResponseSelectionExpression() != null) node.put("routeResponseSelectionExpression", r.getRouteResponseSelectionExpression());
return node;
diff --git a/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/RouteAuthorizerIdResponseTest.java b/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/RouteAuthorizerIdResponseTest.java
new file mode 100644
index 0000000000..76cce8e2cc
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/apigatewayv2/RouteAuthorizerIdResponseTest.java
@@ -0,0 +1,122 @@
+package io.github.hectorvent.floci.services.apigatewayv2;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.http.ContentType;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItem;
+
+/**
+ * Regression coverage for the HTTP API v2 management API returning {@code authorizerId}
+ * on Route resources. The value is persisted via {@code Route.setAuthorizerId} during
+ * create/update and used at runtime (e.g. WebSocketHandler, ApiGatewayExecuteController),
+ * so omitting it from the response causes IaC tools like Terraform to perceive drift on
+ * every plan.
+ */
+@QuarkusTest
+class RouteAuthorizerIdResponseTest {
+
+ @Test
+ void authorizerIdReturnedFromCreateGetAndList() {
+ String apiId = given()
+ .contentType(ContentType.JSON)
+ .body("""
+ {"name":"authz-route-create","protocolType":"HTTP"}
+ """)
+ .when().post("/v2/apis")
+ .then().statusCode(201)
+ .extract().path("apiId");
+
+ String authorizerId = given()
+ .contentType(ContentType.JSON)
+ .body("""
+ {
+ "authorizerType":"JWT",
+ "name":"jwt-authz",
+ "identitySource":["$request.header.Authorization"],
+ "jwtConfiguration":{"issuer":"https://example.com","audience":["api"]}
+ }
+ """)
+ .when().post("/v2/apis/" + apiId + "/authorizers")
+ .then().statusCode(201)
+ .extract().path("authorizerId");
+
+ String routeId = given()
+ .contentType(ContentType.JSON)
+ .body("""
+ {
+ "routeKey":"GET /secured",
+ "authorizationType":"JWT",
+ "authorizerId":"%s"
+ }
+ """.formatted(authorizerId))
+ .when().post("/v2/apis/" + apiId + "/routes")
+ .then().statusCode(201)
+ .body("authorizationType", equalTo("JWT"))
+ .body("authorizerId", equalTo(authorizerId))
+ .extract().path("routeId");
+
+ given()
+ .when().get("/v2/apis/" + apiId + "/routes/" + routeId)
+ .then().statusCode(200)
+ .body("authorizationType", equalTo("JWT"))
+ .body("authorizerId", equalTo(authorizerId));
+
+ given()
+ .when().get("/v2/apis/" + apiId + "/routes")
+ .then().statusCode(200)
+ .body("items.authorizerId", hasItem(authorizerId));
+ }
+
+ @Test
+ void authorizerIdReturnedAfterUpdate() {
+ String apiId = given()
+ .contentType(ContentType.JSON)
+ .body("""
+ {"name":"authz-route-update","protocolType":"HTTP"}
+ """)
+ .when().post("/v2/apis")
+ .then().statusCode(201)
+ .extract().path("apiId");
+
+ String authorizerId = given()
+ .contentType(ContentType.JSON)
+ .body("""
+ {
+ "authorizerType":"JWT",
+ "name":"jwt-authz-2",
+ "identitySource":["$request.header.Authorization"],
+ "jwtConfiguration":{"issuer":"https://example.com","audience":["api"]}
+ }
+ """)
+ .when().post("/v2/apis/" + apiId + "/authorizers")
+ .then().statusCode(201)
+ .extract().path("authorizerId");
+
+ String routeId = given()
+ .contentType(ContentType.JSON)
+ .body("""
+ {"routeKey":"GET /open","authorizationType":"NONE"}
+ """)
+ .when().post("/v2/apis/" + apiId + "/routes")
+ .then().statusCode(201)
+ .extract().path("routeId");
+
+ given()
+ .contentType(ContentType.JSON)
+ .body("""
+ {"authorizationType":"JWT","authorizerId":"%s"}
+ """.formatted(authorizerId))
+ .when().patch("/v2/apis/" + apiId + "/routes/" + routeId)
+ .then().statusCode(200)
+ .body("authorizationType", equalTo("JWT"))
+ .body("authorizerId", equalTo(authorizerId));
+
+ given()
+ .when().get("/v2/apis/" + apiId + "/routes/" + routeId)
+ .then().statusCode(200)
+ .body("authorizerId", equalTo(authorizerId));
+ }
+}