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

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

Issue 1240183002: Update SplitString calls in chrome. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 26 matching lines...) Expand all
37 std::vector<std::string> dns_names_google; 37 std::vector<std::string> dns_names_google;
38 dns_names_google.push_back("www"); 38 dns_names_google.push_back("www");
39 dns_names_google.push_back("google"); 39 dns_names_google.push_back("google");
40 dns_names_google.push_back("com"); 40 dns_names_google.push_back("com");
41 std::vector<std::vector<std::string>> dns_name_tokens_google; 41 std::vector<std::vector<std::string>> dns_name_tokens_google;
42 dns_name_tokens_google.push_back(dns_names_google); 42 dns_name_tokens_google.push_back(dns_names_google);
43 int cert_error = net::ERR_CERT_COMMON_NAME_INVALID; 43 int cert_error = net::ERR_CERT_COMMON_NAME_INVALID;
44 WebContents* contents = web_contents(); 44 WebContents* contents = web_contents();
45 { 45 {
46 GURL origin("https://google.com"); 46 GURL origin("https://google.com");
47 std::string host_name = origin.host(); 47 std::vector<std::string> host_name_tokens = base::SplitString(
48 std::vector<std::string> host_name_tokens; 48 origin.host(), ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
49 base::SplitStringDontTrim(host_name, '.', &host_name_tokens);
50 SSLErrorClassification ssl_error(contents, 49 SSLErrorClassification ssl_error(contents,
51 time, 50 time,
52 origin, 51 origin,
53 cert_error, 52 cert_error,
54 *google_cert); 53 *google_cert);
55 EXPECT_TRUE(ssl_error.IsWWWSubDomainMatch()); 54 EXPECT_TRUE(ssl_error.IsWWWSubDomainMatch());
56 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens, 55 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens,
57 dns_name_tokens_google)); 56 dns_name_tokens_google));
58 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google, 57 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google,
59 host_name_tokens)); 58 host_name_tokens));
60 EXPECT_FALSE(ssl_error.IsSubDomainOutsideWildcard(host_name_tokens)); 59 EXPECT_FALSE(ssl_error.IsSubDomainOutsideWildcard(host_name_tokens));
61 EXPECT_FALSE(ssl_error.IsCertLikelyFromMultiTenantHosting()); 60 EXPECT_FALSE(ssl_error.IsCertLikelyFromMultiTenantHosting());
62 } 61 }
63 62
64 { 63 {
65 GURL origin("https://foo.blah.google.com"); 64 GURL origin("https://foo.blah.google.com");
66 std::string host_name = origin.host(); 65 std::vector<std::string> host_name_tokens = base::SplitString(
67 std::vector<std::string> host_name_tokens; 66 origin.host(), ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
68 base::SplitStringDontTrim(host_name, '.', &host_name_tokens);
69 SSLErrorClassification ssl_error(contents, 67 SSLErrorClassification ssl_error(contents,
70 time, 68 time,
71 origin, 69 origin,
72 cert_error, 70 cert_error,
73 *google_cert); 71 *google_cert);
74 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch()); 72 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch());
75 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens, 73 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens,
76 dns_name_tokens_google)); 74 dns_name_tokens_google));
77 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google, 75 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google,
78 host_name_tokens)); 76 host_name_tokens));
79 } 77 }
80 78
81 { 79 {
82 GURL origin("https://foo.www.google.com"); 80 GURL origin("https://foo.www.google.com");
83 std::string host_name = origin.host(); 81 std::vector<std::string> host_name_tokens = base::SplitString(
84 std::vector<std::string> host_name_tokens; 82 origin.host(), ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
85 base::SplitStringDontTrim(host_name, '.', &host_name_tokens);
86 SSLErrorClassification ssl_error(contents, 83 SSLErrorClassification ssl_error(contents,
87 time, 84 time,
88 origin, 85 origin,
89 cert_error, 86 cert_error,
90 *google_cert); 87 *google_cert);
91 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch()); 88 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch());
92 EXPECT_TRUE(ssl_error.NameUnderAnyNames(host_name_tokens, 89 EXPECT_TRUE(ssl_error.NameUnderAnyNames(host_name_tokens,
93 dns_name_tokens_google)); 90 dns_name_tokens_google));
94 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google, 91 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google,
95 host_name_tokens)); 92 host_name_tokens));
96 } 93 }
97 94
98 { 95 {
99 GURL origin("https://www.google.com.foo"); 96 GURL origin("https://www.google.com.foo");
100 std::string host_name = origin.host(); 97 std::vector<std::string> host_name_tokens = base::SplitString(
101 std::vector<std::string> host_name_tokens; 98 origin.host(), ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
102 base::SplitStringDontTrim(host_name, '.', &host_name_tokens);
103 SSLErrorClassification ssl_error(contents, 99 SSLErrorClassification ssl_error(contents,
104 time, 100 time,
105 origin, 101 origin,
106 cert_error, 102 cert_error,
107 *google_cert); 103 *google_cert);
108 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch()); 104 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch());
109 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens, 105 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens,
110 dns_name_tokens_google)); 106 dns_name_tokens_google));
111 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google, 107 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google,
112 host_name_tokens)); 108 host_name_tokens));
113 } 109 }
114 110
115 { 111 {
116 GURL origin("https://www.foogoogle.com."); 112 GURL origin("https://www.foogoogle.com.");
117 std::string host_name = origin.host(); 113 std::vector<std::string> host_name_tokens = base::SplitString(
118 std::vector<std::string> host_name_tokens; 114 origin.host(), ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
119 base::SplitStringDontTrim(host_name, '.', &host_name_tokens);
120 SSLErrorClassification ssl_error(contents, 115 SSLErrorClassification ssl_error(contents,
121 time, 116 time,
122 origin, 117 origin,
123 cert_error, 118 cert_error,
124 *google_cert); 119 *google_cert);
125 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch()); 120 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch());
126 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens, 121 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens,
127 dns_name_tokens_google)); 122 dns_name_tokens_google));
128 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google, 123 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_google,
129 host_name_tokens)); 124 host_name_tokens));
130 } 125 }
131 126
132 scoped_refptr<net::X509Certificate> webkit_cert( 127 scoped_refptr<net::X509Certificate> webkit_cert(
133 net::X509Certificate::CreateFromBytes( 128 net::X509Certificate::CreateFromBytes(
134 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der))); 129 reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der)));
135 ASSERT_NE(static_cast<net::X509Certificate*>(NULL), webkit_cert.get()); 130 ASSERT_NE(static_cast<net::X509Certificate*>(NULL), webkit_cert.get());
136 std::vector<std::string> dns_names_webkit; 131 std::vector<std::string> dns_names_webkit;
137 dns_names_webkit.push_back("webkit"); 132 dns_names_webkit.push_back("webkit");
138 dns_names_webkit.push_back("org"); 133 dns_names_webkit.push_back("org");
139 std::vector<std::vector<std::string>> dns_name_tokens_webkit; 134 std::vector<std::vector<std::string>> dns_name_tokens_webkit;
140 dns_name_tokens_webkit.push_back(dns_names_webkit); 135 dns_name_tokens_webkit.push_back(dns_names_webkit);
141 { 136 {
142 GURL origin("https://a.b.webkit.org"); 137 GURL origin("https://a.b.webkit.org");
143 std::string host_name = origin.host(); 138 std::vector<std::string> host_name_tokens = base::SplitString(
144 std::vector<std::string> host_name_tokens; 139 origin.host(), ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
145 base::SplitStringDontTrim(host_name, '.', &host_name_tokens);
146 SSLErrorClassification ssl_error(contents, 140 SSLErrorClassification ssl_error(contents,
147 time, 141 time,
148 origin, 142 origin,
149 cert_error, 143 cert_error,
150 *webkit_cert); 144 *webkit_cert);
151 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch()); 145 EXPECT_FALSE(ssl_error.IsWWWSubDomainMatch());
152 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens, 146 EXPECT_FALSE(ssl_error.NameUnderAnyNames(host_name_tokens,
153 dns_name_tokens_webkit)); 147 dns_name_tokens_webkit));
154 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_webkit, 148 EXPECT_FALSE(ssl_error.AnyNamesUnderName(dns_name_tokens_webkit,
155 host_name_tokens)); 149 host_name_tokens));
156 EXPECT_TRUE(ssl_error.IsSubDomainOutsideWildcard(host_name_tokens)); 150 EXPECT_TRUE(ssl_error.IsSubDomainOutsideWildcard(host_name_tokens));
157 EXPECT_FALSE(ssl_error.IsCertLikelyFromMultiTenantHosting()); 151 EXPECT_FALSE(ssl_error.IsCertLikelyFromMultiTenantHosting());
158 } 152 }
159 } 153 }
160 154
161 TEST_F(SSLErrorClassificationTest, TestHostNameHasKnownTLD) { 155 TEST_F(SSLErrorClassificationTest, TestHostNameHasKnownTLD) {
162 EXPECT_TRUE(SSLErrorClassification::IsHostNameKnownTLD("www.google.com")); 156 EXPECT_TRUE(SSLErrorClassification::IsHostNameKnownTLD("www.google.com"));
163 EXPECT_TRUE(SSLErrorClassification::IsHostNameKnownTLD("b.appspot.com")); 157 EXPECT_TRUE(SSLErrorClassification::IsHostNameKnownTLD("b.appspot.com"));
164 EXPECT_FALSE(SSLErrorClassification::IsHostNameKnownTLD("a.private")); 158 EXPECT_FALSE(SSLErrorClassification::IsHostNameKnownTLD("a.private"));
165 } 159 }
166 160
167 TEST_F(SSLErrorClassificationTest, TestPrivateURL) { 161 TEST_F(SSLErrorClassificationTest, TestPrivateURL) {
168 EXPECT_FALSE(SSLErrorClassification::IsHostnameNonUniqueOrDotless( 162 EXPECT_FALSE(SSLErrorClassification::IsHostnameNonUniqueOrDotless(
169 "www.foogoogle.com.")); 163 "www.foogoogle.com."));
170 EXPECT_TRUE(SSLErrorClassification::IsHostnameNonUniqueOrDotless("go")); 164 EXPECT_TRUE(SSLErrorClassification::IsHostnameNonUniqueOrDotless("go"));
171 EXPECT_TRUE( 165 EXPECT_TRUE(
172 SSLErrorClassification::IsHostnameNonUniqueOrDotless("172.17.108.108")); 166 SSLErrorClassification::IsHostnameNonUniqueOrDotless("172.17.108.108"));
173 EXPECT_TRUE(SSLErrorClassification::IsHostnameNonUniqueOrDotless("foo.blah")); 167 EXPECT_TRUE(SSLErrorClassification::IsHostnameNonUniqueOrDotless("foo.blah"));
174 } 168 }
OLDNEW
« no previous file with comments | « chrome/browser/ssl/ssl_error_classification.cc ('k') | chrome/browser/supervised_user/supervised_user_whitelist_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698