Skip to content

armgit / floci

Public Imported from GitHub
0

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

fix(cloudformation): reject a non-numeric AuthorizerResultTtlInSeconds (#4055)

Hector Venturaeb247a50aa4c
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ApiGatewayV2CfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ApiGatewayV2CfnProvisioner.java
index a89e377bcf..e2db4e082f 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ApiGatewayV2CfnProvisioner.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/ApiGatewayV2CfnProvisioner.java
@@ -748,7 +748,12 @@ public class ApiGatewayV2CfnProvisioner implements CfnResourceProvisioner {
String ttl = ctx.resolveOptional(props, "AuthorizerResultTtlInSeconds");
if (ttl != null) {
- req.put("authorizerResultTtlInSeconds", Integer.parseInt(ttl));
+ try {
+ req.put("authorizerResultTtlInSeconds", Integer.parseInt(ttl));
+ } catch (NumberFormatException ignored) {
+ throw new AwsException("ValidationError",
+ "AuthorizerResultTtlInSeconds must be an integer", 400);
+ }
}
String simpleResponses = ctx.resolveOptional(props, "EnableSimpleResponses");
if (simpleResponses != null) {
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayV2CfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayV2CfnProvisionerTest.java
index ea026eb69a..50f1cf339b 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayV2CfnProvisionerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/ApiGatewayV2CfnProvisionerTest.java
@@ -66,6 +66,21 @@ class ApiGatewayV2CfnProvisionerTest {
api.getAttributes().get("ExecuteApiArn"));
}
+ @Test
+ void authorizerWithNonNumericTtlIsRejected() throws Exception {
+ StackResource authorizer = provisioner.provision("MyAuth", "AWS::ApiGatewayV2::Authorizer",
+ mapper.readTree("""
+ {"ApiId": "api-123",
+ "IdentitySource": ["$request.header.Authorization"],
+ "AuthorizerResultTtlInSeconds": "not-a-number"}
+ """),
+ engine(), REGION, "000000000000", "test-stack", null, Map.of());
+
+ assertEquals("CREATE_FAILED", authorizer.getStatus());
+ assertTrue(authorizer.getStatusReason().contains("AuthorizerResultTtlInSeconds must be an integer"),
+ authorizer.getStatusReason());
+ }
+
@Test
void restoresExistingRoutesAndCleansPartialReplacementWhenRouteCreationFails() throws Exception {
Route oldRoute = route("old-route", "GET /before");