Skip to content

Commit

Permalink
Add region validation using DNS Host label regex (#3368)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored Jul 27, 2020
1 parent 788a009 commit 5e0d7f6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-Region-3a08ee8a.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "Region",
"description": "Add region validation using DNS Host label regex"
}
12 changes: 9 additions & 3 deletions lib/event_listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,15 @@ AWS.EventListeners = {
});

add('VALIDATE_REGION', 'validate', function VALIDATE_REGION(req) {
if (!req.service.config.region && !req.service.isGlobalEndpoint) {
req.response.error = AWS.util.error(new Error(),
{code: 'ConfigError', message: 'Missing region in config'});
if (!req.service.isGlobalEndpoint) {
var dnsHostRegex = new RegExp(/^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9])$/);
if (!req.service.config.region) {
req.response.error = AWS.util.error(new Error(),
{code: 'ConfigError', message: 'Missing region in config'});
} else if (!dnsHostRegex.test(req.service.config.region)) {
req.response.error = AWS.util.error(new Error(),
{code: 'ConfigError', message: 'Invalid region in config'});
}
}
});

Expand Down
63 changes: 53 additions & 10 deletions test/event_listeners.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5e0d7f6

Please sign in to comment.