-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6309775
add validation
badmintoncryer 98a0dc2
add unit test
badmintoncryer 7fed8a6
Merge branch 'main' into domainNameValidation
badmintoncryer ea43c6a
update
badmintoncryer 7234ea0
update integ test
badmintoncryer d43d22f
update integ test
badmintoncryer ad14c70
revert package.json
badmintoncryer 23efe87
Merge remote-tracking branch 'origin/main' into domainNameValidation
badmintoncryer 91efe52
Merge branch 'main' into domainNameValidation
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,5 +175,6 @@ | |
}, | ||
"dependencies": { | ||
"string-width": "^4.2.3" | ||
} | ||
}, | ||
"packageManager": "[email protected]+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think it would be more helpful to include "characters" in the error message. |
||||||
} | ||||||
if (!/^(((?!-)[A-Za-z0-9-]{0,62}[A-Za-z0-9])\.)+((?!-)[A-Za-z0-9-]{1,62}[A-Za-z0-9])(\.)?$/.test(domainName)) { | ||||||
throw new Error(`Domain name must be a valid hostname, got: ${domainName}`); | ||||||
} | ||||||
|
||||||
const domain = new CfnDomain(this, 'Resource', { | ||||||
appId: props.app.appId, | ||||||
domainName, | ||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -176,6 +176,55 @@ test('map a branch to the domain root', () => { | |||||
}); | ||||||
}); | ||||||
|
||||||
test('throw error for invalid domain name length', () => { | ||||||
const stack = new Stack(); | ||||||
const app = new amplify.App(stack, 'App', { | ||||||
sourceCodeProvider: new amplify.GitHubSourceCodeProvider({ | ||||||
owner: 'aws', | ||||||
repository: 'aws-cdk', | ||||||
oauthToken: SecretValue.unsafePlainText('secret'), | ||||||
}), | ||||||
}); | ||||||
const prodBranch = app.addBranch('main'); | ||||||
|
||||||
expect(() => app.addDomain('Domain', { | ||||||
subDomains: [ | ||||||
{ | ||||||
branch: prodBranch, | ||||||
prefix: 'prod', | ||||||
}, | ||||||
], | ||||||
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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}); | ||||||
|
||||||
test.each([ | ||||||
'-example.com', | ||||||
'example..com', | ||||||
'example.com-', | ||||||
'[email protected]', | ||||||
])('throw error for invalid domain name', (domainName) => { | ||||||
const stack = new Stack(); | ||||||
const app = new amplify.App(stack, 'App', { | ||||||
sourceCodeProvider: new amplify.GitHubSourceCodeProvider({ | ||||||
owner: 'aws', | ||||||
repository: 'aws-cdk', | ||||||
oauthToken: SecretValue.unsafePlainText('secret'), | ||||||
}), | ||||||
}); | ||||||
const prodBranch = app.addBranch('main'); | ||||||
|
||||||
expect(() => app.addDomain('Domain', { | ||||||
subDomains: [ | ||||||
{ | ||||||
branch: prodBranch, | ||||||
prefix: 'prod', | ||||||
}, | ||||||
], | ||||||
domainName, | ||||||
})).toThrow(`Domain name must be a valid hostname, got: ${domainName}`); | ||||||
}); | ||||||
|
||||||
test('throws at synthesis without subdomains', () => { | ||||||
// GIVEN | ||||||
const app = new App(); | ||||||
|
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.
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.
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!