Skip to content
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

fix: ValueError is not caught by int() #2305

Merged
merged 2 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion samtranslator/model/apigateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def _is_missing_identity_source(self, identity):
try:
ttl_int = int(ttl)
# this will catch if ttl is None and not convertable to an int
except TypeError:
except (TypeError, ValueError):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a unit test case to show when exactly this exception will be thrown?
My understanding is ValueError will be thrown if ttl value contains a non numeric value, and I think in this case we should throw a different exception

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, test cases added.

# previous behavior before trying to read ttl
return required_properties_missing

Expand Down
4 changes: 4 additions & 0 deletions tests/validator/input/api/error_auth_cognito.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Resources:
Identity:
ReauthorizeEvery: "3"
UserPoolArn: User.pool.arn
CognitoIdentityReauthorizeEveryValueError:
Identity:
ReauthorizeEvery: NotANumber
UserPoolArn: User.pool.arn
CognitoIdentityReauthorizeEveryTooHigh:
Identity:
ReauthorizeEvery: 3601
Expand Down
1 change: 1 addition & 0 deletions tests/validator/output/api/error_auth_cognito.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"[Resources.MyApi.Properties.Auth.Authorizers.CognitoIdentityReauthorizeEveryNotInt.Identity.ReauthorizeEvery] '3' is not of type 'integer', 'intrinsic'",
"[Resources.MyApi.Properties.Auth.Authorizers.CognitoIdentityReauthorizeEveryTooHigh.Identity.ReauthorizeEvery] 3601 is greater than the maximum of 3600",
"[Resources.MyApi.Properties.Auth.Authorizers.CognitoIdentityReauthorizeEveryTooLow.Identity.ReauthorizeEvery] 0 is less than the minimum of 1",
"[Resources.MyApi.Properties.Auth.Authorizers.CognitoIdentityReauthorizeEveryValueError.Identity.ReauthorizeEvery] 'NotANumber' is not of type 'integer', 'intrinsic'",
"[Resources.MyApi.Properties.Auth.Authorizers.CognitoIdentityValidationExpressionEmpty.Identity.ValidationExpression] Must not be empty",
"[Resources.MyApi.Properties.Auth.Authorizers.CognitoIdentityValidationExpressionNotString.Identity.ValidationExpression] 3 is not of type 'string'",
"[Resources.MyApi.Properties.Auth.Authorizers.CognitoUserPoolArnEmpty.UserPoolArn] Must not be empty",
Expand Down