aws-cloudformation / cfn-lint

CloudFormation Linter
MIT No Attribution
2.46k stars 597 forks source link

E3031 'string' does not match '^.*$' #3771

Closed dr3 closed 1 month ago

dr3 commented 1 month ago

CloudFormation Lint Version

1.17.2

What operating system are you using?

Mac

Describe the bug

(Introduced In 1.17.0, works in 1.16.1)

String does not match '^.*$' (which is regex for "anything")

E3031 '#if($context.identity.claims.account_type == "ADMIN") \n  #return\n#else\n  $util.error("MUST BE ADMIN")\n#end\n' does not match '^.*$'
testing2.yaml:29:7

Expected behavior

It passes

Reproduction template

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Example

Resources:
  GraphQLApi:
    Type: AWS::AppSync::GraphQLApi
    Properties:
      Name: !Ref APIName
      AuthenticationType: OPENID_CONNECT
      OpenIDConnectConfig:
        Issuer: https://securetoken.google.com/foobar

  NoneDataSource:
    Type: AWS::AppSync::DataSource
    Properties:
      ApiId: !GetAtt GraphQLApi.ApiId
      Name: "NoneSource"
      Type: NONE

  AdminOnlyAuthFunction:
    Type: AWS::AppSync::FunctionConfiguration
    Properties:
      ApiId: !GetAtt GraphQLApi.ApiId
      Name: auth_admin_logic
      Description: Must be admin user
      DataSourceName: !GetAtt NoneDataSource.Name
      FunctionVersion: "2018-05-29"
      RequestMappingTemplate: >
        #if($context.identity.claims.account_type == "ADMIN") 
          #return
        #else
          $util.error("MUST BE ADMIN")
        #end
      ResponseMappingTemplate: >
        #return

Parameters:
  APIName:
    Type: String
kddejong commented 1 month ago

Looks like the re.search doesn't do multiline pattern matching so the newlines are throwing it off. Instead of spending resources validating that its a string it just makes sense to remove it. This field is related to some boto automation in which we are taking patterns from botocore. We had an exception for "." so added one for "^.$" as well.