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: Count UTF-8 string length by # of chars vs. bytes in message and subject args for aws_cognito_user_pool #36661

Conversation

acwwat
Copy link
Contributor

@acwwat acwwat commented Mar 30, 2024

Description

This PR is to fix the validation functions of the *message and *subject arguments in the aws_cognito_user_pool resource, which allows UTF-8 characters, so that the # of characters are counted by runes and not by bytes.

Note: When I initially added a new test case with max size messages and subjects, the API will fail with a 413 object too large error. I believe this is a bug with the AWS API since the API specs should technically allow messages up to 20000 characters, including UTF-8. To allow the test case to pass, I've reduced the message sizes to 1000 characters. Meanwhile I've opened an AWS support case to see if they can address it. So be aware that even with this fix, you probably can't use very long messages.

Relations

Closes #32607

References

Referred to CreateUserPool and Configuring SMS and email verification messages and user invitation messages for the specs.

Output from Acceptance Testing

$ make testacc TESTS=TestValidUserPool PKG=cognitoidp
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/cognitoidp/... -v -count 1 -parallel 20 -run='TestValidUserPool'  -timeout 360m
=== RUN   TestValidUserPoolEmailVerificationMessage
=== PAUSE TestValidUserPoolEmailVerificationMessage
=== RUN   TestValidUserPoolEmailVerificationSubject
=== PAUSE TestValidUserPoolEmailVerificationSubject
=== RUN   TestValidUserPoolID
=== PAUSE TestValidUserPoolID
=== RUN   TestValidUserPoolSMSAuthenticationMessage
=== PAUSE TestValidUserPoolSMSAuthenticationMessage
=== RUN   TestValidUserPoolSMSVerificationMessage
=== PAUSE TestValidUserPoolSMSVerificationMessage
=== CONT  TestValidUserPoolEmailVerificationMessage
=== CONT  TestValidUserPoolSMSAuthenticationMessage
=== CONT  TestValidUserPoolID
=== CONT  TestValidUserPoolSMSVerificationMessage
=== CONT  TestValidUserPoolEmailVerificationSubject
--- PASS: TestValidUserPoolID (0.00s)
--- PASS: TestValidUserPoolSMSAuthenticationMessage (0.00s)
--- PASS: TestValidUserPoolSMSVerificationMessage (0.00s)
--- PASS: TestValidUserPoolEmailVerificationSubject (0.00s)
--- PASS: TestValidUserPoolEmailVerificationMessage (0.00s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/cognitoidp 0.166s

$
$ make testacc TESTS=TestAccCognitoIDPUserPool_ PKG=cognitoidp
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/cognitoidp/... -v -count 1 -parallel 20 -run='TestAccCognitoIDPUserPool_'  -timeout 360m
=== RUN   TestAccCognitoIDPUserPool_basic
=== PAUSE TestAccCognitoIDPUserPool_basic
=== RUN   TestAccCognitoIDPUserPool_deletionProtection
=== PAUSE TestAccCognitoIDPUserPool_deletionProtection
=== RUN   TestAccCognitoIDPUserPool_recovery
=== PAUSE TestAccCognitoIDPUserPool_recovery
=== RUN   TestAccCognitoIDPUserPool_withAdminCreateUser
=== PAUSE TestAccCognitoIDPUserPool_withAdminCreateUser
=== RUN   TestAccCognitoIDPUserPool_withAdminCreateUserAndPasswordPolicy
=== PAUSE TestAccCognitoIDPUserPool_withAdminCreateUserAndPasswordPolicy
=== RUN   TestAccCognitoIDPUserPool_withAdvancedSecurityMode
=== PAUSE TestAccCognitoIDPUserPool_withAdvancedSecurityMode
=== RUN   TestAccCognitoIDPUserPool_withDevice
=== PAUSE TestAccCognitoIDPUserPool_withDevice
=== RUN   TestAccCognitoIDPUserPool_withEmailVerificationMessage
=== PAUSE TestAccCognitoIDPUserPool_withEmailVerificationMessage
=== RUN   TestAccCognitoIDPUserPool_MFA_sms
=== PAUSE TestAccCognitoIDPUserPool_MFA_sms
=== RUN   TestAccCognitoIDPUserPool_MFA_smsAndSoftwareTokenMFA
=== PAUSE TestAccCognitoIDPUserPool_MFA_smsAndSoftwareTokenMFA
=== RUN   TestAccCognitoIDPUserPool_MFA_smsToSoftwareTokenMFA
=== PAUSE TestAccCognitoIDPUserPool_MFA_smsToSoftwareTokenMFA
=== RUN   TestAccCognitoIDPUserPool_MFA_softwareTokenMFA
=== PAUSE TestAccCognitoIDPUserPool_MFA_softwareTokenMFA
=== RUN   TestAccCognitoIDPUserPool_MFA_softwareTokenMFAToSMS
=== PAUSE TestAccCognitoIDPUserPool_MFA_softwareTokenMFAToSMS
=== RUN   TestAccCognitoIDPUserPool_smsAuthenticationMessage
=== PAUSE TestAccCognitoIDPUserPool_smsAuthenticationMessage
=== RUN   TestAccCognitoIDPUserPool_sms
=== PAUSE TestAccCognitoIDPUserPool_sms
=== RUN   TestAccCognitoIDPUserPool_SMS_snsRegion
=== PAUSE TestAccCognitoIDPUserPool_SMS_snsRegion
=== RUN   TestAccCognitoIDPUserPool_SMS_externalID
=== PAUSE TestAccCognitoIDPUserPool_SMS_externalID
=== RUN   TestAccCognitoIDPUserPool_SMS_snsCallerARN
=== PAUSE TestAccCognitoIDPUserPool_SMS_snsCallerARN
=== RUN   TestAccCognitoIDPUserPool_smsVerificationMessage
=== PAUSE TestAccCognitoIDPUserPool_smsVerificationMessage
=== RUN   TestAccCognitoIDPUserPool_withEmail
=== PAUSE TestAccCognitoIDPUserPool_withEmail
=== RUN   TestAccCognitoIDPUserPool_withEmailSource
    user_pool_test.go:885: Environment variable TEST_AWS_SES_VERIFIED_EMAIL_ARN is not set, skipping test
--- SKIP: TestAccCognitoIDPUserPool_withEmailSource (0.00s)
=== RUN   TestAccCognitoIDPUserPool_tags
=== PAUSE TestAccCognitoIDPUserPool_tags
=== RUN   TestAccCognitoIDPUserPool_withAliasAttributes
=== PAUSE TestAccCognitoIDPUserPool_withAliasAttributes
=== RUN   TestAccCognitoIDPUserPool_withUsernameAttributes
=== PAUSE TestAccCognitoIDPUserPool_withUsernameAttributes
=== RUN   TestAccCognitoIDPUserPool_withPasswordPolicy
=== PAUSE TestAccCognitoIDPUserPool_withPasswordPolicy
=== RUN   TestAccCognitoIDPUserPool_withUsername
=== PAUSE TestAccCognitoIDPUserPool_withUsername
=== RUN   TestAccCognitoIDPUserPool_withLambda
=== PAUSE TestAccCognitoIDPUserPool_withLambda
=== RUN   TestAccCognitoIDPUserPool_WithLambda_email
=== PAUSE TestAccCognitoIDPUserPool_WithLambda_email
=== RUN   TestAccCognitoIDPUserPool_WithLambda_sms
=== PAUSE TestAccCognitoIDPUserPool_WithLambda_sms
=== RUN   TestAccCognitoIDPUserPool_WithLambda_preGenerationTokenConfig
=== PAUSE TestAccCognitoIDPUserPool_WithLambda_preGenerationTokenConfig
=== RUN   TestAccCognitoIDPUserPool_schemaAttributes
=== PAUSE TestAccCognitoIDPUserPool_schemaAttributes
=== RUN   TestAccCognitoIDPUserPool_schemaAttributesRemoved
=== PAUSE TestAccCognitoIDPUserPool_schemaAttributesRemoved
=== RUN   TestAccCognitoIDPUserPool_schemaAttributesModified
=== PAUSE TestAccCognitoIDPUserPool_schemaAttributesModified
=== RUN   TestAccCognitoIDPUserPool_schemaAttributesStringAttributeConstraints
=== PAUSE TestAccCognitoIDPUserPool_schemaAttributesStringAttributeConstraints
=== RUN   TestAccCognitoIDPUserPool_withVerificationMessageTemplate
=== PAUSE TestAccCognitoIDPUserPool_withVerificationMessageTemplate
=== RUN   TestAccCognitoIDPUserPool_withVerificationMessageTemplateUTF8
=== PAUSE TestAccCognitoIDPUserPool_withVerificationMessageTemplateUTF8
=== RUN   TestAccCognitoIDPUserPool_update
=== PAUSE TestAccCognitoIDPUserPool_update
=== RUN   TestAccCognitoIDPUserPool_disappears
=== PAUSE TestAccCognitoIDPUserPool_disappears
=== RUN   TestAccCognitoIDPUserPool_withUserAttributeUpdateSettings
=== PAUSE TestAccCognitoIDPUserPool_withUserAttributeUpdateSettings
=== CONT  TestAccCognitoIDPUserPool_basic
=== CONT  TestAccCognitoIDPUserPool_withEmail
=== CONT  TestAccCognitoIDPUserPool_schemaAttributes
=== CONT  TestAccCognitoIDPUserPool_withVerificationMessageTemplateUTF8
=== CONT  TestAccCognitoIDPUserPool_disappears
=== CONT  TestAccCognitoIDPUserPool_withUsername
=== CONT  TestAccCognitoIDPUserPool_schemaAttributesStringAttributeConstraints
=== CONT  TestAccCognitoIDPUserPool_withVerificationMessageTemplate
=== CONT  TestAccCognitoIDPUserPool_WithLambda_sms
=== CONT  TestAccCognitoIDPUserPool_WithLambda_preGenerationTokenConfig
=== CONT  TestAccCognitoIDPUserPool_schemaAttributesModified
=== CONT  TestAccCognitoIDPUserPool_withUsernameAttributes
=== CONT  TestAccCognitoIDPUserPool_withPasswordPolicy
=== CONT  TestAccCognitoIDPUserPool_update
=== CONT  TestAccCognitoIDPUserPool_MFA_smsToSoftwareTokenMFA
=== CONT  TestAccCognitoIDPUserPool_smsVerificationMessage
=== CONT  TestAccCognitoIDPUserPool_SMS_snsCallerARN
=== CONT  TestAccCognitoIDPUserPool_SMS_externalID
=== CONT  TestAccCognitoIDPUserPool_SMS_snsRegion
=== CONT  TestAccCognitoIDPUserPool_sms
--- PASS: TestAccCognitoIDPUserPool_disappears (132.71s)
=== CONT  TestAccCognitoIDPUserPool_smsAuthenticationMessage
--- PASS: TestAccCognitoIDPUserPool_withEmail (146.69s)
=== CONT  TestAccCognitoIDPUserPool_MFA_softwareTokenMFAToSMS
--- PASS: TestAccCognitoIDPUserPool_basic (151.13s)
=== CONT  TestAccCognitoIDPUserPool_MFA_softwareTokenMFA
--- PASS: TestAccCognitoIDPUserPool_schemaAttributesStringAttributeConstraints (178.62s)
=== CONT  TestAccCognitoIDPUserPool_WithLambda_email
--- PASS: TestAccCognitoIDPUserPool_schemaAttributesModified (192.96s)
=== CONT  TestAccCognitoIDPUserPool_withAliasAttributes
--- PASS: TestAccCognitoIDPUserPool_withPasswordPolicy (244.53s)
=== CONT  TestAccCognitoIDPUserPool_withUserAttributeUpdateSettings
--- PASS: TestAccCognitoIDPUserPool_withVerificationMessageTemplate (245.32s)
=== CONT  TestAccCognitoIDPUserPool_withLambda
--- PASS: TestAccCognitoIDPUserPool_smsVerificationMessage (249.77s)
=== CONT  TestAccCognitoIDPUserPool_schemaAttributesRemoved
--- PASS: TestAccCognitoIDPUserPool_withVerificationMessageTemplateUTF8 (250.24s)
=== CONT  TestAccCognitoIDPUserPool_tags
--- PASS: TestAccCognitoIDPUserPool_schemaAttributes (255.53s)
=== CONT  TestAccCognitoIDPUserPool_withAdvancedSecurityMode
--- PASS: TestAccCognitoIDPUserPool_withUsername (262.78s)
=== CONT  TestAccCognitoIDPUserPool_MFA_smsAndSoftwareTokenMFA
--- PASS: TestAccCognitoIDPUserPool_withUsernameAttributes (265.03s)
=== CONT  TestAccCognitoIDPUserPool_MFA_sms
--- PASS: TestAccCognitoIDPUserPool_SMS_snsRegion (370.45s)
=== CONT  TestAccCognitoIDPUserPool_withEmailVerificationMessage
--- PASS: TestAccCognitoIDPUserPool_smsAuthenticationMessage (266.71s)
=== CONT  TestAccCognitoIDPUserPool_withDevice
--- PASS: TestAccCognitoIDPUserPool_MFA_smsToSoftwareTokenMFA (411.84s)
=== CONT  TestAccCognitoIDPUserPool_withAdminCreateUser
--- PASS: TestAccCognitoIDPUserPool_schemaAttributesRemoved (192.18s)
=== CONT  TestAccCognitoIDPUserPool_withAdminCreateUserAndPasswordPolicy
--- PASS: TestAccCognitoIDPUserPool_withAliasAttributes (288.79s)
=== CONT  TestAccCognitoIDPUserPool_recovery
--- PASS: TestAccCognitoIDPUserPool_withUserAttributeUpdateSettings (281.21s)
=== CONT  TestAccCognitoIDPUserPool_deletionProtection
--- PASS: TestAccCognitoIDPUserPool_MFA_softwareTokenMFA (395.09s)
--- PASS: TestAccCognitoIDPUserPool_SMS_externalID (565.35s)
--- PASS: TestAccCognitoIDPUserPool_MFA_softwareTokenMFAToSMS (459.64s)
--- PASS: TestAccCognitoIDPUserPool_SMS_snsCallerARN (613.08s)
--- PASS: TestAccCognitoIDPUserPool_withAdminCreateUserAndPasswordPolicy (190.01s)
--- PASS: TestAccCognitoIDPUserPool_tags (389.98s)
--- PASS: TestAccCognitoIDPUserPool_withAdvancedSecurityMode (392.29s)
--- PASS: TestAccCognitoIDPUserPool_sms (666.08s)
--- PASS: TestAccCognitoIDPUserPool_withEmailVerificationMessage (297.58s)
--- PASS: TestAccCognitoIDPUserPool_withDevice (279.41s)
--- PASS: TestAccCognitoIDPUserPool_withAdminCreateUser (270.70s)
--- PASS: TestAccCognitoIDPUserPool_WithLambda_preGenerationTokenConfig (713.60s)
--- PASS: TestAccCognitoIDPUserPool_deletionProtection (201.47s)
--- PASS: TestAccCognitoIDPUserPool_update (747.89s)
--- PASS: TestAccCognitoIDPUserPool_WithLambda_sms (752.08s)
--- PASS: TestAccCognitoIDPUserPool_recovery (272.24s)
--- PASS: TestAccCognitoIDPUserPool_MFA_smsAndSoftwareTokenMFA (508.70s)
--- PASS: TestAccCognitoIDPUserPool_MFA_sms (535.12s)
--- PASS: TestAccCognitoIDPUserPool_WithLambda_email (632.77s)
--- PASS: TestAccCognitoIDPUserPool_withLambda (662.11s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/cognitoidp 907.618s

$

Copy link

Community Note

Voting for Prioritization

  • Please vote on this pull request by adding a 👍 reaction to the original post to help the community and maintainers prioritize this pull request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added size/L Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. service/cognitoidp Issues and PRs that pertain to the cognitoidp service. labels Mar 30, 2024
@terraform-aws-provider terraform-aws-provider bot added needs-triage Waiting for first response or review from a maintainer. external-maintainer Contribution from a trusted external contributor. labels Mar 30, 2024
@acwwat acwwat force-pushed the b-aws_cognito_user_pool-fix_utf8_str_len_validations branch from 0afa864 to 0712e62 Compare March 30, 2024 21:35
@acwwat acwwat changed the title [WIP] fix: Count UTF-8 string length by # of chars vs. bytes in message and subject args for aws_cognito_user_pool fix: Count UTF-8 string length by # of chars vs. bytes in message and subject args for aws_cognito_user_pool Mar 30, 2024
@acwwat acwwat force-pushed the b-aws_cognito_user_pool-fix_utf8_str_len_validations branch from 0712e62 to 4e69533 Compare March 30, 2024 21:36
@ewbankkit ewbankkit removed the needs-triage Waiting for first response or review from a maintainer. label Apr 1, 2024
Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

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

LGTM 🚀.

% make testacc TESTARGS='-run=TestAccCognitoIDPUserPool_withVerificationMessageTemplate\|TestAccCognitoIDPUserPool_withVerificationMessageTemplateUTF8' PKG=cognitoidp
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.21.8 test ./internal/service/cognitoidp/... -v -count 1 -parallel 20  -run=TestAccCognitoIDPUserPool_withVerificationMessageTemplate\|TestAccCognitoIDPUserPool_withVerificationMessageTemplateUTF8 -timeout 360m
=== RUN   TestAccCognitoIDPUserPool_withVerificationMessageTemplate
=== PAUSE TestAccCognitoIDPUserPool_withVerificationMessageTemplate
=== RUN   TestAccCognitoIDPUserPool_withVerificationMessageTemplateUTF8
=== PAUSE TestAccCognitoIDPUserPool_withVerificationMessageTemplateUTF8
=== CONT  TestAccCognitoIDPUserPool_withVerificationMessageTemplate
=== CONT  TestAccCognitoIDPUserPool_withVerificationMessageTemplateUTF8
--- PASS: TestAccCognitoIDPUserPool_withVerificationMessageTemplate (37.90s)
--- PASS: TestAccCognitoIDPUserPool_withVerificationMessageTemplateUTF8 (37.93s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/cognitoidp	50.241s

@ewbankkit
Copy link
Contributor

@xxx Thanks for the contribution 🎉 👏.

@ewbankkit ewbankkit merged commit 55a6cbf into hashicorp:main Apr 1, 2024
29 checks passed
@github-actions github-actions bot added this to the v5.44.0 milestone Apr 1, 2024
@acwwat acwwat deleted the b-aws_cognito_user_pool-fix_utf8_str_len_validations branch April 1, 2024 19:33
Copy link

github-actions bot commented Apr 5, 2024

This functionality has been released in v5.44.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

github-actions bot commented May 7, 2024

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
external-maintainer Contribution from a trusted external contributor. service/cognitoidp Issues and PRs that pertain to the cognitoidp service. size/L Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Cognito SMS message character limit
2 participants