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

Unified Diff: net/dns/dns_util_unittest.cc

Issue 2739203003: Measure how often DNS hostnames aren't in preferred name form. (Closed)
Patch Set: Change the behavior to reporting via UMA; add documentation. 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
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..0d9079950e12e0f1f36c6a1095d4d6b37e3d0ab9 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;
+ } else {
Ryan Sleevi 2017/03/22 00:16:07 https://chromium.googlesource.com/chromium/src/+/m
palmer 2017/03/22 01:03:34 Done.
+ continue;
+ }
+ }
+
+ if (!net::IsValidLabelCharacter(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

Powered by Google App Engine
This is Rietveld 408576698