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

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

Issue 1080593006: Fix flaky browser test SSLUITest.BadCertFollowedByGoodCert (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 5 years, 8 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 24 matching lines...) Expand all
35 #include "chrome/test/base/ui_test_utils.h" 35 #include "chrome/test/base/ui_test_utils.h"
36 #include "components/content_settings/core/browser/host_content_settings_map.h" 36 #include "components/content_settings/core/browser/host_content_settings_map.h"
37 #include "components/variations/variations_associated_data.h" 37 #include "components/variations/variations_associated_data.h"
38 #include "components/web_modal/web_contents_modal_dialog_manager.h" 38 #include "components/web_modal/web_contents_modal_dialog_manager.h"
39 #include "content/public/browser/browser_context.h" 39 #include "content/public/browser/browser_context.h"
40 #include "content/public/browser/interstitial_page.h" 40 #include "content/public/browser/interstitial_page.h"
41 #include "content/public/browser/navigation_controller.h" 41 #include "content/public/browser/navigation_controller.h"
42 #include "content/public/browser/navigation_entry.h" 42 #include "content/public/browser/navigation_entry.h"
43 #include "content/public/browser/notification_service.h" 43 #include "content/public/browser/notification_service.h"
44 #include "content/public/browser/render_frame_host.h" 44 #include "content/public/browser/render_frame_host.h"
45 #include "content/public/browser/render_process_host.h" 45 #include "content/public/browser/render_process_host.h"
davidben 2015/04/24 14:53:00 No longer needed.
jww 2015/04/24 17:26:35 Done.
46 #include "content/public/browser/render_view_host.h" 46 #include "content/public/browser/render_view_host.h"
47 #include "content/public/browser/render_widget_host_view.h" 47 #include "content/public/browser/render_widget_host_view.h"
48 #include "content/public/browser/web_contents.h" 48 #include "content/public/browser/web_contents.h"
49 #include "content/public/browser/web_contents_observer.h" 49 #include "content/public/browser/web_contents_observer.h"
50 #include "content/public/common/security_style.h" 50 #include "content/public/common/security_style.h"
51 #include "content/public/common/ssl_status.h" 51 #include "content/public/common/ssl_status.h"
52 #include "content/public/test/browser_test_utils.h" 52 #include "content/public/test/browser_test_utils.h"
53 #include "content/public/test/download_test_observer.h" 53 #include "content/public/test/download_test_observer.h"
54 #include "content/public/test/test_renderer_host.h" 54 #include "content/public/test/test_renderer_host.h"
55 #include "net/base/host_port_pair.h" 55 #include "net/base/host_port_pair.h"
56 #include "net/base/net_errors.h" 56 #include "net/base/net_errors.h"
57 #include "net/base/test_data_directory.h" 57 #include "net/base/test_data_directory.h"
58 #include "net/cert/cert_status_flags.h" 58 #include "net/cert/cert_status_flags.h"
59 #include "net/cert/test_root_certs.h" 59 #include "net/cert/test_root_certs.h"
davidben 2015/04/24 14:53:00 No longer needed.
jww 2015/04/24 17:26:35 Done.
60 #include "net/cert/x509_certificate.h" 60 #include "net/cert/x509_certificate.h"
61 #include "net/dns/host_resolver.h" 61 #include "net/dns/host_resolver.h"
62 #include "net/dns/mock_host_resolver.h" 62 #include "net/dns/mock_host_resolver.h"
davidben 2015/04/24 14:53:00 Not sure the two host resolver includes were ever
jww 2015/04/24 17:26:35 Yeah, I added those by accident (or rather, forgot
63 #include "net/http/http_transaction_factory.h" 63 #include "net/http/http_transaction_factory.h"
davidben 2015/04/24 14:53:00 No longer needed.
jww 2015/04/24 17:26:35 Done.
64 #include "net/ssl/ssl_info.h" 64 #include "net/ssl/ssl_info.h"
65 #include "net/test/spawned_test_server/spawned_test_server.h" 65 #include "net/test/spawned_test_server/spawned_test_server.h"
66 #include "net/url_request/url_request_context.h" 66 #include "net/url_request/url_request_context.h"
67 #include "net/url_request/url_request_context_getter.h" 67 #include "net/url_request/url_request_context_getter.h"
davidben 2015/04/24 14:53:00 No longer needed.
jww 2015/04/24 17:26:35 Done.
68 68
69 #if defined(USE_NSS_CERTS) 69 #if defined(USE_NSS_CERTS)
70 #include "chrome/browser/net/nss_context.h" 70 #include "chrome/browser/net/nss_context.h"
71 #include "net/base/crypto_module.h" 71 #include "net/base/crypto_module.h"
72 #include "net/cert/nss_cert_database.h" 72 #include "net/cert/nss_cert_database.h"
73 #endif // defined(USE_NSS_CERTS) 73 #endif // defined(USE_NSS_CERTS)
74 74
75 using base::ASCIIToUTF16; 75 using base::ASCIIToUTF16;
76 using chrome_browser_interstitials::SecurityInterstitialIDNTest; 76 using chrome_browser_interstitials::SecurityInterstitialIDNTest;
77 using chrome_browser_net::CertificateErrorReporter; 77 using chrome_browser_net::CertificateErrorReporter;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 266
267 private: 267 private:
268 const scoped_refptr<SafeBrowsingUIManager> safe_browsing_ui_manager_; 268 const scoped_refptr<SafeBrowsingUIManager> safe_browsing_ui_manager_;
269 bool reported_; 269 bool reported_;
270 bool expect_report_; 270 bool expect_report_;
271 base::Closure report_sent_callback_; 271 base::Closure report_sent_callback_;
272 }; 272 };
273 273
274 } // namespace CertificateReporting 274 } // namespace CertificateReporting
275 275
276 void RootCertsChangedOnIOThread(
277 const scoped_refptr<net::URLRequestContextGetter> context_getter) {
278 net::CertDatabase::GetInstance()->NotifyObserversOfCACertChanged(NULL);
279 context_getter->GetURLRequestContext()
280 ->http_transaction_factory()
281 ->GetSession()
282 ->CloseAllConnections();
283 }
284
285 // Alerts the URLRequestContext for the given WebContents that a root
286 // certificate has changed state or been removed. This, in turn, clears any
287 // cached certificate validation in the cert verifier. This will also close all
288 // connections in the socket pool of |contents|, so calls to this should be made
289 // with care.
290 void RootCertsChanged(WebContents* contents) {
291 scoped_refptr<net::URLRequestContextGetter> url_request_context =
292 contents->GetBrowserContext()->GetRequestContextForRenderProcess(
293 contents->GetRenderProcessHost()->GetID());
294 base::RunLoop run_loop;
295 content::BrowserThread::PostTaskAndReply(
296 content::BrowserThread::IO, FROM_HERE,
297 base::Bind(&RootCertsChangedOnIOThread, url_request_context),
298 run_loop.QuitClosure());
299 run_loop.Run();
300 base::RunLoop().RunUntilIdle();
301 }
302
303 } // namespace 276 } // namespace
304 277
305 class SSLUITest : public InProcessBrowserTest { 278 class SSLUITest : public InProcessBrowserTest {
306 public: 279 public:
307 SSLUITest() 280 SSLUITest()
308 : https_server_(net::SpawnedTestServer::TYPE_HTTPS, 281 : https_server_(net::SpawnedTestServer::TYPE_HTTPS,
309 SSLOptions(SSLOptions::CERT_OK), 282 SSLOptions(SSLOptions::CERT_OK),
310 base::FilePath(kDocRoot)), 283 base::FilePath(kDocRoot)),
311 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS, 284 https_server_expired_(net::SpawnedTestServer::TYPE_HTTPS,
312 SSLOptions(SSLOptions::CERT_EXPIRED), 285 SSLOptions(SSLOptions::CERT_EXPIRED),
(...skipping 2029 matching lines...) Expand 10 before | Expand all | Expand 10 after
2342 2315
2343 browser()->tab_strip_model()->ActivateTabAt(1, true); 2316 browser()->tab_strip_model()->ActivateTabAt(1, true);
2344 EXPECT_TRUE(tab->GetRenderWidgetHostView()->IsShowing()); 2317 EXPECT_TRUE(tab->GetRenderWidgetHostView()->IsShowing());
2345 } 2318 }
2346 2319
2347 // Verifies that if a bad certificate is seen for a host and the user proceeds 2320 // Verifies that if a bad certificate is seen for a host and the user proceeds
2348 // through the interstitial, the decision to proceed is initially remembered. 2321 // through the interstitial, the decision to proceed is initially remembered.
2349 // However, if this is followed by another visit, and a good certificate 2322 // However, if this is followed by another visit, and a good certificate
2350 // is seen for the same host, the original exception is forgotten. 2323 // is seen for the same host, the original exception is forgotten.
2351 IN_PROC_BROWSER_TEST_F(SSLUITest, BadCertFollowedByGoodCert) { 2324 IN_PROC_BROWSER_TEST_F(SSLUITest, BadCertFollowedByGoodCert) {
2325 // It is necessary to use |https_server_expired_| rather than
2326 // |https_server_mismatched| because the former shares a host with
2327 // |https_server_| and cert exceptions are per host.
2328 ASSERT_TRUE(https_server_expired_.Start());
2352 ASSERT_TRUE(https_server_.Start()); 2329 ASSERT_TRUE(https_server_.Start());
2330
2331 std::string https_server_expired_host =
2332 https_server_.GetURL("files/ssl/google.html").host();
2353 std::string https_server_host = 2333 std::string https_server_host =
2354 https_server_.GetURL("files/ssl/google.html").host(); 2334 https_server_.GetURL("files/ssl/google.html").host();
2335 ASSERT_EQ(https_server_expired_host, https_server_host);
Ryan Sleevi 2015/04/24 11:03:40 This isn't part of the contract of net::TestServer
davidben 2015/04/24 14:53:00 I think this is fine. We'll notice if it breaks an
2355 2336
2356 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents(); 2337 WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
2357 net::TestRootCerts* root_certs = net::TestRootCerts::GetInstance();
2358
2359 ASSERT_TRUE(root_certs);
2360 root_certs->Clear();
2361 2338
2362 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext()); 2339 Profile* profile = Profile::FromBrowserContext(tab->GetBrowserContext());
2363 ChromeSSLHostStateDelegate* state = 2340 ChromeSSLHostStateDelegate* state =
2364 reinterpret_cast<ChromeSSLHostStateDelegate*>( 2341 reinterpret_cast<ChromeSSLHostStateDelegate*>(
2365 profile->GetSSLHostStateDelegate()); 2342 profile->GetSSLHostStateDelegate());
2366 2343
2367 ui_test_utils::NavigateToURL(browser(), 2344 ui_test_utils::NavigateToURL(
2368 https_server_.GetURL("files/ssl/google.html")); 2345 browser(), https_server_expired_.GetURL("files/ssl/google.html"));
2369 2346
2370 ProceedThroughInterstitial(tab); 2347 ProceedThroughInterstitial(tab);
2371 EXPECT_TRUE(state->HasAllowException(https_server_host)); 2348 EXPECT_TRUE(state->HasAllowException(https_server_host));
2372 2349
2373 ASSERT_TRUE(https_server_.LoadTestRootCert());
2374 RootCertsChanged(tab);
2375 ui_test_utils::NavigateToURL(browser(), 2350 ui_test_utils::NavigateToURL(browser(),
2376 https_server_.GetURL("files/ssl/google.html")); 2351 https_server_.GetURL("files/ssl/google.html"));
2377 ASSERT_FALSE(tab->GetInterstitialPage()); 2352 ASSERT_FALSE(tab->GetInterstitialPage());
2378 EXPECT_FALSE(state->HasAllowException(https_server_host)); 2353 EXPECT_FALSE(state->HasAllowException(https_server_host));
2379 } 2354 }
2380 2355
2381 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest { 2356 class SSLBlockingPageIDNTest : public SecurityInterstitialIDNTest {
2382 protected: 2357 protected:
2383 // SecurityInterstitialIDNTest implementation 2358 // SecurityInterstitialIDNTest implementation
2384 SecurityInterstitialPage* CreateInterstitial( 2359 SecurityInterstitialPage* CreateInterstitial(
(...skipping 16 matching lines...) Expand all
2401 2376
2402 // Visit a page over https that contains a frame with a redirect. 2377 // Visit a page over https that contains a frame with a redirect.
2403 2378
2404 // XMLHttpRequest insecure content in synchronous mode. 2379 // XMLHttpRequest insecure content in synchronous mode.
2405 2380
2406 // XMLHttpRequest insecure content in asynchronous mode. 2381 // XMLHttpRequest insecure content in asynchronous mode.
2407 2382
2408 // XMLHttpRequest over bad ssl in synchronous mode. 2383 // XMLHttpRequest over bad ssl in synchronous mode.
2409 2384
2410 // XMLHttpRequest over OK ssl in synchronous mode. 2385 // XMLHttpRequest over OK ssl in synchronous mode.
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698