Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(145)

Unified Diff: net/dns/dns_util_unittest.cc

Issue 2739203003: Measure how often DNS hostnames aren't in preferred name form. (Closed)
Patch Set: Rebase. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/dns/dns_util.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/dns/dns_util_unittest.cc
diff --git a/net/dns/dns_util_unittest.cc b/net/dns/dns_util_unittest.cc
index 1d534716b6afead994e02d9789c3ef0f130371ed..7b01d4263b926a24abc37042a59957ccf797697a 100644
--- a/net/dns/dns_util_unittest.cc
+++ b/net/dns/dns_util_unittest.cc
@@ -6,6 +6,28 @@
#include "testing/gtest/include/gtest/gtest.h"
+namespace {
+
+bool IsValidDNSDomainName(const char* name) {
+ size_t length = strlen(name);
+ for (size_t i = 0; i < length; ++i) {
+ if (name[i] == '.') {
+ if (i == 0 || name[i - 1] == '.') {
+ return false;
+ }
+ continue;
+ }
+
+ if (!net::IsValidHostLabelCharacter(name[i],
+ i == 0 || name[i - 1] == '.')) {
+ return false;
+ }
+ }
+ return true;
+}
+
+} // namespace
+
namespace net {
class DNSUtilTest : public testing::Test {
@@ -69,4 +91,30 @@ TEST_F(DNSUtilTest, DNSDomainToString) {
EXPECT_EQ("", DNSDomainToString("\x06"));
}
+TEST_F(DNSUtilTest, IsValidDNSDomain) {
+ const char* const bad_hostnames[] = {
+ "%20%20noodles.blorg", "noo dles.blorg ", "noo dles.blorg. ",
+ "^noodles.blorg", "noodles^.blorg", "noo&dles.blorg",
+ "noodles.blorg`", "www.-noodles.blorg",
+ };
+
+ // TODO(palmer): In the future, when we can remove support for invalid names,
+ // change the calls to from |IsValidDNSDomainName| to |IsValidDNSDomain|, and
+ // remove |IsValidDNSDomainName| (defined above).
+
+ for (size_t i = 0; i < arraysize(bad_hostnames); ++i) {
+ EXPECT_FALSE(IsValidDNSDomainName(bad_hostnames[i]));
+ }
+
+ const char* const good_hostnames[] = {
+ "www.noodles.blorg", "1www.noodles.blorg", "www.2noodles.blorg",
+ "www.n--oodles.blorg", "www.noodl_es.blorg", "www.no-_odles.blorg",
+ "www_.noodles.blorg", "www.noodles.blorg.", "_privet._tcp.local",
+ };
+
+ for (size_t i = 0; i < arraysize(good_hostnames); ++i) {
+ EXPECT_TRUE(IsValidDNSDomainName(good_hostnames[i]));
+ }
+}
+
} // namespace net
« no previous file with comments | « net/dns/dns_util.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698