OLD | NEW |
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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 #include "net/base/nss_cert_database.h" | 48 #include "net/base/nss_cert_database.h" |
49 #endif // defined(USE_NSS) | 49 #endif // defined(USE_NSS) |
50 | 50 |
51 using content::InterstitialPage; | 51 using content::InterstitialPage; |
52 using content::NavigationController; | 52 using content::NavigationController; |
53 using content::NavigationEntry; | 53 using content::NavigationEntry; |
54 using content::SSLStatus; | 54 using content::SSLStatus; |
55 using content::WebContents; | 55 using content::WebContents; |
56 | 56 |
57 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); | 57 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); |
| 58 const FilePath::CharType kWsRoot[] = FILE_PATH_LITERAL("net/data/websocket"); |
58 | 59 |
59 namespace { | 60 namespace { |
60 | 61 |
61 class ProvisionalLoadWaiter : public content::WebContentsObserver { | 62 class ProvisionalLoadWaiter : public content::WebContentsObserver { |
62 public: | 63 public: |
63 explicit ProvisionalLoadWaiter(WebContents* tab) | 64 explicit ProvisionalLoadWaiter(WebContents* tab) |
64 : WebContentsObserver(tab), waiting_(false), seen_(false) {} | 65 : WebContentsObserver(tab), waiting_(false), seen_(false) {} |
65 | 66 |
66 void Wait() { | 67 void Wait() { |
67 if (seen_) | 68 if (seen_) |
(...skipping 16 matching lines...) Expand all Loading... |
84 } | 85 } |
85 | 86 |
86 private: | 87 private: |
87 bool waiting_; | 88 bool waiting_; |
88 bool seen_; | 89 bool seen_; |
89 }; | 90 }; |
90 | 91 |
91 } // namespace | 92 } // namespace |
92 | 93 |
93 class SSLUITest : public InProcessBrowserTest { | 94 class SSLUITest : public InProcessBrowserTest { |
94 typedef net::TestServer::SSLOptions SSLOptions; | |
95 | |
96 public: | 95 public: |
97 SSLUITest() | 96 SSLUITest() |
98 : https_server_(net::TestServer::TYPE_HTTPS, | 97 : https_server_(net::TestServer::TYPE_HTTPS, |
99 SSLOptions(SSLOptions::CERT_OK), | 98 SSLOptions(SSLOptions::CERT_OK), |
100 FilePath(kDocRoot)), | 99 FilePath(kDocRoot)), |
101 https_server_expired_(net::TestServer::TYPE_HTTPS, | 100 https_server_expired_(net::TestServer::TYPE_HTTPS, |
102 SSLOptions(SSLOptions::CERT_EXPIRED), | 101 SSLOptions(SSLOptions::CERT_EXPIRED), |
103 FilePath(kDocRoot)), | 102 FilePath(kDocRoot)), |
104 https_server_mismatched_(net::TestServer::TYPE_HTTPS, | 103 https_server_mismatched_(net::TestServer::TYPE_HTTPS, |
105 SSLOptions(SSLOptions::CERT_MISMATCHED_NAME), | 104 SSLOptions(SSLOptions::CERT_MISMATCHED_NAME), |
106 FilePath(kDocRoot)) {} | 105 FilePath(kDocRoot)), |
| 106 wss_server_expired_(net::TestServer::TYPE_WSS, |
| 107 SSLOptions(SSLOptions::CERT_EXPIRED), |
| 108 FilePath(kWsRoot)) {} |
107 | 109 |
108 virtual void SetUpCommandLine(CommandLine* command_line) { | 110 virtual void SetUpCommandLine(CommandLine* command_line) { |
109 // Browser will both run and display insecure content. | 111 // Browser will both run and display insecure content. |
110 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); | 112 command_line->AppendSwitch(switches::kAllowRunningInsecureContent); |
111 // Use process-per-site so that navigating to a same-site page in a | 113 // Use process-per-site so that navigating to a same-site page in a |
112 // new tab will use the same process. | 114 // new tab will use the same process. |
113 command_line->AppendSwitch(switches::kProcessPerSite); | 115 command_line->AppendSwitch(switches::kProcessPerSite); |
114 } | 116 } |
115 | 117 |
116 void CheckAuthenticatedState(WebContents* tab, | 118 void CheckAuthenticatedState(WebContents* tab, |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 make_pair("REPLACE_WITH_UNSAFE_WORKER_PATH", unsafe_worker_path)); | 291 make_pair("REPLACE_WITH_UNSAFE_WORKER_PATH", unsafe_worker_path)); |
290 return net::TestServer::GetFilePathWithReplacements( | 292 return net::TestServer::GetFilePathWithReplacements( |
291 "files/ssl/page_with_unsafe_worker.html", | 293 "files/ssl/page_with_unsafe_worker.html", |
292 replacement_text_for_page_with_unsafe_worker, | 294 replacement_text_for_page_with_unsafe_worker, |
293 page_with_unsafe_worker_path); | 295 page_with_unsafe_worker_path); |
294 } | 296 } |
295 | 297 |
296 net::TestServer https_server_; | 298 net::TestServer https_server_; |
297 net::TestServer https_server_expired_; | 299 net::TestServer https_server_expired_; |
298 net::TestServer https_server_mismatched_; | 300 net::TestServer https_server_mismatched_; |
| 301 net::TestServer wss_server_expired_; |
299 | 302 |
300 private: | 303 private: |
| 304 typedef net::TestServer::SSLOptions SSLOptions; |
| 305 |
301 DISALLOW_COPY_AND_ASSIGN(SSLUITest); | 306 DISALLOW_COPY_AND_ASSIGN(SSLUITest); |
302 }; | 307 }; |
303 | 308 |
304 class SSLUITestBlock : public SSLUITest { | 309 class SSLUITestBlock : public SSLUITest { |
305 public: | 310 public: |
306 SSLUITestBlock() : SSLUITest() {} | 311 SSLUITestBlock() : SSLUITest() {} |
307 | 312 |
308 // Browser will neither run nor display insecure content. | 313 // Browser will neither run nor display insecure content. |
309 virtual void SetUpCommandLine(CommandLine* command_line) { | 314 virtual void SetUpCommandLine(CommandLine* command_line) { |
310 command_line->AppendSwitch(switches::kNoDisplayingInsecureContent); | 315 command_line->AppendSwitch(switches::kNoDisplayingInsecureContent); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 EXPECT_FALSE(tab->GetController().CanGoForward()); | 548 EXPECT_FALSE(tab->GetController().CanGoForward()); |
544 NavigationEntry* entry4 = tab->GetController().GetActiveEntry(); | 549 NavigationEntry* entry4 = tab->GetController().GetActiveEntry(); |
545 EXPECT_TRUE(entry2 == entry4); | 550 EXPECT_TRUE(entry2 == entry4); |
546 } | 551 } |
547 | 552 |
548 // Visit a HTTP page which request WSS connection to a server providing invalid | 553 // Visit a HTTP page which request WSS connection to a server providing invalid |
549 // certificate. Close the page while WSS connection waits for SSLManager's | 554 // certificate. Close the page while WSS connection waits for SSLManager's |
550 // response from UI thread. | 555 // response from UI thread. |
551 IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndClose) { | 556 IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndClose) { |
552 ASSERT_TRUE(test_server()->Start()); | 557 ASSERT_TRUE(test_server()->Start()); |
553 ASSERT_TRUE(https_server_expired_.Start()); | 558 ASSERT_TRUE(wss_server_expired_.Start()); |
554 | 559 |
555 // Setup page title observer. | 560 // Setup page title observer. |
556 WebContents* tab = chrome::GetActiveWebContents(browser()); | 561 WebContents* tab = chrome::GetActiveWebContents(browser()); |
557 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); | 562 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); |
558 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 563 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
559 | 564 |
560 // Create GURLs to test pages. | 565 // Create GURLs to test pages. |
561 std::string masterUrlPath = StringPrintf("%s?%d", | 566 std::string masterUrlPath = StringPrintf("%s?%d", |
562 test_server()->GetURL("files/ssl/wss_close.html").spec().c_str(), | 567 test_server()->GetURL("files/ssl/wss_close.html").spec().c_str(), |
563 https_server_expired_.host_port_pair().port()); | 568 wss_server_expired_.host_port_pair().port()); |
564 GURL masterUrl(masterUrlPath); | 569 GURL masterUrl(masterUrlPath); |
565 std::string slaveUrlPath = StringPrintf("%s?%d", | 570 std::string slaveUrlPath = StringPrintf("%s?%d", |
566 test_server()->GetURL("files/ssl/wss_close_slave.html").spec().c_str(), | 571 test_server()->GetURL("files/ssl/wss_close_slave.html").spec().c_str(), |
567 https_server_expired_.host_port_pair().port()); | 572 wss_server_expired_.host_port_pair().port()); |
568 GURL slaveUrl(slaveUrlPath); | 573 GURL slaveUrl(slaveUrlPath); |
569 | 574 |
570 // Create tabs and visit pages which keep on creating wss connections. | 575 // Create tabs and visit pages which keep on creating wss connections. |
571 TabContents* tabs[16]; | 576 TabContents* tabs[16]; |
572 for (int i = 0; i < 16; ++i) { | 577 for (int i = 0; i < 16; ++i) { |
573 tabs[i] = chrome::AddSelectedTabWithURL(browser(), slaveUrl, | 578 tabs[i] = chrome::AddSelectedTabWithURL(browser(), slaveUrl, |
574 content::PAGE_TRANSITION_LINK); | 579 content::PAGE_TRANSITION_LINK); |
575 } | 580 } |
576 chrome::SelectNextTab(browser()); | 581 chrome::SelectNextTab(browser()); |
577 | 582 |
578 // Visit a page which waits for one TLS handshake failure. | 583 // Visit a page which waits for one TLS handshake failure. |
579 // The title will be changed to 'PASS'. | 584 // The title will be changed to 'PASS'. |
580 ui_test_utils::NavigateToURL(browser(), masterUrl); | 585 ui_test_utils::NavigateToURL(browser(), masterUrl); |
581 const string16 result = watcher.WaitAndGetTitle(); | 586 const string16 result = watcher.WaitAndGetTitle(); |
582 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); | 587 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); |
583 | 588 |
584 // Close tabs which contains the test page. | 589 // Close tabs which contains the test page. |
585 for (int i = 0; i < 16; ++i) | 590 for (int i = 0; i < 16; ++i) |
586 chrome::CloseWebContents(browser(), tabs[i]->web_contents()); | 591 chrome::CloseWebContents(browser(), tabs[i]->web_contents()); |
587 chrome::CloseWebContents(browser(), tab); | 592 chrome::CloseWebContents(browser(), tab); |
588 } | 593 } |
589 | 594 |
590 // Visit a HTTPS page and proceeds despite an invalid certificate. The page | 595 // Visit a HTTPS page and proceeds despite an invalid certificate. The page |
591 // requests WSS connection to the same origin host to check if WSS connection | 596 // requests WSS connection to the same origin host to check if WSS connection |
592 // share certificates policy with HTTPS correcly. | 597 // share certificates policy with HTTPS correcly. |
593 IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndGoForward) { | 598 IN_PROC_BROWSER_TEST_F(SSLUITest, TestWSSInvalidCertAndGoForward) { |
594 ASSERT_TRUE(test_server()->Start()); | 599 ASSERT_TRUE(test_server()->Start()); |
595 ASSERT_TRUE(https_server_expired_.Start()); | 600 ASSERT_TRUE(wss_server_expired_.Start()); |
596 | |
597 // Start pywebsocket with TLS. | |
598 content::TestWebSocketServer wss_server; | |
599 int port = wss_server.UseRandomPort(); | |
600 wss_server.UseTLS(); | |
601 FilePath wss_root_dir; | |
602 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &wss_root_dir)); | |
603 ASSERT_TRUE(wss_server.Start(wss_root_dir)); | |
604 | 601 |
605 // Setup page title observer. | 602 // Setup page title observer. |
606 WebContents* tab = chrome::GetActiveWebContents(browser()); | 603 WebContents* tab = chrome::GetActiveWebContents(browser()); |
607 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); | 604 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); |
608 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 605 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
609 | 606 |
610 // Visit bad HTTPS page. | 607 // Visit bad HTTPS page. |
611 std::string urlPath = | 608 std::string scheme("https"); |
612 StringPrintf("%s%d%s", "https://localhost:", port, "/ws.html"); | 609 GURL::Replacements replacements; |
613 ui_test_utils::NavigateToURL(browser(), GURL(urlPath)); | 610 replacements.SetSchemeStr(scheme); |
614 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_COMMON_NAME_INVALID, | 611 ui_test_utils::NavigateToURL( |
615 false, true); // Interstitial showing | 612 browser(), |
| 613 wss_server_expired_.GetURL( |
| 614 "connect_check.html").ReplaceComponents(replacements)); |
| 615 CheckAuthenticationBrokenState(tab, net::CERT_STATUS_DATE_INVALID, false, |
| 616 true); // Interstitial showing |
616 | 617 |
617 // Proceed anyway. | 618 // Proceed anyway. |
618 ProceedThroughInterstitial(tab); | 619 ProceedThroughInterstitial(tab); |
619 | 620 |
620 // Test page run a WebSocket wss connection test. The result will be shown | 621 // Test page run a WebSocket wss connection test. The result will be shown |
621 // as page title. | 622 // as page title. |
622 const string16 result = watcher.WaitAndGetTitle(); | 623 const string16 result = watcher.WaitAndGetTitle(); |
623 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); | 624 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); |
624 } | 625 } |
625 | 626 |
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1570 https_server_.GetURL(replacement_path)); | 1571 https_server_.GetURL(replacement_path)); |
1571 | 1572 |
1572 CheckAuthenticatedState(chrome::GetActiveWebContents(browser()), false); | 1573 CheckAuthenticatedState(chrome::GetActiveWebContents(browser()), false); |
1573 } | 1574 } |
1574 | 1575 |
1575 // Visit a page and establish a WebSocket connection over bad https with | 1576 // Visit a page and establish a WebSocket connection over bad https with |
1576 // --ignore-certificate-errors. The connection should be established without | 1577 // --ignore-certificate-errors. The connection should be established without |
1577 // interstitial page showing. | 1578 // interstitial page showing. |
1578 IN_PROC_BROWSER_TEST_F(SSLUITestIgnoreCertErrors, TestWSS) { | 1579 IN_PROC_BROWSER_TEST_F(SSLUITestIgnoreCertErrors, TestWSS) { |
1579 ASSERT_TRUE(test_server()->Start()); | 1580 ASSERT_TRUE(test_server()->Start()); |
1580 ASSERT_TRUE(https_server_expired_.Start()); | 1581 ASSERT_TRUE(wss_server_expired_.Start()); |
1581 | |
1582 // Start pywebsocket with TLS. | |
1583 content::TestWebSocketServer wss_server; | |
1584 int port = wss_server.UseRandomPort(); | |
1585 wss_server.UseTLS(); | |
1586 FilePath wss_root_dir; | |
1587 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &wss_root_dir)); | |
1588 ASSERT_TRUE(wss_server.Start(wss_root_dir)); | |
1589 | 1582 |
1590 // Setup page title observer. | 1583 // Setup page title observer. |
1591 WebContents* tab = chrome::GetActiveWebContents(browser()); | 1584 WebContents* tab = chrome::GetActiveWebContents(browser()); |
1592 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); | 1585 content::TitleWatcher watcher(tab, ASCIIToUTF16("PASS")); |
1593 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); | 1586 watcher.AlsoWaitForTitle(ASCIIToUTF16("FAIL")); |
1594 | 1587 |
1595 // Visit bad HTTPS page. | 1588 // Visit bad HTTPS page. |
1596 std::string url_path = | 1589 std::string scheme("https"); |
1597 StringPrintf("%s%d%s", "https://localhost:", port, "/ws.html"); | 1590 GURL::Replacements replacements; |
1598 ui_test_utils::NavigateToURL(browser(), GURL(url_path)); | 1591 replacements.SetSchemeStr(scheme); |
| 1592 ui_test_utils::NavigateToURL( |
| 1593 browser(), |
| 1594 wss_server_expired_.GetURL( |
| 1595 "connect_check.html").ReplaceComponents(replacements)); |
1599 | 1596 |
1600 // We shouldn't have an interstitial page showing here. | 1597 // We shouldn't have an interstitial page showing here. |
1601 | 1598 |
1602 // Test page run a WebSocket wss connection test. The result will be shown | 1599 // Test page run a WebSocket wss connection test. The result will be shown |
1603 // as page title. | 1600 // as page title. |
1604 const string16 result = watcher.WaitAndGetTitle(); | 1601 const string16 result = watcher.WaitAndGetTitle(); |
1605 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); | 1602 EXPECT_TRUE(LowerCaseEqualsASCII(result, "pass")); |
1606 } | 1603 } |
1607 | 1604 |
1608 // TODO(jcampan): more tests to do below. | 1605 // TODO(jcampan): more tests to do below. |
1609 | 1606 |
1610 // Visit a page over https that contains a frame with a redirect. | 1607 // Visit a page over https that contains a frame with a redirect. |
1611 | 1608 |
1612 // XMLHttpRequest insecure content in synchronous mode. | 1609 // XMLHttpRequest insecure content in synchronous mode. |
1613 | 1610 |
1614 // XMLHttpRequest insecure content in asynchronous mode. | 1611 // XMLHttpRequest insecure content in asynchronous mode. |
1615 | 1612 |
1616 // XMLHttpRequest over bad ssl in synchronous mode. | 1613 // XMLHttpRequest over bad ssl in synchronous mode. |
1617 | 1614 |
1618 // XMLHttpRequest over OK ssl in synchronous mode. | 1615 // XMLHttpRequest over OK ssl in synchronous mode. |
OLD | NEW |