forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrypto_utils_test.cc
49 lines (41 loc) · 1.44 KB
/
crypto_utils_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/quic/crypto/crypto_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
namespace test {
namespace {
TEST(CryptoUtilsTest, IsValidSNI) {
// IP as SNI.
EXPECT_FALSE(CryptoUtils::IsValidSNI("192.168.0.1"));
// SNI without any dot.
EXPECT_FALSE(CryptoUtils::IsValidSNI("somedomain"));
// Invalid RFC2396 hostname
// TODO(rtenneti): Support RFC2396 hostname.
// EXPECT_FALSE(CryptoUtils::IsValidSNI("some_domain.com"));
// An empty string must be invalid otherwise the QUIC client will try sending
// it.
EXPECT_FALSE(CryptoUtils::IsValidSNI(""));
// Valid SNI
EXPECT_TRUE(CryptoUtils::IsValidSNI("test.google.com"));
}
TEST(CryptoUtilsTest, NormalizeHostname) {
struct {
const char *input, *expected;
} tests[] = {
{ "www.google.com", "www.google.com", },
{ "WWW.GOOGLE.COM", "www.google.com", },
{ "www.google.com.", "www.google.com", },
{ "www.google.COM.", "www.google.com", },
{ "www.google.com..", "www.google.com", },
{ "www.google.com........", "www.google.com", },
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
EXPECT_EQ(std::string(tests[i].expected),
CryptoUtils::NormalizeHostname(tests[i].input));
}
}
} // namespace
} // namespace test
} // namespace net