- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.4k
fix(bug): Check if Identity.ReauthorizeEvery equals zero #2105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      5d2896b
              
                Revert "Revert "Issue 1508 remove check requiring identity ... (#1577…
              
              
                jfuss 201e4a5
              
                Update implementation to support intrinsics/ add more tests to valida…
              
              
                jfuss 3aa2014
              
                Fixing hashes for py2
              
              
                jfuss 87a0805
              
                Run make black
              
              
                jfuss 5f29f93
              
                Handle pr feedback
              
              
                jfuss d04a588
              
                Add another unit tests to cover the original issue
              
              
                jfuss File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -14,6 +14,100 @@ def test_create_oauth2_auth(self): | |
|  | ||
| def test_create_authorizer_fails_with_string_authorization_scopes(self): | ||
| with pytest.raises(InvalidResourceException): | ||
| auth = ApiGatewayAuthorizer( | ||
| api_logical_id="logicalId", name="authName", authorization_scopes="invalid_scope" | ||
| ApiGatewayAuthorizer(api_logical_id="logicalId", name="authName", authorization_scopes="invalid_scope") | ||
|  | ||
| def test_create_authorizer_fails_with_missing_identity_values_and_not_cached(self): | ||
| with pytest.raises(InvalidResourceException): | ||
| ApiGatewayAuthorizer( | ||
| api_logical_id="logicalId", | ||
| name="authName", | ||
| identity={"ReauthorizeEvery": 10}, | ||
| function_payload_type="REQUEST", | ||
| ) | ||
|  | ||
| def test_create_authorizer_fails_with_empty_identity(self): | ||
| with pytest.raises(InvalidResourceException): | ||
| ApiGatewayAuthorizer( | ||
| api_logical_id="logicalId", name="authName", identity={}, function_payload_type="REQUEST" | ||
| ) | ||
|  | ||
| def test_create_authorizer_doesnt_fail_with_identity_reauthorization_every_as_zero(self): | ||
| auth = ApiGatewayAuthorizer( | ||
| api_logical_id="logicalId", | ||
| name="authName", | ||
| identity={"ReauthorizeEvery": 0}, | ||
| function_payload_type="REQUEST", | ||
| ) | ||
|  | ||
| self.assertIsNotNone(auth) | ||
|  | ||
| def test_create_authorizer_with_non_integer_identity(self): | ||
| auth = ApiGatewayAuthorizer( | ||
| api_logical_id="logicalId", | ||
| name="authName", | ||
| identity={"ReauthorizeEvery": [], "Headers": ["Accept"]}, | ||
| function_payload_type="REQUEST", | ||
| ) | ||
|  | ||
| self.assertIsNotNone(auth) | ||
|  | ||
| def test_create_authorizer_with_identity_intrinsic_is_valid_with_headers(self): | ||
| auth = ApiGatewayAuthorizer( | ||
| api_logical_id="logicalId", | ||
| name="authName", | ||
| identity={"ReauthorizeEvery": {"FN:If": ["isProd", 10, 0]}, "Headers": ["Accept"]}, | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: the intrinsic key is actually  | ||
| function_payload_type="REQUEST", | ||
| ) | ||
|  | ||
| self.assertIsNotNone(auth) | ||
|  | ||
| def test_create_authorizer_with_identity_intrinsic_is_invalid_if_no_querystring_stagevariables_context_headers( | ||
| self, | ||
| ): | ||
| with pytest.raises(InvalidResourceException): | ||
| ApiGatewayAuthorizer( | ||
| api_logical_id="logicalId", | ||
| name="authName", | ||
| identity={"ReauthorizeEvery": {"FN:If": ["isProd", 10, 0]}}, | ||
| function_payload_type="REQUEST", | ||
| ) | ||
|  | ||
| def test_create_authorizer_with_identity_intrinsic_is_valid_with_context(self): | ||
| auth = ApiGatewayAuthorizer( | ||
| api_logical_id="logicalId", | ||
| name="authName", | ||
| identity={"ReauthorizeEvery": {"FN:If": ["isProd", 10, 0]}, "Context": ["Accept"]}, | ||
| function_payload_type="REQUEST", | ||
| ) | ||
|  | ||
| self.assertIsNotNone(auth) | ||
|  | ||
| def test_create_authorizer_with_identity_intrinsic_is_valid_with_stage_variables(self): | ||
| auth = ApiGatewayAuthorizer( | ||
| api_logical_id="logicalId", | ||
| name="authName", | ||
| identity={"ReauthorizeEvery": {"FN:If": ["isProd", 10, 0]}, "StageVariables": ["Stage"]}, | ||
| function_payload_type="REQUEST", | ||
| ) | ||
|  | ||
| self.assertIsNotNone(auth) | ||
|  | ||
| def test_create_authorizer_with_identity_intrinsic_is_valid_with_query_strings(self): | ||
| auth = ApiGatewayAuthorizer( | ||
| api_logical_id="logicalId", | ||
| name="authName", | ||
| identity={"ReauthorizeEvery": {"FN:If": ["isProd", 10, 0]}, "QueryStrings": ["AQueryString"]}, | ||
| function_payload_type="REQUEST", | ||
| ) | ||
|  | ||
| self.assertIsNotNone(auth) | ||
|  | ||
| def test_create_authorizer_with_identity_ReauthorizeEvery_asNone_valid_with_query_strings(self): | ||
| auth = ApiGatewayAuthorizer( | ||
| api_logical_id="logicalId", | ||
| name="authName", | ||
| identity={"ReauthorizeEvery": None, "QueryStrings": ["AQueryString"]}, | ||
| function_payload_type="REQUEST", | ||
| ) | ||
|  | ||
| self.assertIsNotNone(auth) | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| AWSTemplateFormatVersion: "2010-09-09" | ||
| Transform: AWS::Serverless-2016-10-31 | ||
|  | ||
| Conditions: | ||
| isProd: true | ||
|  | ||
|  | ||
| Resources: | ||
| APIGateway: | ||
| Type: 'AWS::Serverless::Api' | ||
| Properties: | ||
| StageName: Prod | ||
| Auth: | ||
| DefaultAuthorizer: SomeAuthorizer | ||
| Authorizers: | ||
| SomeAuthorizer: | ||
| FunctionPayloadType: REQUEST | ||
| FunctionArn: SomeArn | ||
| Identity: | ||
| Headers: | ||
| - Accept | ||
| ReauthorizeEvery: !If [isProd, 3600, 0] | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.