OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/dns/dns_util.h" | 5 #include "net/dns/dns_util.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 DNSDomainToString(IncludeNUL("\003foo\003bar\002uk"))); | 62 DNSDomainToString(IncludeNUL("\003foo\003bar\002uk"))); |
63 | 63 |
64 // It should cope with a lack of root label. | 64 // It should cope with a lack of root label. |
65 EXPECT_EQ("foo.bar", DNSDomainToString("\003foo\003bar")); | 65 EXPECT_EQ("foo.bar", DNSDomainToString("\003foo\003bar")); |
66 | 66 |
67 // Invalid inputs should return an empty string. | 67 // Invalid inputs should return an empty string. |
68 EXPECT_EQ("", DNSDomainToString(IncludeNUL("\x80"))); | 68 EXPECT_EQ("", DNSDomainToString(IncludeNUL("\x80"))); |
69 EXPECT_EQ("", DNSDomainToString("\x06")); | 69 EXPECT_EQ("", DNSDomainToString("\x06")); |
70 } | 70 } |
71 | 71 |
| 72 TEST_F(DNSUtilTest, IsValidDNSDomain) { |
| 73 const char* const bad_hostnames[] = { |
| 74 "%20%20noodles.blorg", "noo dles.blorg ", "noo dles.blorg. ", |
| 75 "^noodles.blorg", "noodles^.blorg", "noo&dles.blorg", |
| 76 "noodles.blorg`", "www._noodles.blorg", "www._noodles.-blorg", |
| 77 }; |
| 78 |
| 79 for (size_t i = 0; i < arraysize(bad_hostnames); ++i) { |
| 80 EXPECT_FALSE(IsValidDNSDomain(bad_hostnames[i])); |
| 81 } |
| 82 |
| 83 const char* const good_hostnames[] = { |
| 84 "www.noodles.blorg", "1www.noodles.blorg", "www.2noodles.blorg", |
| 85 "www.n--oodles.blorg", "www.noodl_es.blorg", "www.no-_odles.blorg", |
| 86 "www_.noodles.blorg", "www.noodles.blorg.", |
| 87 }; |
| 88 |
| 89 for (size_t i = 0; i < arraysize(good_hostnames); ++i) { |
| 90 EXPECT_TRUE(IsValidDNSDomain(good_hostnames[i])); |
| 91 } |
| 92 } |
| 93 |
72 } // namespace net | 94 } // namespace net |
OLD | NEW |