Limit length of cognito user pool prefix to 63 #2343
Merged
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.
What does this change?
I recently ran into an issue when trying to add googleAuth to a project with a rather long app name:
1 validation error detected: Value 'com-gu-myvery-looong-appname-prod-6ead8aa1447b718dd224f9eab2808b25' at 'domain' failed to satisfy constraint: Member must have length less than or equal to 63 (Service: AWSCognitoIdentityProviderService; Status Code: 400; Error Code: InvalidParameterException; Request ID: f58fe6de-1cf3-44a2-8498-a3afaca5bd3b; Proxy: null)
This change attempts to resolve the issue by trimming the generated domain prefix to 63 chars. I'm making an assumption that a 5 char hash will be enough to ensure uniqueness (the current md5 hash is 32 chars).
The important thing here is that we don't want to change the domainPrefix of any existing cognito user pools, which is why I'm only trimming the domainPrefix when the length is greater than 63.
How to test
I've added a few unit tests - see what you think. I tested against the offending project and was able to succesfully set up google auth: