-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate DNS when using S3 virtual-addressing mode
Needed to validate S3 bucket names when used in virtual-addressing mode. Valid DNS hostnames are composed from valid DNS labels. Valid DNS labels follow the following rules: 1. Have a maximum length of 63 octets (the entirety of the hostname cannot exceed 255 octets) 2. Composed of just alphanumeric characters and dashes 3. Does not start or end with a dash '-' https://www.ietf.org/rfc/rfc1035.txt
- Loading branch information
1 parent
0876431
commit 44b6404
Showing
8 changed files
with
152 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ Release | |
*~ | ||
*# | ||
*.iml | ||
tags | ||
|
||
#compiled python files | ||
*.pyc | ||
|
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
|
||
/* | ||
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
#include <aws/external/gtest.h> | ||
#include <aws/core/utils/Dns.h> | ||
|
||
using namespace Aws::Utils; | ||
|
||
TEST(DnsTest, TestValidDnsLabels) | ||
{ | ||
ASSERT_TRUE(IsValidDnsLabel("a")); | ||
ASSERT_TRUE(IsValidDnsLabel("ab")); | ||
ASSERT_TRUE(IsValidDnsLabel("abc")); | ||
ASSERT_TRUE(IsValidDnsLabel("contains-dashes-in-the-middle")); | ||
ASSERT_TRUE(IsValidDnsLabel("123StartsWithNumbers")); | ||
ASSERT_TRUE(IsValidDnsLabel("Ends-With-Numbers123")); | ||
ASSERT_TRUE(IsValidDnsLabel("123StartsAndEndsWithNumbers000")); | ||
ASSERT_TRUE(IsValidDnsLabel("42")); | ||
ASSERT_TRUE(IsValidDnsLabel("012345678901234567890123456789012345678901234567890123456789012")); // 63 characters | ||
} | ||
|
||
TEST(DnsTest, TestInvalidDnsLabels) | ||
{ | ||
ASSERT_FALSE(IsValidDnsLabel("")); | ||
ASSERT_FALSE(IsValidDnsLabel("has_underscore")); | ||
ASSERT_FALSE(IsValidDnsLabel("trailing-dash-")); | ||
ASSERT_FALSE(IsValidDnsLabel("-starts-with-dash")); | ||
ASSERT_FALSE(IsValidDnsLabel("ends-with-dash-")); | ||
ASSERT_FALSE(IsValidDnsLabel("-starts-and-ends-with-dash-")); | ||
ASSERT_FALSE(IsValidDnsLabel("-")); | ||
ASSERT_FALSE(IsValidDnsLabel("c0nt@in$-$ymb01$")); | ||
ASSERT_FALSE(IsValidDnsLabel("0123456789012345678901234567890123456789012345678901234567890123")); // 64 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <aws/core/utils/memory/stl/AWSString.h> | ||
|
||
namespace Aws | ||
{ | ||
namespace Utils | ||
{ | ||
AWS_CORE_API bool IsValidDnsLabel(const Aws::String& label); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
|
||
|
||
|
||
#include <aws/core/utils/DNS.h> | ||
#include <regex> | ||
|
||
namespace Aws | ||
{ | ||
namespace Utils | ||
{ | ||
bool IsValidDnsLabel(const Aws::String& label) | ||
{ | ||
// Valid DNS hostnames are composed of valid DNS labels separated by a period. | ||
// Valid DNS labels are characterized by the following: | ||
// 1- Only contains alphanumeric characters and/or dashes | ||
// 2- Cannot start or end with a dash | ||
// 3- Have a maximum length of 63 characters (the entirety of the domain name should be less than 255 bytes) | ||
|
||
//TODO: consider making this regex static and passing std::regex_constants::optimize flag | ||
const std::regex dnsLabel("^[[:alnum:]](?:[[:alnum:]-]{0,61}[[:alnum:]])?$"); | ||
return regex_search(label, dnsLabel); | ||
} | ||
} | ||
} |
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
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