-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
chore(amplify): domain name validation #31959
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution.
some minor comments.
@@ -131,6 +131,13 @@ export class Domain extends Resource { | |||
this.subDomains = props.subDomains || []; | |||
|
|||
const domainName = props.domainName || id; | |||
if (domainName.length > 255) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might need to check token.
Token.isUnresolved(domainName)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I keep forgetting to check the token no matter how many times I try... Thank you for the reminder!
@@ -131,6 +131,13 @@ export class Domain extends Resource { | |||
this.subDomains = props.subDomains || []; | |||
|
|||
const domainName = props.domainName || id; | |||
if (domainName.length > 255) { | |||
throw new Error(`Domain name must be 255 characters or less, got: ${domainName.length}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new Error(`Domain name must be 255 characters or less, got: ${domainName.length}`); | |
throw new Error(`Domain name must be 255 characters or less, got: ${domainName.length} characters.`); |
I think it would be more helpful to include "characters" in the error message.
}, | ||
], | ||
domainName: 'a'.repeat(256), | ||
})).toThrow('Domain name must be 255 characters or less, got: 256'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
})).toThrow('Domain name must be 255 characters or less, got: 256'); | |
})).toThrow('Domain name must be 255 characters or less, got: 256 characters.'); |
@mazyu36 Thank you for your really quick review!! I've addressed all of your comments. Unfortunately, the /codebuild/output/src3849279982/src/github.com/aws/aws-cdk/packages/@aws-cdk/aws-amplify-alpha/lib/domain.js:30
@aws-cdk/aws-amplify-alpha: throw new Error(`Domain name must be a valid hostname, got: ${domainName}`);
@aws-cdk/aws-amplify-alpha: ^
@aws-cdk/aws-amplify-alpha: Error: Domain name must be a valid hostname, got: *.example.com
@aws-cdk/aws-amplify-alpha: at new Domain (/codebuild/output/src3849279982/src/github.com/aws/aws-cdk/packages/@aws-cdk/aws-amplify-alpha/lib/domain.js:30:19)
@aws-cdk/aws-amplify-alpha: at App.addDomain (/codebuild/output/src3849279982/src/github.com/aws/aws-cdk/packages/@aws-cdk/aws-amplify-alpha/lib/app.js:151:16)
@aws-cdk/aws-amplify-alpha: at new TestStack (/codebuild/output/src3849279982/src/github.com/aws/aws-cdk/packages/@aws-cdk/aws-amplify-alpha/test/integ.app-custom-domain.js:28:28)
@aws-cdk/aws-amplify-alpha: at Object.<anonymous> (/codebuild/output/src3849279982/src/github.com/aws/aws-cdk/packages/@aws-cdk/aws-amplify-alpha/test/integ.app-custom-domain.js:54:15)
@aws-cdk/aws-amplify-alpha: at Module._compile (node:internal/modules/cjs/loader:1364:14)
@aws-cdk/aws-amplify-alpha: at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
@aws-cdk/aws-amplify-alpha: at Module.load (node:internal/modules/cjs/loader:1203:32)
@aws-cdk/aws-amplify-alpha: at Module._load (node:internal/modules/cjs/loader:1019:12)
@aws-cdk/aws-amplify-alpha: at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
@aws-cdk/aws-amplify-alpha: at node:internal/main/run_main_module:28:49
@aws-cdk/aws-amplify-alpha: Node.js v18.20.4
@aws-cdk/aws-amplify-alpha: ERROR integ.app-custom-domain 0.509s |
@badmintoncryer For integ test runs, the actual domain is set in an environment variable. I’m currently considering ways to avoid this, but I haven’t found a good solution yet. |
@mazyu36 Thank you for your detailed information! I understand very well! If I modify the referenced value to - const domainName = process.env.CDK_INTEG_DOMAIN_NAME ?? process.env.DOMAIN_NAME;
+ const domainName = process.env.CDK_INTEG_HOSTED_ZONE_NAME ?? process.env.DOMAIN_NAME; This is a good opportunity, so I’ll go ahead and try purchasing a domain too. Haha |
@badmintoncryer |
@mazyu36 I've bought my domain and rerun integ test. |
3a74ca1
to
23efe87
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM
@Mergifyio update |
✅ Branch has been successfully updated |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
None
Reason for this change
We can configure amplify domain name but there is no validation for that.
Description of changes
Add validation for an amplify domain name
Description of how you validated changes
Add unit test
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license