Home | History | Annotate | Download | only in crypto
      1 // Copyright (c) 2013 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/quic/crypto/crypto_utils.h"
      6 
      7 #include "testing/gtest/include/gtest/gtest.h"
      8 
      9 namespace net {
     10 namespace test {
     11 namespace {
     12 
     13 TEST(CryptoUtilsTest, IsValidSNI) {
     14   // IP as SNI.
     15   EXPECT_FALSE(CryptoUtils::IsValidSNI("192.168.0.1"));
     16   // SNI without any dot.
     17   EXPECT_FALSE(CryptoUtils::IsValidSNI("somedomain"));
     18   // Invalid RFC2396 hostname
     19   // TODO(rtenneti): Support RFC2396 hostname.
     20   // EXPECT_FALSE(CryptoUtils::IsValidSNI("some_domain.com"));
     21   // An empty string must be invalid otherwise the QUIC client will try sending
     22   // it.
     23   EXPECT_FALSE(CryptoUtils::IsValidSNI(""));
     24 
     25   // Valid SNI
     26   EXPECT_TRUE(CryptoUtils::IsValidSNI("test.google.com"));
     27 }
     28 
     29 TEST(CryptoUtilsTest, NormalizeHostname) {
     30   struct {
     31     const char *input, *expected;
     32   } tests[] = {
     33     { "www.google.com", "www.google.com", },
     34     { "WWW.GOOGLE.COM", "www.google.com", },
     35     { "www.google.com.", "www.google.com", },
     36     { "www.google.COM.", "www.google.com", },
     37     { "www.google.com..", "www.google.com", },
     38     { "www.google.com........", "www.google.com", },
     39   };
     40 
     41   for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
     42     EXPECT_EQ(std::string(tests[i].expected),
     43               CryptoUtils::NormalizeHostname(tests[i].input));
     44   }
     45 }
     46 
     47 }  // namespace
     48 }  // namespace test
     49 }  // namespace net
     50