| 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/base/dns_util.h" | 5 #include "net/base/dns_util.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 7 |
| 8 namespace net { | 8 namespace net { |
| 9 | 9 |
| 10 class DNSUtilTest : public testing::Test { | 10 class DNSUtilTest : public testing::Test { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 EXPECT_FALSE(DNSDomainFromDot("..", &out)); | 24 EXPECT_FALSE(DNSDomainFromDot("..", &out)); |
| 25 | 25 |
| 26 EXPECT_TRUE(DNSDomainFromDot("com", &out)); | 26 EXPECT_TRUE(DNSDomainFromDot("com", &out)); |
| 27 EXPECT_EQ(out, IncludeNUL("\003com")); | 27 EXPECT_EQ(out, IncludeNUL("\003com")); |
| 28 EXPECT_TRUE(DNSDomainFromDot("google.com", &out)); | 28 EXPECT_TRUE(DNSDomainFromDot("google.com", &out)); |
| 29 EXPECT_EQ(out, IncludeNUL("\x006google\003com")); | 29 EXPECT_EQ(out, IncludeNUL("\x006google\003com")); |
| 30 EXPECT_TRUE(DNSDomainFromDot("www.google.com", &out)); | 30 EXPECT_TRUE(DNSDomainFromDot("www.google.com", &out)); |
| 31 EXPECT_EQ(out, IncludeNUL("\003www\006google\003com")); | 31 EXPECT_EQ(out, IncludeNUL("\003www\006google\003com")); |
| 32 | 32 |
| 33 // Label is 63 chars: still valid | 33 // Label is 63 chars: still valid |
| 34 EXPECT_TRUE(DNSDomainFromDot("123456789a123456789a123456789a123456789a12345678
9a123456789a123", &out)); | 34 EXPECT_TRUE(DNSDomainFromDot("z23456789a123456789a123456789a123456789a12345678
9a123456789a123", &out)); |
| 35 EXPECT_EQ(out, IncludeNUL("\077123456789a123456789a123456789a123456789a1234567
89a123456789a123")); | 35 EXPECT_EQ(out, IncludeNUL("\077z23456789a123456789a123456789a123456789a1234567
89a123456789a123")); |
| 36 | 36 |
| 37 // Label is too long: invalid | 37 // Label is too long: invalid |
| 38 EXPECT_FALSE(DNSDomainFromDot("123456789a123456789a123456789a123456789a1234567
89a123456789a1234", &out)); | 38 EXPECT_FALSE(DNSDomainFromDot("123456789a123456789a123456789a123456789a1234567
89a123456789a1234", &out)); |
| 39 | 39 |
| 40 // 253 characters in the name: still valid | 40 // 253 characters in the name: still valid |
| 41 EXPECT_TRUE(DNSDomainFromDot("123456789.123456789.123456789.123456789.12345678
9.123456789.123456789.123456789.123456789.123456789.123456789.123456789.12345678
9.123456789.123456789.123456789.123456789.123456789.123456789.123456789.12345678
9.123456789.123456789.123456789.123456789.123", &out)); | 41 EXPECT_TRUE(DNSDomainFromDot("abcdefghi.abcdefghi.abcdefghi.abcdefghi.abcdefgh
i.abcdefghi.abcdefghi.abcdefghi.abcdefghi.abcdefghi.abcdefghi.abcdefghi.abcdefgh
i.abcdefghi.abcdefghi.abcdefghi.abcdefghi.abcdefghi.abcdefghi.abcdefghi.abcdefgh
i.abcdefghi.abcdefghi.abcdefghi.abcdefghi.abc", &out)); |
| 42 EXPECT_EQ(out, IncludeNUL("\011123456789\011123456789\011123456789\01112345678
9\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\
011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\01
1123456789\011123456789\011123456789\011123456789\011123456789\011123456789\0111
23456789\011123456789\011123456789\003123")); | 42 EXPECT_EQ(out, IncludeNUL("\011abcdefghi\011abcdefghi\011abcdefghi\011abcdefgh
i\011abcdefghi\011abcdefghi\011abcdefghi\011abcdefghi\011abcdefghi\011abcdefghi\
011abcdefghi\011abcdefghi\011abcdefghi\011abcdefghi\011abcdefghi\011abcdefghi\01
1abcdefghi\011abcdefghi\011abcdefghi\011abcdefghi\011abcdefghi\011abcdefghi\011a
bcdefghi\011abcdefghi\011abcdefghi\003abc")); |
| 43 | 43 |
| 44 // 254 characters in the name: invalid | 44 // 254 characters in the name: invalid |
| 45 EXPECT_FALSE(DNSDomainFromDot("123456789.123456789.123456789.123456789.1234567
89.123456789.123456789.123456789.123456789.123456789.123456789.123456789.1234567
89.123456789.123456789.123456789.123456789.123456789.123456789.123456789.1234567
89.123456789.123456789.123456789.123456789.1234", &out)); | 45 EXPECT_FALSE(DNSDomainFromDot("123456789.123456789.123456789.123456789.1234567
89.123456789.123456789.123456789.123456789.123456789.123456789.123456789.1234567
89.123456789.123456789.123456789.123456789.123456789.123456789.123456789.1234567
89.123456789.123456789.123456789.123456789.1234", &out)); |
| 46 | 46 |
| 47 // Zero length labels should be dropped. | 47 // Zero length labels should be dropped. |
| 48 EXPECT_TRUE(DNSDomainFromDot("www.google.com.", &out)); | 48 EXPECT_TRUE(DNSDomainFromDot("www.google.com.", &out)); |
| 49 EXPECT_EQ(out, IncludeNUL("\003www\006google\003com")); | 49 EXPECT_EQ(out, IncludeNUL("\003www\006google\003com")); |
| 50 | 50 |
| 51 EXPECT_TRUE(DNSDomainFromDot(".google.com", &out)); | 51 EXPECT_TRUE(DNSDomainFromDot(".google.com", &out)); |
| 52 EXPECT_EQ(out, IncludeNUL("\006google\003com")); | 52 EXPECT_EQ(out, IncludeNUL("\006google\003com")); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 64 | 64 |
| 65 // It should cope with a lack of root label. | 65 // It should cope with a lack of root label. |
| 66 EXPECT_EQ("foo.bar", DNSDomainToString("\003foo\003bar")); | 66 EXPECT_EQ("foo.bar", DNSDomainToString("\003foo\003bar")); |
| 67 | 67 |
| 68 // Invalid inputs should return an empty string. | 68 // Invalid inputs should return an empty string. |
| 69 EXPECT_EQ("", DNSDomainToString(IncludeNUL("\x80"))); | 69 EXPECT_EQ("", DNSDomainToString(IncludeNUL("\x80"))); |
| 70 EXPECT_EQ("", DNSDomainToString("\x06")); | 70 EXPECT_EQ("", DNSDomainToString("\x06")); |
| 71 } | 71 } |
| 72 | 72 |
| 73 } // namespace net | 73 } // namespace net |
| OLD | NEW |