OLD | NEW |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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/quic/platform/api/quic_hostname_utils.h" | 5 #include "net/quic/platform/api/quic_hostname_utils.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "net/quic/platform/api/quic_test.h" |
8 | 8 |
9 using std::string; | 9 using std::string; |
10 | 10 |
11 namespace net { | 11 namespace net { |
12 namespace test { | 12 namespace test { |
13 namespace { | 13 namespace { |
14 | 14 |
15 TEST(QuicHostnameUtilsTest, IsValidSNI) { | 15 class QuicHostnameUtilsTest : public QuicTest {}; |
| 16 |
| 17 TEST_F(QuicHostnameUtilsTest, IsValidSNI) { |
16 // IP as SNI. | 18 // IP as SNI. |
17 EXPECT_FALSE(QuicHostnameUtils::IsValidSNI("192.168.0.1")); | 19 EXPECT_FALSE(QuicHostnameUtils::IsValidSNI("192.168.0.1")); |
18 // SNI without any dot. | 20 // SNI without any dot. |
19 EXPECT_FALSE(QuicHostnameUtils::IsValidSNI("somedomain")); | 21 EXPECT_FALSE(QuicHostnameUtils::IsValidSNI("somedomain")); |
20 // Invalid by RFC2396 but unfortunately domains of this form exist. | 22 // Invalid by RFC2396 but unfortunately domains of this form exist. |
21 EXPECT_TRUE(QuicHostnameUtils::IsValidSNI("some_domain.com")); | 23 EXPECT_TRUE(QuicHostnameUtils::IsValidSNI("some_domain.com")); |
22 // An empty string must be invalid otherwise the QUIC client will try sending | 24 // An empty string must be invalid otherwise the QUIC client will try sending |
23 // it. | 25 // it. |
24 EXPECT_FALSE(QuicHostnameUtils::IsValidSNI("")); | 26 EXPECT_FALSE(QuicHostnameUtils::IsValidSNI("")); |
25 | 27 |
26 // Valid SNI | 28 // Valid SNI |
27 EXPECT_TRUE(QuicHostnameUtils::IsValidSNI("test.google.com")); | 29 EXPECT_TRUE(QuicHostnameUtils::IsValidSNI("test.google.com")); |
28 } | 30 } |
29 | 31 |
30 TEST(QuicHostnameUtilsTest, NormalizeHostname) { | 32 TEST_F(QuicHostnameUtilsTest, NormalizeHostname) { |
31 struct { | 33 struct { |
32 const char *input, *expected; | 34 const char *input, *expected; |
33 } tests[] = { | 35 } tests[] = { |
34 { | 36 { |
35 "www.google.com", "www.google.com", | 37 "www.google.com", "www.google.com", |
36 }, | 38 }, |
37 { | 39 { |
38 "WWW.GOOGLE.COM", "www.google.com", | 40 "WWW.GOOGLE.COM", "www.google.com", |
39 }, | 41 }, |
40 { | 42 { |
(...skipping 14 matching lines...) Expand all Loading... |
55 char buf[256]; | 57 char buf[256]; |
56 snprintf(buf, sizeof(buf), "%s", tests[i].input); | 58 snprintf(buf, sizeof(buf), "%s", tests[i].input); |
57 EXPECT_EQ(string(tests[i].expected), | 59 EXPECT_EQ(string(tests[i].expected), |
58 QuicHostnameUtils::NormalizeHostname(buf)); | 60 QuicHostnameUtils::NormalizeHostname(buf)); |
59 } | 61 } |
60 } | 62 } |
61 | 63 |
62 } // namespace | 64 } // namespace |
63 } // namespace test | 65 } // namespace test |
64 } // namespace net | 66 } // namespace net |
OLD | NEW |