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

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

Issue 1227173006: New SSL metric added: Likely From Same Domain (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: resolving comments Created 5 years, 5 months 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') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/ssl/ssl_error_classification.h" 5 #include "chrome/browser/ssl/ssl_error_classification.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 origin, 52 origin,
53 cert_error, 53 cert_error,
54 *google_cert); 54 *google_cert);
55 EXPECT_TRUE(ssl_error.IsWWWSubDomainMatch()); 55 EXPECT_TRUE(ssl_error.IsWWWSubDomainMatch());
56 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens, 56 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens,
57 dns_name_tokens_google)); 57 dns_name_tokens_google));
58 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google, 58 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google,
59 host_name_tokens)); 59 host_name_tokens));
60 EXPECT_FALSE(ssl_error.IsSubDomainOutsideWildcard(host_name_tokens)); 60 EXPECT_FALSE(ssl_error.IsSubDomainOutsideWildcard(host_name_tokens));
61 EXPECT_FALSE(ssl_error.IsCertLikelyFromMultiTenantHosting()); 61 EXPECT_FALSE(ssl_error.IsCertLikelyFromMultiTenantHosting());
62 EXPECT_TRUE(ssl_error.IsCertLikelyFromSameDomain());
62 } 63 }
63 64
64 { 65 {
65 GURL origin("https://foo.blah.google.com"); 66 GURL origin("https://foo.blah.google.com");
66 std::string host_name = origin.host(); 67 std::string host_name = origin.host();
67 std::vector<std::string> host_name_tokens; 68 std::vector<std::string> host_name_tokens;
68 base::SplitStringDontTrim(host_name, '.', &host_name_tokens); 69 base::SplitStringDontTrim(host_name, '.', &host_name_tokens);
69 SSLErrorClassification ssl_error(contents, 70 SSLErrorClassification ssl_error(contents,
70 time, 71 time,
71 origin, 72 origin,
72 cert_error, 73 cert_error,
73 *google_cert); 74 *google_cert);
74 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch()); 75 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch());
75 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens, 76 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens,
76 dns_name_tokens_google)); 77 dns_name_tokens_google));
77 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google, 78 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google,
78 host_name_tokens)); 79 host_name_tokens));
80 EXPECT_TRUE(ssl_error.IsCertLikelyFromSameDomain());
79 } 81 }
80 82
81 { 83 {
82 GURL origin("https://foo.www.google.com"); 84 GURL origin("https://foo.www.google.com");
83 std::string host_name = origin.host(); 85 std::string host_name = origin.host();
84 std::vector<std::string> host_name_tokens; 86 std::vector<std::string> host_name_tokens;
85 base::SplitStringDontTrim(host_name, '.', &host_name_tokens); 87 base::SplitStringDontTrim(host_name, '.', &host_name_tokens);
86 SSLErrorClassification ssl_error(contents, 88 SSLErrorClassification ssl_error(contents,
87 time, 89 time,
88 origin, 90 origin,
89 cert_error, 91 cert_error,
90 *google_cert); 92 *google_cert);
91 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch()); 93 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch());
92 EXPECT_TRUE(ssl_error.NameUnderAnyNames(host_name_tokens, 94 EXPECT_TRUE(ssl_error.NameUnderAnyNames(host_name_tokens,
93 dns_name_tokens_google)); 95 dns_name_tokens_google));
94 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google, 96 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google,
95 host_name_tokens)); 97 host_name_tokens));
98 EXPECT_TRUE(ssl_error.IsCertLikelyFromSameDomain());
96 } 99 }
97 100
98 { 101 {
99 GURL origin("https://www.google.com.foo"); 102 GURL origin("https://www.google.com.foo");
100 std::string host_name = origin.host(); 103 std::string host_name = origin.host();
101 std::vector<std::string> host_name_tokens; 104 std::vector<std::string> host_name_tokens;
102 base::SplitStringDontTrim(host_name, '.', &host_name_tokens); 105 base::SplitStringDontTrim(host_name, '.', &host_name_tokens);
103 SSLErrorClassification ssl_error(contents, 106 SSLErrorClassification ssl_error(contents,
104 time, 107 time,
105 origin, 108 origin,
106 cert_error, 109 cert_error,
107 *google_cert); 110 *google_cert);
108 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch()); 111 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch());
109 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens, 112 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens,
110 dns_name_tokens_google)); 113 dns_name_tokens_google));
111 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google, 114 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google,
112 host_name_tokens)); 115 host_name_tokens));
116 EXPECT_FALSE(ssl_error.IsCertLikelyFromSameDomain());
113 } 117 }
114 118
115 { 119 {
116 GURL origin("https://www.foogoogle.com."); 120 GURL origin("https://www.foogoogle.com.");
117 std::string host_name = origin.host(); 121 std::string host_name = origin.host();
118 std::vector<std::string> host_name_tokens; 122 std::vector<std::string> host_name_tokens;
119 base::SplitStringDontTrim(host_name, '.', &host_name_tokens); 123 base::SplitStringDontTrim(host_name, '.', &host_name_tokens);
120 SSLErrorClassification ssl_error(contents, 124 SSLErrorClassification ssl_error(contents,
121 time, 125 time,
122 origin, 126 origin,
123 cert_error, 127 cert_error,
124 *google_cert); 128 *google_cert);
125 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch()); 129 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch());
126 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens, 130 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens,
127 dns_name_tokens_google)); 131 dns_name_tokens_google));
128 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google, 132 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google,
129 host_name_tokens)); 133 host_name_tokens));
134 EXPECT_FALSE(ssl_error.IsCertLikelyFromSameDomain());
130 } 135 }
131 136
132 scoped_refptr<net::X509Certificate> webkit_cert( 137 scoped_refptr<net::X509Certificate> webkit_cert(
133 net::X509Certificate::CreateFromBytes( 138 net::X509Certificate::CreateFromBytes(
134 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); 139 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)));
135 ASSERT_NE(static_cast<net::X509Certificate*>(NULL), webkit_cert.get()); 140 ASSERT_NE(static_cast<net::X509Certificate*>(NULL), webkit_cert.get());
136 std::vector<std::string> dns_names_webkit; 141 std::vector<std::string> dns_names_webkit;
137 dns_names_webkit.push_back("webkit"); 142 dns_names_webkit.push_back("webkit");
138 dns_names_webkit.push_back("org"); 143 dns_names_webkit.push_back("org");
139 std::vector<std::vector<std::string>> dns_name_tokens_webkit; 144 std::vector<std::vector<std::string>> dns_name_tokens_webkit;
140 dns_name_tokens_webkit.push_back(dns_names_webkit); 145 dns_name_tokens_webkit.push_back(dns_names_webkit);
141 { 146 {
142 GURL origin("https://a.b.webkit.org"); 147 GURL origin("https://a.b.webkit.org");
143 std::string host_name = origin.host(); 148 std::string host_name = origin.host();
144 std::vector<std::string> host_name_tokens; 149 std::vector<std::string> host_name_tokens;
145 base::SplitStringDontTrim(host_name, '.', &host_name_tokens); 150 base::SplitStringDontTrim(host_name, '.', &host_name_tokens);
146 SSLErrorClassification ssl_error(contents, 151 SSLErrorClassification ssl_error(contents,
147 time, 152 time,
148 origin, 153 origin,
149 cert_error, 154 cert_error,
150 *webkit_cert); 155 *webkit_cert);
151 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch()); 156 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch());
152 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens, 157 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens,
153 dns_name_tokens_webkit)); 158 dns_name_tokens_webkit));
154 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_webkit, 159 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_webkit,
155 host_name_tokens)); 160 host_name_tokens));
156 EXPECT_TRUE(ssl_error.IsSubDomainOutsideWildcard(host_name_tokens)); 161 EXPECT_TRUE(ssl_error.IsSubDomainOutsideWildcard(host_name_tokens));
157 EXPECT_FALSE(ssl_error.IsCertLikelyFromMultiTenantHosting()); 162 EXPECT_FALSE(ssl_error.IsCertLikelyFromMultiTenantHosting());
163 EXPECT_TRUE(ssl_error.IsCertLikelyFromSameDomain());
158 } 164 }
159 } 165 }
160 166
161 TEST_F(SSLErrorClassificationTest, TestHostNameHasKnownTLD) { 167 TEST_F(SSLErrorClassificationTest, TestHostNameHasKnownTLD) {
162 EXPECT_TRUE(SSLErrorClassification::IsHostNameKnownTLD("www.google.com")); 168 EXPECT_TRUE(SSLErrorClassification::IsHostNameKnownTLD("www.google.com"));
163 EXPECT_TRUE(SSLErrorClassification::IsHostNameKnownTLD("b.appspot.com")); 169 EXPECT_TRUE(SSLErrorClassification::IsHostNameKnownTLD("b.appspot.com"));
164 EXPECT_FALSE(SSLErrorClassification::IsHostNameKnownTLD("a.private")); 170 EXPECT_FALSE(SSLErrorClassification::IsHostNameKnownTLD("a.private"));
165 } 171 }
166 172
167 TEST_F(SSLErrorClassificationTest, TestPrivateURL) { 173 TEST_F(SSLErrorClassificationTest, TestPrivateURL) {
168 EXPECT_FALSE(SSLErrorClassification::IsHostnameNonUniqueOrDotless( 174 EXPECT_FALSE(SSLErrorClassification::IsHostnameNonUniqueOrDotless(
169 "www.foogoogle.com.")); 175 "www.foogoogle.com."));
170 EXPECT_TRUE(SSLErrorClassification::IsHostnameNonUniqueOrDotless("go")); 176 EXPECT_TRUE(SSLErrorClassification::IsHostnameNonUniqueOrDotless("go"));
171 EXPECT_TRUE( 177 EXPECT_TRUE(
172 SSLErrorClassification::IsHostnameNonUniqueOrDotless("172.17.108.108")); 178 SSLErrorClassification::IsHostnameNonUniqueOrDotless("172.17.108.108"));
173 EXPECT_TRUE(SSLErrorClassification::IsHostnameNonUniqueOrDotless("foo.blah")); 179 EXPECT_TRUE(SSLErrorClassification::IsHostnameNonUniqueOrDotless("foo.blah"));
174 } 180 }
OLDNEW
« no previous file with comments | « chrome/browser/ssl/ssl_error_classification.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698