OLD | NEW |
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 <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/test/simple_test_clock.h" | 9 #include "base/test/simple_test_clock.h" |
10 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 10 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // QueryPolicy unit tests the expected behavior of calling QueryPolicy on the | 55 // QueryPolicy unit tests the expected behavior of calling QueryPolicy on the |
56 // SSLHostStateDelegate class after various SSL cert decisions have been made. | 56 // SSLHostStateDelegate class after various SSL cert decisions have been made. |
57 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, QueryPolicy) { | 57 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, QueryPolicy) { |
58 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); | 58 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); |
59 content::WebContents* tab = | 59 content::WebContents* tab = |
60 browser()->tab_strip_model()->GetActiveWebContents(); | 60 browser()->tab_strip_model()->GetActiveWebContents(); |
61 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 61 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
62 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); | 62 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); |
63 bool unused_value; | 63 bool unused_value; |
64 | 64 |
65 // Verifying that all three of the certs we will be looking at are unknown | 65 // Verifying that all three of the certs we will be looking at are denied |
66 // before any action has been taken. | 66 // before any action has been taken. |
67 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 67 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
68 state->QueryPolicy(kWWWGoogleHost, | 68 state->QueryPolicy(kWWWGoogleHost, |
69 google_cert.get(), | 69 google_cert.get(), |
70 net::CERT_STATUS_DATE_INVALID, | 70 net::CERT_STATUS_DATE_INVALID, |
71 &unused_value)); | 71 &unused_value)); |
72 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 72 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
73 state->QueryPolicy(kGoogleHost, | 73 state->QueryPolicy(kGoogleHost, |
74 google_cert.get(), | 74 google_cert.get(), |
75 net::CERT_STATUS_DATE_INVALID, | 75 net::CERT_STATUS_DATE_INVALID, |
76 &unused_value)); | 76 &unused_value)); |
77 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 77 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
78 state->QueryPolicy(kExampleHost, | 78 state->QueryPolicy(kExampleHost, |
79 google_cert.get(), | 79 google_cert.get(), |
80 net::CERT_STATUS_DATE_INVALID, | 80 net::CERT_STATUS_DATE_INVALID, |
81 &unused_value)); | 81 &unused_value)); |
82 | 82 |
83 // Simulate a user decision to allow an invalid certificate exception for | 83 // Simulate a user decision to allow an invalid certificate exception for |
84 // kWWWGoogleHost. | 84 // kWWWGoogleHost. |
85 state->AllowCert( | 85 state->AllowCert( |
86 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 86 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
87 | 87 |
88 // Verify that only kWWWGoogleHost is allowed and that the other two certs | 88 // Verify that only kWWWGoogleHost is allowed and that the other two certs |
89 // being tested still have no decision associated with them. | 89 // being tested still are denied. |
90 EXPECT_EQ(net::CertPolicy::ALLOWED, | 90 EXPECT_EQ(content::SSLHostStateDelegate::ALLOWED, |
91 state->QueryPolicy(kWWWGoogleHost, | 91 state->QueryPolicy(kWWWGoogleHost, |
92 google_cert.get(), | 92 google_cert.get(), |
93 net::CERT_STATUS_DATE_INVALID, | 93 net::CERT_STATUS_DATE_INVALID, |
94 &unused_value)); | 94 &unused_value)); |
95 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 95 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
96 state->QueryPolicy(kGoogleHost, | 96 state->QueryPolicy(kGoogleHost, |
97 google_cert.get(), | 97 google_cert.get(), |
98 net::CERT_STATUS_DATE_INVALID, | 98 net::CERT_STATUS_DATE_INVALID, |
99 &unused_value)); | 99 &unused_value)); |
100 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 100 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
101 state->QueryPolicy(kExampleHost, | 101 state->QueryPolicy(kExampleHost, |
102 google_cert.get(), | 102 google_cert.get(), |
103 net::CERT_STATUS_DATE_INVALID, | 103 net::CERT_STATUS_DATE_INVALID, |
104 &unused_value)); | 104 &unused_value)); |
105 | 105 |
106 // Simulate a user decision to allow an invalid certificate exception for | 106 // Simulate a user decision to allow an invalid certificate exception for |
107 // kExampleHost. | 107 // kExampleHost. |
108 state->AllowCert( | 108 state->AllowCert( |
109 kExampleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 109 kExampleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
110 | 110 |
111 // Verify that both kWWWGoogleHost and kExampleHost have allow exceptions | 111 // Verify that both kWWWGoogleHost and kExampleHost have allow exceptions |
112 // while kGoogleHost still has no associated decision. | 112 // while kGoogleHost still is denied. |
113 EXPECT_EQ(net::CertPolicy::ALLOWED, | 113 EXPECT_EQ(content::SSLHostStateDelegate::ALLOWED, |
114 state->QueryPolicy(kWWWGoogleHost, | 114 state->QueryPolicy(kWWWGoogleHost, |
115 google_cert.get(), | 115 google_cert.get(), |
116 net::CERT_STATUS_DATE_INVALID, | 116 net::CERT_STATUS_DATE_INVALID, |
117 &unused_value)); | 117 &unused_value)); |
118 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 118 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
119 state->QueryPolicy(kGoogleHost, | 119 state->QueryPolicy(kGoogleHost, |
120 google_cert.get(), | 120 google_cert.get(), |
121 net::CERT_STATUS_DATE_INVALID, | 121 net::CERT_STATUS_DATE_INVALID, |
122 &unused_value)); | 122 &unused_value)); |
123 EXPECT_EQ(net::CertPolicy::ALLOWED, | 123 EXPECT_EQ(content::SSLHostStateDelegate::ALLOWED, |
124 state->QueryPolicy(kExampleHost, | 124 state->QueryPolicy(kExampleHost, |
125 google_cert.get(), | 125 google_cert.get(), |
126 net::CERT_STATUS_DATE_INVALID, | 126 net::CERT_STATUS_DATE_INVALID, |
127 &unused_value)); | |
128 | |
129 // Simulate a user decision to deny an invalid certificate for kExampleHost. | |
130 state->DenyCert( | |
131 kExampleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | |
132 | |
133 // Verify that kWWWGoogleHost is allowed and kExampleHost is denied while | |
134 // kGoogleHost still has no associated decision. | |
135 EXPECT_EQ(net::CertPolicy::ALLOWED, | |
136 state->QueryPolicy(kWWWGoogleHost, | |
137 google_cert.get(), | |
138 net::CERT_STATUS_DATE_INVALID, | |
139 &unused_value)); | |
140 EXPECT_EQ(net::CertPolicy::UNKNOWN, | |
141 state->QueryPolicy(kGoogleHost, | |
142 google_cert.get(), | |
143 net::CERT_STATUS_DATE_INVALID, | |
144 &unused_value)); | |
145 EXPECT_EQ(net::CertPolicy::DENIED, | |
146 state->QueryPolicy(kExampleHost, | |
147 google_cert.get(), | |
148 net::CERT_STATUS_DATE_INVALID, | |
149 &unused_value)); | 127 &unused_value)); |
150 } | 128 } |
151 | 129 |
152 // HasPolicyAndRevoke unit tests the expected behavior of calling | 130 // HasPolicyAndRevoke unit tests the expected behavior of calling |
153 // HasUserDecision before and after calling RevokeUserDecisions on the | 131 // HasAllowed before and after calling RevokeUserAllowExceptions on the |
154 // SSLHostStateDelegate class. | 132 // SSLHostStateDelegate class. |
155 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, HasPolicyAndRevoke) { | 133 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, HasPolicyAndRevoke) { |
156 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); | 134 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); |
157 content::WebContents* tab = | 135 content::WebContents* tab = |
158 browser()->tab_strip_model()->GetActiveWebContents(); | 136 browser()->tab_strip_model()->GetActiveWebContents(); |
159 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 137 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
160 ChromeSSLHostStateDelegate* state = | 138 ChromeSSLHostStateDelegate* state = |
161 ChromeSSLHostStateDelegateFactory::GetForProfile(profile); | 139 ChromeSSLHostStateDelegateFactory::GetForProfile(profile); |
162 bool unused_value; | 140 bool unused_value; |
163 | 141 |
164 // Simulate a user decision to allow an invalid certificate exception for | 142 // Simulate a user decision to allow an invalid certificate exception for |
165 // kWWWGoogleHost and for kExampleHost. | 143 // kWWWGoogleHost and for kExampleHost. |
166 state->AllowCert( | 144 state->AllowCert( |
167 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 145 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
168 state->AllowCert( | 146 state->AllowCert( |
169 kExampleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 147 kExampleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
170 | 148 |
171 // Verify that HasUserDecision correctly acknowledges that a user decision has | 149 // Verify that HasAllowed correctly acknowledges that a user decision has |
172 // been made about kWWWGoogleHost. Then verify that HasUserDecision correctly | 150 // been made about kWWWGoogleHost. Then verify that HasAllowed correctly |
173 // identifies that the decision has been revoked. | 151 // identifies that the decision has been revoked. |
174 EXPECT_TRUE(state->HasUserDecision(kWWWGoogleHost)); | 152 EXPECT_TRUE(state->HasAllowed(kWWWGoogleHost)); |
175 state->RevokeUserDecisions(kWWWGoogleHost); | 153 state->RevokeUserAllowExceptions(kWWWGoogleHost); |
176 EXPECT_FALSE(state->HasUserDecision(kWWWGoogleHost)); | 154 EXPECT_FALSE(state->HasAllowed(kWWWGoogleHost)); |
177 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 155 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
178 state->QueryPolicy(kWWWGoogleHost, | 156 state->QueryPolicy(kWWWGoogleHost, |
179 google_cert.get(), | 157 google_cert.get(), |
180 net::CERT_STATUS_DATE_INVALID, | 158 net::CERT_STATUS_DATE_INVALID, |
181 &unused_value)); | 159 &unused_value)); |
182 | 160 |
183 // Verify that the revocation of the kWWWGoogleHost decision does not affect | 161 // Verify that the revocation of the kWWWGoogleHost decision does not affect |
184 // the Allow for kExampleHost. | 162 // the Allow for kExampleHost. |
185 EXPECT_TRUE(state->HasUserDecision(kExampleHost)); | 163 EXPECT_TRUE(state->HasAllowed(kExampleHost)); |
186 | 164 |
187 // Verify the revocation of the kWWWGoogleHost decision does not affect the | 165 // Verify the revocation of the kWWWGoogleHost decision does not affect the |
188 // non-decision for kGoogleHost. Then verify that a revocation of a URL with | 166 // non-decision for kGoogleHost. Then verify that a revocation of a URL with |
189 // no decision has no effect. | 167 // no decision has no effect. |
190 EXPECT_FALSE(state->HasUserDecision(kGoogleHost)); | 168 EXPECT_FALSE(state->HasAllowed(kGoogleHost)); |
191 state->RevokeUserDecisions(kGoogleHost); | 169 state->RevokeUserAllowExceptions(kGoogleHost); |
192 EXPECT_FALSE(state->HasUserDecision(kGoogleHost)); | 170 EXPECT_FALSE(state->HasAllowed(kGoogleHost)); |
193 } | 171 } |
194 | 172 |
195 // Clear unit tests the expected behavior of calling Clear to forget all cert | 173 // Clear unit tests the expected behavior of calling Clear to forget all cert |
196 // decision state on the SSLHostStateDelegate class. | 174 // decision state on the SSLHostStateDelegate class. |
197 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, Clear) { | 175 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, Clear) { |
198 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); | 176 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); |
199 content::WebContents* tab = | 177 content::WebContents* tab = |
200 browser()->tab_strip_model()->GetActiveWebContents(); | 178 browser()->tab_strip_model()->GetActiveWebContents(); |
201 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 179 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
202 ChromeSSLHostStateDelegate* state = | 180 ChromeSSLHostStateDelegate* state = |
203 ChromeSSLHostStateDelegateFactory::GetForProfile(profile); | 181 ChromeSSLHostStateDelegateFactory::GetForProfile(profile); |
204 bool unused_value; | 182 bool unused_value; |
205 | 183 |
206 // Simulate a user decision to allow an invalid certificate exception for | 184 // Simulate a user decision to allow an invalid certificate exception for |
207 // kWWWGoogleHost and for kExampleHost. | 185 // kWWWGoogleHost and for kExampleHost. |
208 state->AllowCert( | 186 state->AllowCert( |
209 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 187 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
210 | 188 |
211 // Do a full clear, then make sure that both kWWWGoogleHost, which had a | 189 // Do a full clear, then make sure that both kWWWGoogleHost, which had a |
212 // decision made, and kExampleHost, which was untouched, are now in a | 190 // decision made, and kExampleHost, which was untouched, are now in a denied |
213 // non-decision state. | 191 // state. |
214 state->Clear(); | 192 state->Clear(); |
215 EXPECT_FALSE(state->HasUserDecision(kWWWGoogleHost)); | 193 EXPECT_FALSE(state->HasAllowed(kWWWGoogleHost)); |
216 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 194 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
217 state->QueryPolicy(kWWWGoogleHost, | 195 state->QueryPolicy(kWWWGoogleHost, |
218 google_cert.get(), | 196 google_cert.get(), |
219 net::CERT_STATUS_DATE_INVALID, | 197 net::CERT_STATUS_DATE_INVALID, |
220 &unused_value)); | 198 &unused_value)); |
221 EXPECT_FALSE(state->HasUserDecision(kExampleHost)); | 199 EXPECT_FALSE(state->HasAllowed(kExampleHost)); |
222 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 200 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
223 state->QueryPolicy(kExampleHost, | 201 state->QueryPolicy(kExampleHost, |
224 google_cert.get(), | 202 google_cert.get(), |
225 net::CERT_STATUS_DATE_INVALID, | 203 net::CERT_STATUS_DATE_INVALID, |
226 &unused_value)); | 204 &unused_value)); |
227 } | 205 } |
228 | 206 |
229 // DidHostRunInsecureContent unit tests the expected behavior of calling | 207 // DidHostRunInsecureContent unit tests the expected behavior of calling |
230 // DidHostRunInsecureContent as well as HostRanInsecureContent to check if | 208 // DidHostRunInsecureContent as well as HostRanInsecureContent to check if |
231 // insecure content has been run and to mark it as such. | 209 // insecure content has been run and to mark it as such. |
232 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, | 210 IN_PROC_BROWSER_TEST_F(ChromeSSLHostStateDelegateTest, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 252 |
275 // Add a cert exception to the profile and then verify that it still exists | 253 // Add a cert exception to the profile and then verify that it still exists |
276 // in the incognito profile. | 254 // in the incognito profile. |
277 state->AllowCert( | 255 state->AllowCert( |
278 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 256 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
279 | 257 |
280 scoped_ptr<Profile> incognito(profile->CreateOffTheRecordProfile()); | 258 scoped_ptr<Profile> incognito(profile->CreateOffTheRecordProfile()); |
281 content::SSLHostStateDelegate* incognito_state = | 259 content::SSLHostStateDelegate* incognito_state = |
282 incognito->GetSSLHostStateDelegate(); | 260 incognito->GetSSLHostStateDelegate(); |
283 | 261 |
284 EXPECT_EQ(net::CertPolicy::ALLOWED, | 262 EXPECT_EQ(content::SSLHostStateDelegate::ALLOWED, |
285 incognito_state->QueryPolicy(kWWWGoogleHost, | 263 incognito_state->QueryPolicy(kWWWGoogleHost, |
286 google_cert.get(), | 264 google_cert.get(), |
287 net::CERT_STATUS_DATE_INVALID, | 265 net::CERT_STATUS_DATE_INVALID, |
288 &unused_value)); | 266 &unused_value)); |
289 | 267 |
290 // Add a cert exception to the incognito profile. It will be checked after | 268 // Add a cert exception to the incognito profile. It will be checked after |
291 // restart that this exception does not exist. Note the different cert URL and | 269 // restart that this exception does not exist. Note the different cert URL and |
292 // error than above thus mapping to a second exception. Also validate that it | 270 // error than above thus mapping to a second exception. Also validate that it |
293 // was not added as an exception to the regular profile. | 271 // was not added as an exception to the regular profile. |
294 incognito_state->AllowCert( | 272 incognito_state->AllowCert( |
295 kGoogleHost, google_cert.get(), net::CERT_STATUS_COMMON_NAME_INVALID); | 273 kGoogleHost, google_cert.get(), net::CERT_STATUS_COMMON_NAME_INVALID); |
296 | 274 |
297 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 275 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
298 state->QueryPolicy(kGoogleHost, | 276 state->QueryPolicy(kGoogleHost, |
299 google_cert.get(), | 277 google_cert.get(), |
300 net::CERT_STATUS_COMMON_NAME_INVALID, | 278 net::CERT_STATUS_COMMON_NAME_INVALID, |
301 &unused_value)); | 279 &unused_value)); |
302 } | 280 } |
303 | 281 |
304 // AfterRestart ensures that any cert decisions made in an incognito profile are | 282 // AfterRestart ensures that any cert decisions made in an incognito profile are |
305 // forgetten after a session restart even if given a command line flag to | 283 // forgetten after a session restart even if given a command line flag to |
306 // remember cert decisions after restart. | 284 // remember cert decisions after restart. |
307 IN_PROC_BROWSER_TEST_F(IncognitoSSLHostStateDelegateTest, AfterRestart) { | 285 IN_PROC_BROWSER_TEST_F(IncognitoSSLHostStateDelegateTest, AfterRestart) { |
308 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); | 286 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); |
309 content::WebContents* tab = | 287 content::WebContents* tab = |
310 browser()->tab_strip_model()->GetActiveWebContents(); | 288 browser()->tab_strip_model()->GetActiveWebContents(); |
311 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 289 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
312 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); | 290 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); |
313 bool unused_value; | 291 bool unused_value; |
314 | 292 |
315 // Verify that the exception added before restart to the regular | 293 // Verify that the exception added before restart to the regular |
316 // (non-incognito) profile still exists and was not cleared after the | 294 // (non-incognito) profile still exists and was not cleared after the |
317 // incognito session ended. | 295 // incognito session ended. |
318 EXPECT_EQ(net::CertPolicy::ALLOWED, | 296 EXPECT_EQ(content::SSLHostStateDelegate::ALLOWED, |
319 state->QueryPolicy(kWWWGoogleHost, | 297 state->QueryPolicy(kWWWGoogleHost, |
320 google_cert.get(), | 298 google_cert.get(), |
321 net::CERT_STATUS_DATE_INVALID, | 299 net::CERT_STATUS_DATE_INVALID, |
322 &unused_value)); | 300 &unused_value)); |
323 | 301 |
324 scoped_ptr<Profile> incognito(profile->CreateOffTheRecordProfile()); | 302 scoped_ptr<Profile> incognito(profile->CreateOffTheRecordProfile()); |
325 content::SSLHostStateDelegate* incognito_state = | 303 content::SSLHostStateDelegate* incognito_state = |
326 incognito->GetSSLHostStateDelegate(); | 304 incognito->GetSSLHostStateDelegate(); |
327 | 305 |
328 // Verify that the exception added before restart to the incognito profile was | 306 // Verify that the exception added before restart to the incognito profile was |
329 // cleared when the incognito session ended. | 307 // cleared when the incognito session ended. |
330 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 308 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
331 incognito_state->QueryPolicy(kGoogleHost, | 309 incognito_state->QueryPolicy(kGoogleHost, |
332 google_cert.get(), | 310 google_cert.get(), |
333 net::CERT_STATUS_COMMON_NAME_INVALID, | 311 net::CERT_STATUS_COMMON_NAME_INVALID, |
334 &unused_value)); | 312 &unused_value)); |
335 } | 313 } |
336 | 314 |
337 // Tests to make sure that if the remember value is set to -1, any decisions | 315 // Tests to make sure that if the remember value is set to -1, any decisions |
338 // won't be remembered over a restart. | 316 // won't be remembered over a restart. |
339 class ForGetSSLHostStateDelegateTest : public ChromeSSLHostStateDelegateTest { | 317 class ForGetSSLHostStateDelegateTest : public ChromeSSLHostStateDelegateTest { |
340 protected: | 318 protected: |
341 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 319 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
342 ChromeSSLHostStateDelegateTest::SetUpCommandLine(command_line); | 320 ChromeSSLHostStateDelegateTest::SetUpCommandLine(command_line); |
343 command_line->AppendSwitchASCII(switches::kRememberCertErrorDecisions, | 321 command_line->AppendSwitchASCII(switches::kRememberCertErrorDecisions, |
344 kForgetAtSessionEnd); | 322 kForgetAtSessionEnd); |
345 } | 323 } |
346 }; | 324 }; |
347 | 325 |
348 IN_PROC_BROWSER_TEST_F(ForGetSSLHostStateDelegateTest, PRE_AfterRestart) { | 326 IN_PROC_BROWSER_TEST_F(ForGetSSLHostStateDelegateTest, PRE_AfterRestart) { |
349 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); | 327 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); |
350 content::WebContents* tab = | 328 content::WebContents* tab = |
351 browser()->tab_strip_model()->GetActiveWebContents(); | 329 browser()->tab_strip_model()->GetActiveWebContents(); |
352 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 330 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
353 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); | 331 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); |
354 bool unused_value; | 332 bool unused_value; |
355 | 333 |
356 state->AllowCert( | 334 state->AllowCert( |
357 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 335 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
358 EXPECT_EQ(net::CertPolicy::ALLOWED, | 336 EXPECT_EQ(content::SSLHostStateDelegate::ALLOWED, |
359 state->QueryPolicy(kWWWGoogleHost, | 337 state->QueryPolicy(kWWWGoogleHost, |
360 google_cert.get(), | 338 google_cert.get(), |
361 net::CERT_STATUS_DATE_INVALID, | 339 net::CERT_STATUS_DATE_INVALID, |
362 &unused_value)); | 340 &unused_value)); |
363 } | 341 } |
364 | 342 |
365 IN_PROC_BROWSER_TEST_F(ForGetSSLHostStateDelegateTest, AfterRestart) { | 343 IN_PROC_BROWSER_TEST_F(ForGetSSLHostStateDelegateTest, AfterRestart) { |
366 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); | 344 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); |
367 content::WebContents* tab = | 345 content::WebContents* tab = |
368 browser()->tab_strip_model()->GetActiveWebContents(); | 346 browser()->tab_strip_model()->GetActiveWebContents(); |
369 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 347 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
370 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); | 348 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); |
371 bool unused_value; | 349 bool unused_value; |
372 | 350 |
373 // The cert should now be |UNKONWN| because the profile is set to forget cert | 351 // The cert should now be |DENIED| because the profile is set to forget cert |
374 // exceptions after session end. | 352 // exceptions after session end. |
375 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 353 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
376 state->QueryPolicy(kWWWGoogleHost, | 354 state->QueryPolicy(kWWWGoogleHost, |
377 google_cert.get(), | 355 google_cert.get(), |
378 net::CERT_STATUS_DATE_INVALID, | 356 net::CERT_STATUS_DATE_INVALID, |
379 &unused_value)); | 357 &unused_value)); |
380 } | 358 } |
381 | 359 |
382 // Tests to make sure that if the remember value is set to 0, any decisions made | 360 // Tests to make sure that if the remember value is set to 0, any decisions made |
383 // will be forgetten immediately. | 361 // will be forgetten immediately. |
384 class ForgetInstantlySSLHostStateDelegateTest | 362 class ForgetInstantlySSLHostStateDelegateTest |
385 : public ChromeSSLHostStateDelegateTest { | 363 : public ChromeSSLHostStateDelegateTest { |
(...skipping 19 matching lines...) Expand all Loading... |
405 ChromeSSLHostStateDelegate* chrome_state = | 383 ChromeSSLHostStateDelegate* chrome_state = |
406 static_cast<ChromeSSLHostStateDelegate*>(state); | 384 static_cast<ChromeSSLHostStateDelegate*>(state); |
407 chrome_state->SetClock(scoped_ptr<base::Clock>(clock)); | 385 chrome_state->SetClock(scoped_ptr<base::Clock>(clock)); |
408 | 386 |
409 // Start the clock at standard system time but do not advance at all to | 387 // Start the clock at standard system time but do not advance at all to |
410 // emphasize that instant forget works. | 388 // emphasize that instant forget works. |
411 clock->SetNow(base::Time::NowFromSystemTime()); | 389 clock->SetNow(base::Time::NowFromSystemTime()); |
412 | 390 |
413 state->AllowCert( | 391 state->AllowCert( |
414 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 392 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
415 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 393 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
416 state->QueryPolicy(kWWWGoogleHost, | 394 state->QueryPolicy(kWWWGoogleHost, |
417 google_cert.get(), | 395 google_cert.get(), |
418 net::CERT_STATUS_DATE_INVALID, | 396 net::CERT_STATUS_DATE_INVALID, |
419 &unused_value)); | 397 &unused_value)); |
420 } | 398 } |
421 | 399 |
422 // Tests to make sure that if the remember value is set to a non-zero value0, | 400 // Tests to make sure that if the remember value is set to a non-zero value, |
423 // any decisions will be remembered over a restart, but only for the length | 401 // any decisions will be remembered over a restart, but only for the length |
424 // specified. | 402 // specified. |
425 class RememberSSLHostStateDelegateTest : public ChromeSSLHostStateDelegateTest { | 403 class RememberSSLHostStateDelegateTest : public ChromeSSLHostStateDelegateTest { |
426 protected: | 404 protected: |
427 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 405 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
428 ChromeSSLHostStateDelegateTest::SetUpCommandLine(command_line); | 406 ChromeSSLHostStateDelegateTest::SetUpCommandLine(command_line); |
429 command_line->AppendSwitchASCII(switches::kRememberCertErrorDecisions, | 407 command_line->AppendSwitchASCII(switches::kRememberCertErrorDecisions, |
430 kDeltaSecondsString); | 408 kDeltaSecondsString); |
431 } | 409 } |
432 }; | 410 }; |
433 | 411 |
434 IN_PROC_BROWSER_TEST_F(RememberSSLHostStateDelegateTest, PRE_AfterRestart) { | 412 IN_PROC_BROWSER_TEST_F(RememberSSLHostStateDelegateTest, PRE_AfterRestart) { |
435 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); | 413 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); |
436 content::WebContents* tab = | 414 content::WebContents* tab = |
437 browser()->tab_strip_model()->GetActiveWebContents(); | 415 browser()->tab_strip_model()->GetActiveWebContents(); |
438 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 416 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
439 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); | 417 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); |
440 bool unused_value; | 418 bool unused_value; |
441 | 419 |
442 state->AllowCert( | 420 state->AllowCert( |
443 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 421 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
444 EXPECT_EQ(net::CertPolicy::ALLOWED, | 422 EXPECT_EQ(content::SSLHostStateDelegate::ALLOWED, |
445 state->QueryPolicy(kWWWGoogleHost, | 423 state->QueryPolicy(kWWWGoogleHost, |
446 google_cert.get(), | 424 google_cert.get(), |
447 net::CERT_STATUS_DATE_INVALID, | 425 net::CERT_STATUS_DATE_INVALID, |
448 &unused_value)); | 426 &unused_value)); |
449 } | 427 } |
450 | 428 |
451 IN_PROC_BROWSER_TEST_F(RememberSSLHostStateDelegateTest, AfterRestart) { | 429 IN_PROC_BROWSER_TEST_F(RememberSSLHostStateDelegateTest, AfterRestart) { |
452 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); | 430 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); |
453 content::WebContents* tab = | 431 content::WebContents* tab = |
454 browser()->tab_strip_model()->GetActiveWebContents(); | 432 browser()->tab_strip_model()->GetActiveWebContents(); |
455 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 433 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
456 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); | 434 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); |
457 bool unused_value; | 435 bool unused_value; |
458 | 436 |
459 // chrome_state takes ownership of this clock | 437 // chrome_state takes ownership of this clock |
460 base::SimpleTestClock* clock = new base::SimpleTestClock(); | 438 base::SimpleTestClock* clock = new base::SimpleTestClock(); |
461 ChromeSSLHostStateDelegate* chrome_state = | 439 ChromeSSLHostStateDelegate* chrome_state = |
462 static_cast<ChromeSSLHostStateDelegate*>(state); | 440 static_cast<ChromeSSLHostStateDelegate*>(state); |
463 chrome_state->SetClock(scoped_ptr<base::Clock>(clock)); | 441 chrome_state->SetClock(scoped_ptr<base::Clock>(clock)); |
464 | 442 |
465 // Start the clock at standard system time. | 443 // Start the clock at standard system time. |
466 clock->SetNow(base::Time::NowFromSystemTime()); | 444 clock->SetNow(base::Time::NowFromSystemTime()); |
467 | 445 |
468 // This should only pass if the cert was allowed before the test was restart | 446 // This should only pass if the cert was allowed before the test was restart |
469 // and thus has now been rememebered across browser restarts. | 447 // and thus has now been rememebered across browser restarts. |
470 EXPECT_EQ(net::CertPolicy::ALLOWED, | 448 EXPECT_EQ(content::SSLHostStateDelegate::ALLOWED, |
471 state->QueryPolicy(kWWWGoogleHost, | 449 state->QueryPolicy(kWWWGoogleHost, |
472 google_cert.get(), | 450 google_cert.get(), |
473 net::CERT_STATUS_DATE_INVALID, | 451 net::CERT_STATUS_DATE_INVALID, |
474 &unused_value)); | 452 &unused_value)); |
475 | 453 |
476 // Simulate the clock advancing by the specified delta. | 454 // Simulate the clock advancing by the specified delta. |
477 clock->Advance(base::TimeDelta::FromSeconds(kDeltaOneDayInSeconds + 1)); | 455 clock->Advance(base::TimeDelta::FromSeconds(kDeltaOneDayInSeconds + 1)); |
478 | 456 |
479 // The cert should now be |UNKONWN| because the specified delta has passed. | 457 // The cert should now be |DENIED| because the specified delta has passed. |
480 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 458 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
481 state->QueryPolicy(kWWWGoogleHost, | 459 state->QueryPolicy(kWWWGoogleHost, |
482 google_cert.get(), | 460 google_cert.get(), |
483 net::CERT_STATUS_DATE_INVALID, | 461 net::CERT_STATUS_DATE_INVALID, |
484 &unused_value)); | 462 &unused_value)); |
485 } | 463 } |
486 | 464 |
487 // QueryPolicyExpired unit tests to make sure that if a certificate decision has | 465 // QueryPolicyExpired unit tests to make sure that if a certificate decision has |
488 // expired, the return value from QueryPolicy returns the correct vaule. | 466 // expired, the return value from QueryPolicy returns the correct vaule. |
489 IN_PROC_BROWSER_TEST_F(RememberSSLHostStateDelegateTest, QueryPolicyExpired) { | 467 IN_PROC_BROWSER_TEST_F(RememberSSLHostStateDelegateTest, QueryPolicyExpired) { |
490 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); | 468 scoped_refptr<net::X509Certificate> google_cert = GetGoogleCert(); |
491 content::WebContents* tab = | 469 content::WebContents* tab = |
492 browser()->tab_strip_model()->GetActiveWebContents(); | 470 browser()->tab_strip_model()->GetActiveWebContents(); |
493 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 471 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
494 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); | 472 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); |
495 bool expired_previous_decision; | 473 bool expired_previous_decision; |
496 | 474 |
497 // chrome_state takes ownership of this clock | 475 // chrome_state takes ownership of this clock |
498 base::SimpleTestClock* clock = new base::SimpleTestClock(); | 476 base::SimpleTestClock* clock = new base::SimpleTestClock(); |
499 ChromeSSLHostStateDelegate* chrome_state = | 477 ChromeSSLHostStateDelegate* chrome_state = |
500 static_cast<ChromeSSLHostStateDelegate*>(state); | 478 static_cast<ChromeSSLHostStateDelegate*>(state); |
501 chrome_state->SetClock(scoped_ptr<base::Clock>(clock)); | 479 chrome_state->SetClock(scoped_ptr<base::Clock>(clock)); |
502 | 480 |
503 // Start the clock at standard system time but do not advance at all to | 481 // Start the clock at standard system time but do not advance at all to |
504 // emphasize that instant forget works. | 482 // emphasize that instant forget works. |
505 clock->SetNow(base::Time::NowFromSystemTime()); | 483 clock->SetNow(base::Time::NowFromSystemTime()); |
506 | 484 |
507 // The certificate has never been seen before, so it should be UNKONWN and | 485 // The certificate has never been seen before, so it should be UNKONWN and |
508 // should also indicate that it hasn't expired. | 486 // should also indicate that it hasn't expired. |
509 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 487 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
510 state->QueryPolicy(kWWWGoogleHost, | 488 state->QueryPolicy(kWWWGoogleHost, |
511 google_cert.get(), | 489 google_cert.get(), |
512 net::CERT_STATUS_DATE_INVALID, | 490 net::CERT_STATUS_DATE_INVALID, |
513 &expired_previous_decision)); | 491 &expired_previous_decision)); |
514 EXPECT_FALSE(expired_previous_decision); | 492 EXPECT_FALSE(expired_previous_decision); |
515 | 493 |
516 // After allowing the certificate, a query should say that it is allowed and | 494 // After allowing the certificate, a query should say that it is allowed and |
517 // also specify that it hasn't expired. | 495 // also specify that it hasn't expired. |
518 state->AllowCert( | 496 state->AllowCert( |
519 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 497 kWWWGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
520 EXPECT_EQ(net::CertPolicy::ALLOWED, | 498 EXPECT_EQ(content::SSLHostStateDelegate::ALLOWED, |
521 state->QueryPolicy(kWWWGoogleHost, | 499 state->QueryPolicy(kWWWGoogleHost, |
522 google_cert.get(), | 500 google_cert.get(), |
523 net::CERT_STATUS_DATE_INVALID, | 501 net::CERT_STATUS_DATE_INVALID, |
524 &expired_previous_decision)); | 502 &expired_previous_decision)); |
525 EXPECT_FALSE(expired_previous_decision); | 503 EXPECT_FALSE(expired_previous_decision); |
526 | 504 |
527 // Simulate the clock advancing by the specified delta. | 505 // Simulate the clock advancing by the specified delta. |
528 clock->Advance(base::TimeDelta::FromSeconds(kDeltaOneDayInSeconds + 1)); | 506 clock->Advance(base::TimeDelta::FromSeconds(kDeltaOneDayInSeconds + 1)); |
529 | 507 |
530 // The decision expiration time has come, so it should indicate that the | 508 // The decision expiration time has come, so it should indicate that the |
531 // certificate and error are UNKOWN but also that they expired since the last | 509 // certificate and error are DENIED but also that they expired since the last |
532 // query. | 510 // query. |
533 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 511 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
534 state->QueryPolicy(kWWWGoogleHost, | 512 state->QueryPolicy(kWWWGoogleHost, |
535 google_cert.get(), | 513 google_cert.get(), |
536 net::CERT_STATUS_DATE_INVALID, | 514 net::CERT_STATUS_DATE_INVALID, |
537 &expired_previous_decision)); | 515 &expired_previous_decision)); |
538 EXPECT_TRUE(expired_previous_decision); | 516 EXPECT_TRUE(expired_previous_decision); |
539 | 517 |
540 // However, with a new query, it should indicate that no new expiration has | 518 // However, with a new query, it should indicate that no new expiration has |
541 // occurred. | 519 // occurred. |
542 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 520 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
543 state->QueryPolicy(kWWWGoogleHost, | 521 state->QueryPolicy(kWWWGoogleHost, |
544 google_cert.get(), | 522 google_cert.get(), |
545 net::CERT_STATUS_DATE_INVALID, | 523 net::CERT_STATUS_DATE_INVALID, |
546 &expired_previous_decision)); | 524 &expired_previous_decision)); |
547 EXPECT_FALSE(expired_previous_decision); | 525 EXPECT_FALSE(expired_previous_decision); |
548 } | 526 } |
549 | 527 |
550 // Tests to make sure that if the user deletes their browser history, SSL | 528 // Tests to make sure that if the user deletes their browser history, SSL |
551 // exceptions will be deleted as well. | 529 // exceptions will be deleted as well. |
552 class RemoveBrowsingHistorySSLHostStateDelegateTest | 530 class RemoveBrowsingHistorySSLHostStateDelegateTest |
(...skipping 16 matching lines...) Expand all Loading... |
569 browser()->tab_strip_model()->GetActiveWebContents(); | 547 browser()->tab_strip_model()->GetActiveWebContents(); |
570 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); | 548 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); |
571 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); | 549 content::SSLHostStateDelegate* state = profile->GetSSLHostStateDelegate(); |
572 bool unused_value; | 550 bool unused_value; |
573 | 551 |
574 // Add an exception for an invalid certificate. Then remove the last hour's | 552 // Add an exception for an invalid certificate. Then remove the last hour's |
575 // worth of browsing history and verify that the exception has been deleted. | 553 // worth of browsing history and verify that the exception has been deleted. |
576 state->AllowCert( | 554 state->AllowCert( |
577 kGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); | 555 kGoogleHost, google_cert.get(), net::CERT_STATUS_DATE_INVALID); |
578 RemoveAndWait(profile); | 556 RemoveAndWait(profile); |
579 EXPECT_EQ(net::CertPolicy::UNKNOWN, | 557 EXPECT_EQ(content::SSLHostStateDelegate::DENIED, |
580 state->QueryPolicy(kGoogleHost, | 558 state->QueryPolicy(kGoogleHost, |
581 google_cert.get(), | 559 google_cert.get(), |
582 net::CERT_STATUS_DATE_INVALID, | 560 net::CERT_STATUS_DATE_INVALID, |
583 &unused_value)); | 561 &unused_value)); |
584 } | 562 } |
OLD | NEW |