-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(amplify): domain name validation (#31959)
### 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 - length must be lower than 255 characters - match with [the regular expression](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-amplify-domain.html#cfn-amplify-domain-domainname) - /^(((?!-)[A-Za-z0-9-]{0,62}[A-Za-z0-9])\.)+((?!-)[A-Za-z0-9-]{1,62}[A-Za-z0-9])(\.)?$/ ### Description of how you validated changes Add unit test ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
aee1b30
commit 5137e38
Showing
10 changed files
with
130 additions
and
75 deletions.
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
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 characters.'); | ||
}); | ||
|
||
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(); | ||
|
2 changes: 1 addition & 1 deletion
2
...domain.js.snapshot/amplifyappcustomdomainintegDefaultTestDeployAssert5F8CD1EB.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
...-alpha/test/integ.app-custom-domain.js.snapshot/cdk-amplify-app-custom-domain.assets.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
packages/@aws-cdk/aws-amplify-alpha/test/integ.app-custom-domain.js.snapshot/cdk.out
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
packages/@aws-cdk/aws-amplify-alpha/test/integ.app-custom-domain.js.snapshot/integ.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 7 additions & 8 deletions
15
packages/@aws-cdk/aws-amplify-alpha/test/integ.app-custom-domain.js.snapshot/manifest.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.