mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(cloudformation): identify unsupported SAM Cognito authorizers (#3535)
Co-authored-by: xujiantop-crypto <265865031+xujiantop-crypto@users.noreply.github.com>
This commit is contained in:
1 parent
36c8396f25
commit
809ce40f1e
2 files changed
+36
No files matched your search
+7
@@ -566,6 +566,13 @@ class SamTransformProcessor {
|
||||
Map.Entry<String, JsonNode> entry = it.next();
|
||||
String name = entry.getKey();
|
||||
JsonNode config = entry.getValue();
|
||||
if (config.has("UserPoolArn")
|
||||
|| "COGNITO_USER_POOLS".equals(config.path("AuthType").asText())) {
|
||||
throw new AwsException("ValidationError",
|
||||
"SAM implicit REST API authorizer " + name
|
||||
+ " configures a Cognito user pool authorizer, which Floci does not "
|
||||
+ "support for SAM implicit REST APIs yet.", 400);
|
||||
}
|
||||
String payloadType = config.path("FunctionPayloadType").asText("TOKEN");
|
||||
if (!"REQUEST".equals(payloadType)) {
|
||||
throw new AwsException("ValidationError",
|
||||
|
||||
+29
@@ -937,6 +937,35 @@ class SamTransformProcessorTest {
|
||||
assertTrue(authPermission, "expected SAM to grant API Gateway permission to invoke the authorizer");
|
||||
}
|
||||
|
||||
@Test
|
||||
void expandSamTemplate_implicitApiCognitoAuthorizerReportsUnsupportedCapability() throws Exception {
|
||||
JsonNode template = objectMapper.readTree("""
|
||||
{
|
||||
"Transform": "AWS::Serverless-2016-10-31",
|
||||
"Globals": {"Api": {"Auth": {
|
||||
"DefaultAuthorizer": "MyCognitoAuth",
|
||||
"Authorizers": {"MyCognitoAuth": {
|
||||
"AuthType": "COGNITO_USER_POOLS",
|
||||
"UserPoolArn": "arn:aws:cognito-idp:us-east-1:000000000000:userpool/us-east-1_example"
|
||||
}}
|
||||
}}},
|
||||
"Resources": {
|
||||
"Fn": {"Type": "AWS::Serverless::Function", "Properties": {
|
||||
"Handler": "index.handler", "Runtime": "nodejs20.x", "InlineCode": "code",
|
||||
"Events": {"Get": {"Type": "Api", "Properties": {"Path": "/x", "Method": "GET"}}}
|
||||
}}
|
||||
}
|
||||
}
|
||||
""");
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () -> processor.expandSamTemplate(template));
|
||||
|
||||
assertEquals("ValidationError", error.getErrorCode());
|
||||
assertEquals("SAM implicit REST API authorizer MyCognitoAuth configures a Cognito user pool "
|
||||
+ "authorizer, which Floci does not support for SAM implicit REST APIs yet.", error.getMessage());
|
||||
assertFalse(error.getMessage().contains("FunctionPayloadType"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void expandSamTemplate_implicitApiEventCanOptOutOfGlobalAuthorizer() throws Exception {
|
||||
JsonNode template = objectMapper.readTree("""
|
||||
|
||||
Reference in new issue
Block a user