Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: chrome/browser/ssl/ssl_error_classification_unittest.cc

Issue 1355413003: Move error classification into the ssl_errors component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove size_t / int mixing Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ssl/ssl_error_classification.cc ('k') | chrome/browser/ssl/ssl_error_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 "chrome/browser/ssl/ssl_error_classification.h"
6
7 #include "base/files/file_path.h"
8 #include "base/strings/string_split.h"
9 #include "base/time/time.h"
10 #include "net/base/net_errors.h"
11 #include "net/base/test_data_directory.h"
12 #include "net/cert/x509_cert_types.h"
13 #include "net/cert/x509_certificate.h"
14 #include "net/test/cert_test_util.h"
15 #include "net/test/test_certificate_data.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "url/gurl.h"
18
19 using base::Time;
20
21 class SSLErrorClassificationTest : public testing::Test {};
22
23 TEST_F(SSLErrorClassificationTest, TestNameMismatch) {
24 scoped_refptr<net::X509Certificate> google_cert(
25 net::X509Certificate::CreateFromBytes(
26 reinterpret_cast<const char*>(google_der), sizeof(google_der)));
27 ASSERT_NE(static_cast<net::X509Certificate*>(NULL), google_cert.get());
28 base::Time time = base::Time::NowFromSystemTime();
29 std::vector<std::string> dns_names_google;
30 dns_names_google.push_back("www");
31 dns_names_google.push_back("google");
32 dns_names_google.push_back("com");
33 std::vector<std::vector<std::string>> dns_name_tokens_google;
34 dns_name_tokens_google.push_back(dns_names_google);
35 int cert_error = net::ERR_CERT_COMMON_NAME_INVALID;
36 {
37 GURL origin("https://google.com");
38 std::vector<std::string> host_name_tokens = base::SplitString(
39 origin.host(), ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
40 SSLErrorClassification ssl_error(time, origin, cert_error, *google_cert);
41 EXPECT_TRUE(ssl_error.IsWWWSubDomainMatch());
42 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens,
43 dns_name_tokens_google));
44 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google,
45 host_name_tokens));
46 EXPECT_FALSE(ssl_error.IsSubDomainOutsideWildcard(host_name_tokens));
47 EXPECT_FALSE(ssl_error.IsCertLikelyFromMultiTenantHosting());
48 EXPECT_TRUE(ssl_error.IsCertLikelyFromSameDomain());
49 }
50
51 {
52 GURL origin("https://foo.blah.google.com");
53 std::vector<std::string> host_name_tokens = base::SplitString(
54 origin.host(), ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
55 SSLErrorClassification ssl_error(time, origin, cert_error, *google_cert);
56 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch());
57 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens,
58 dns_name_tokens_google));
59 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google,
60 host_name_tokens));
61 EXPECT_TRUE(ssl_error.IsCertLikelyFromSameDomain());
62 }
63
64 {
65 GURL origin("https://foo.www.google.com");
66 std::vector<std::string> host_name_tokens = base::SplitString(
67 origin.host(), ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
68 SSLErrorClassification ssl_error(time, origin, cert_error, *google_cert);
69 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch());
70 EXPECT_TRUE(ssl_error.NameUnderAnyNames(host_name_tokens,
71 dns_name_tokens_google));
72 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google,
73 host_name_tokens));
74 EXPECT_TRUE(ssl_error.IsCertLikelyFromSameDomain());
75 }
76
77 {
78 GURL origin("https://www.google.com.foo");
79 std::vector<std::string> host_name_tokens = base::SplitString(
80 origin.host(), ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
81 SSLErrorClassification ssl_error(time, origin, cert_error, *google_cert);
82 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch());
83 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens,
84 dns_name_tokens_google));
85 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google,
86 host_name_tokens));
87 EXPECT_FALSE(ssl_error.IsCertLikelyFromSameDomain());
88 }
89
90 {
91 GURL origin("https://www.foogoogle.com.");
92 std::vector<std::string> host_name_tokens = base::SplitString(
93 origin.host(), ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
94 SSLErrorClassification ssl_error(time, origin, cert_error, *google_cert);
95 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch());
96 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens,
97 dns_name_tokens_google));
98 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google,
99 host_name_tokens));
100 EXPECT_FALSE(ssl_error.IsCertLikelyFromSameDomain());
101 }
102
103 scoped_refptr<net::X509Certificate> webkit_cert(
104 net::X509Certificate::CreateFromBytes(
105 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)));
106 ASSERT_NE(static_cast<net::X509Certificate*>(NULL), webkit_cert.get());
107 std::vector<std::string> dns_names_webkit;
108 dns_names_webkit.push_back("webkit");
109 dns_names_webkit.push_back("org");
110 std::vector<std::vector<std::string>> dns_name_tokens_webkit;
111 dns_name_tokens_webkit.push_back(dns_names_webkit);
112 {
113 GURL origin("https://a.b.webkit.org");
114 std::vector<std::string> host_name_tokens = base::SplitString(
115 origin.host(), ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
116 SSLErrorClassification ssl_error(time, origin, cert_error, *webkit_cert);
117 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch());
118 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens,
119 dns_name_tokens_webkit));
120 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_webkit,
121 host_name_tokens));
122 EXPECT_TRUE(ssl_error.IsSubDomainOutsideWildcard(host_name_tokens));
123 EXPECT_FALSE(ssl_error.IsCertLikelyFromMultiTenantHosting());
124 EXPECT_TRUE(ssl_error.IsCertLikelyFromSameDomain());
125 }
126 }
127
128 TEST_F(SSLErrorClassificationTest, TestHostNameHasKnownTLD) {
129 EXPECT_TRUE(SSLErrorClassification::IsHostNameKnownTLD("www.google.com"));
130 EXPECT_TRUE(SSLErrorClassification::IsHostNameKnownTLD("b.appspot.com"));
131 EXPECT_FALSE(SSLErrorClassification::IsHostNameKnownTLD("a.private"));
132 }
133
134 TEST_F(SSLErrorClassificationTest, TestPrivateURL) {
135 EXPECT_FALSE(SSLErrorClassification::IsHostnameNonUniqueOrDotless(
136 "www.foogoogle.com."));
137 EXPECT_TRUE(SSLErrorClassification::IsHostnameNonUniqueOrDotless("go"));
138 EXPECT_TRUE(
139 SSLErrorClassification::IsHostnameNonUniqueOrDotless("172.17.108.108"));
140 EXPECT_TRUE(SSLErrorClassification::IsHostnameNonUniqueOrDotless("foo.blah"));
141 }
OLDNEW
« no previous file with comments | « chrome/browser/ssl/ssl_error_classification.cc ('k') | chrome/browser/ssl/ssl_error_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698