QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/platform/api/quic_hostname_utils.h" |
| 6 | |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 7 | #include <string> |
| 8 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9 | #include "net/third_party/quiche/src/quic/platform/api/quic_arraysize.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
| 11 | |
| 12 | namespace quic { |
| 13 | namespace test { |
| 14 | namespace { |
| 15 | |
| 16 | class QuicHostnameUtilsTest : public QuicTest {}; |
| 17 | |
| 18 | TEST_F(QuicHostnameUtilsTest, IsValidSNI) { |
| 19 | // IP as SNI. |
| 20 | EXPECT_FALSE(QuicHostnameUtils::IsValidSNI("192.168.0.1")); |
| 21 | // SNI without any dot. |
| 22 | EXPECT_FALSE(QuicHostnameUtils::IsValidSNI("somedomain")); |
| 23 | // Invalid by RFC2396 but unfortunately domains of this form exist. |
| 24 | EXPECT_TRUE(QuicHostnameUtils::IsValidSNI("some_domain.com")); |
| 25 | // An empty string must be invalid otherwise the QUIC client will try sending |
| 26 | // it. |
| 27 | EXPECT_FALSE(QuicHostnameUtils::IsValidSNI("")); |
| 28 | |
| 29 | // Valid SNI |
| 30 | EXPECT_TRUE(QuicHostnameUtils::IsValidSNI("test.google.com")); |
| 31 | } |
| 32 | |
| 33 | TEST_F(QuicHostnameUtilsTest, NormalizeHostname) { |
| 34 | // clang-format off |
| 35 | struct { |
| 36 | const char *input, *expected; |
| 37 | } tests[] = { |
| 38 | { |
| 39 | "www.google.com", |
| 40 | "www.google.com", |
| 41 | }, |
| 42 | { |
| 43 | "WWW.GOOGLE.COM", |
| 44 | "www.google.com", |
| 45 | }, |
| 46 | { |
| 47 | "www.google.com.", |
| 48 | "www.google.com", |
| 49 | }, |
| 50 | { |
| 51 | "www.google.COM.", |
| 52 | "www.google.com", |
| 53 | }, |
| 54 | { |
| 55 | "www.google.com..", |
| 56 | "www.google.com", |
| 57 | }, |
| 58 | { |
| 59 | "www.google.com........", |
| 60 | "www.google.com", |
| 61 | }, |
| 62 | { |
| 63 | "", |
| 64 | "", |
| 65 | }, |
| 66 | { |
| 67 | ".", |
| 68 | "", |
| 69 | }, |
| 70 | { |
| 71 | "........", |
| 72 | "", |
| 73 | }, |
| 74 | { |
| 75 | "\xe5\x85\x89.google.com", |
| 76 | "xn--54q.google.com", |
| 77 | }, |
| 78 | }; |
| 79 | // clang-format on |
| 80 | |
| 81 | for (size_t i = 0; i < QUIC_ARRAYSIZE(tests); ++i) { |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 82 | EXPECT_EQ(std::string(tests[i].expected), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 83 | QuicHostnameUtils::NormalizeHostname(tests[i].input)); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | } // namespace |
| 88 | } // namespace test |
| 89 | } // namespace quic |