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

feat(cognito): user pools - non-ascii email domains #11099

Merged
merged 7 commits into from
Nov 9, 2020

Conversation

wtho
Copy link
Contributor

@wtho wtho commented Oct 25, 2020

If an email address for cognito email settings contains a non-ascii character, the cognito cdk package applies punycode encoding, which cloudformation will pick up properly.

This pull request adds the punycode package to the dependencies, as previously discussed in #8473. The package occupies 42KB in node_modules after installation. I am not sure if I configured the package correctly to be included in the cdk build. The project itself added punycode to aws-cdk-lib and monocdk, I had to re-run yarn install in these packages.

Unit- and integration tests are added, but notice that I could not manage a manual e2e test, I think I need to own a domain with non-ascii letters to do so, which I currently do not.

A similar approach as in this PR will also be interesting for other cdk packages which deal with email addresses and domains, like hosted zones.

According to the Cfn Domain Name Format Docs, characters with code point below 33, or in [127, 255] should be escaped with an octal code, which is not applied in this pull request.

Fixes #8473


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Oct 25, 2020

@wtho wtho force-pushed the wtho/cognito-userpool-punycode-encoding branch from c6c65b6 to 64d2a5f Compare October 25, 2020 20:12
@nija-at nija-at changed the title feat(cognito): auto-encode non-ascii domains feat(cognito): user pool - non-ascii email domains Oct 28, 2020
@nija-at nija-at changed the title feat(cognito): user pool - non-ascii email domains feat(cognito): user pools - non-ascii email domains Oct 28, 2020
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

Thanks for submitting this PR. Looks pretty good. Some minor suggestions below.

You will also need to merge latest from 'master' and resolve the merge conflict.

If an email address for cognito email settings contains a non-ascii
character, the cognito cdk package applies punycode encoding, which
cloudformation will pick up properly.
@wtho wtho force-pushed the wtho/cognito-userpool-punycode-encoding branch from 64d2a5f to d7301f4 Compare October 28, 2020 16:31
@mergify mergify bot dismissed nija-at’s stale review October 28, 2020 16:31

Pull request has been modified.

Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

I'd like to wait for this PR to be merged - #11195 - and rebase this change on top, so that we can correctly add attributions to 3rd party bundled dependencies.

@mergify mergify bot dismissed nija-at’s stale review October 29, 2020 17:36

Pull request has been modified.

@wtho wtho force-pushed the wtho/cognito-userpool-punycode-encoding branch 2 times, most recently from bdd9a31 to 308f32c Compare October 30, 2020 18:08
@wtho
Copy link
Contributor Author

wtho commented Oct 30, 2020

I added the lint rule in cognito's eslintrc.js, but we could move it to the common lint rule configuration if you prefer so.

nija-at
nija-at previously requested changes Nov 2, 2020
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

Thanks for your patience with this.
A couple of more adjustments to the eslint rule.

packages/@aws-cdk/aws-cognito/.eslintrc.js Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-cognito/package.json Outdated Show resolved Hide resolved
packages/monocdk/NOTICE Outdated Show resolved Hide resolved
@wtho wtho force-pushed the wtho/cognito-userpool-punycode-encoding branch from 74af44c to 2b9dfa1 Compare November 2, 2020 16:14
@mergify mergify bot dismissed nija-at’s stale review November 2, 2020 16:14

Pull request has been modified.

@wtho wtho force-pushed the wtho/cognito-userpool-punycode-encoding branch 2 times, most recently from bcdf43b to 7369218 Compare November 3, 2020 19:21
@wtho wtho requested review from rix0rrr and nija-at November 4, 2020 15:16
nija-at
nija-at previously requested changes Nov 6, 2020
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

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

Sorry for the delay. I was on vacation earlier in the week.

Comment on lines 1026 to 1028
function encodeDomain(email: string | undefined): string | undefined {
const splitEmail = email?.split('@');
if (splitEmail === undefined || splitEmail.length !== 2) {
return email;
}
const [local, domain] = splitEmail!;
return `${local}@${punycodeEncode(domain)}`;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we just use the toASCII() API instead. According to the documentation, it takes care of emails.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, but it also encodes the part before the @, which for AWS/Cloudformation should not be encoded. See rix0rr's earlier comment and the documentation.

Copy link
Contributor

@nija-at nija-at Nov 6, 2020

Choose a reason for hiding this comment

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

Not according to the example in the docs that I've linked above. Specifically example#3 shows that the first half of the email address is NOT encoded.

Does the library behave differently? Can you test this and report?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are correct! Did not go through the documentation properly!

I reverted back to the toASCII method, as previously.

@wtho wtho force-pushed the wtho/cognito-userpool-punycode-encoding branch from 7369218 to 79cba93 Compare November 6, 2020 18:02
@mergify mergify bot dismissed nija-at’s stale review November 6, 2020 18:03

Pull request has been modified.

@mergify
Copy link
Contributor

mergify bot commented Nov 9, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 319795a
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Nov 9, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 5d907b6 into aws:master Nov 9, 2020
@wtho wtho deleted the wtho/cognito-userpool-punycode-encoding branch November 9, 2020 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cyrillic email domain in Cognito UserPool does not work
4 participants