Chromium Code Reviews| 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 // This test creates a safebrowsing service using test safebrowsing database | 5 // This test creates a safebrowsing service using test safebrowsing database |
| 6 // and a test protocol manager. It is used to test logics in safebrowsing | 6 // and a test protocol manager. It is used to test logics in safebrowsing |
| 7 // service. | 7 // service. |
| 8 | 8 |
| 9 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 9 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 10 | 10 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 #include "crypto/sha2.h" | 70 #include "crypto/sha2.h" |
| 71 #include "net/cookies/cookie_store.h" | 71 #include "net/cookies/cookie_store.h" |
| 72 #include "net/cookies/cookie_util.h" | 72 #include "net/cookies/cookie_util.h" |
| 73 #include "net/test/embedded_test_server/embedded_test_server.h" | 73 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 74 #include "net/test/embedded_test_server/http_request.h" | 74 #include "net/test/embedded_test_server/http_request.h" |
| 75 #include "net/test/embedded_test_server/http_response.h" | 75 #include "net/test/embedded_test_server/http_response.h" |
| 76 #include "sql/connection.h" | 76 #include "sql/connection.h" |
| 77 #include "sql/statement.h" | 77 #include "sql/statement.h" |
| 78 #include "testing/gmock/include/gmock/gmock.h" | 78 #include "testing/gmock/include/gmock/gmock.h" |
| 79 #include "url/gurl.h" | 79 #include "url/gurl.h" |
| 80 #include "url/url_canon.h" | |
| 80 | 81 |
| 81 #if defined(OS_CHROMEOS) | 82 #if defined(OS_CHROMEOS) |
| 82 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 83 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 83 #include "chromeos/chromeos_switches.h" | 84 #include "chromeos/chromeos_switches.h" |
| 84 #endif | 85 #endif |
| 85 | 86 |
| 86 #if !defined(SAFE_BROWSING_DB_LOCAL) | 87 #if !defined(SAFE_BROWSING_DB_LOCAL) |
| 87 #error This test requires SAFE_BROWSING_DB_LOCAL. | 88 #error This test requires SAFE_BROWSING_DB_LOCAL. |
| 88 #endif | 89 #endif |
| 89 | 90 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 100 | 101 |
| 101 const char kBlacklistResource[] = "/blacklisted/script.js"; | 102 const char kBlacklistResource[] = "/blacklisted/script.js"; |
| 102 const char kEmptyPage[] = "/empty.html"; | 103 const char kEmptyPage[] = "/empty.html"; |
| 103 const char kMaliciousResource[] = "/malware/script.js"; | 104 const char kMaliciousResource[] = "/malware/script.js"; |
| 104 const char kMalwareFile[] = "/downloads/dangerous/dangerous.exe"; | 105 const char kMalwareFile[] = "/downloads/dangerous/dangerous.exe"; |
| 105 const char kMalwarePage[] = "/safe_browsing/malware.html"; | 106 const char kMalwarePage[] = "/safe_browsing/malware.html"; |
| 106 const char kMalwareDelayedLoadsPage[] = | 107 const char kMalwareDelayedLoadsPage[] = |
| 107 "/safe_browsing/malware_delayed_loads.html"; | 108 "/safe_browsing/malware_delayed_loads.html"; |
| 108 const char kMalwareIFrame[] = "/safe_browsing/malware_iframe.html"; | 109 const char kMalwareIFrame[] = "/safe_browsing/malware_iframe.html"; |
| 109 const char kMalwareImg[] = "/safe_browsing/malware_image.png"; | 110 const char kMalwareImg[] = "/safe_browsing/malware_image.png"; |
| 111 const char kMalwareWebSocketPage[] = "/safe_browsing/malware_websocket.html"; | |
| 110 const char kNeverCompletesPath[] = "/never_completes"; | 112 const char kNeverCompletesPath[] = "/never_completes"; |
| 111 const char kPrefetchMalwarePage[] = "/safe_browsing/prefetch_malware.html"; | 113 const char kPrefetchMalwarePage[] = "/safe_browsing/prefetch_malware.html"; |
| 112 | 114 |
| 113 class NeverCompletingHttpResponse : public net::test_server::HttpResponse { | 115 class NeverCompletingHttpResponse : public net::test_server::HttpResponse { |
| 114 public: | 116 public: |
| 115 ~NeverCompletingHttpResponse() override {} | 117 ~NeverCompletingHttpResponse() override {} |
| 116 | 118 |
| 117 void SendResponse( | 119 void SendResponse( |
| 118 const net::test_server::SendBytesCallback& send, | 120 const net::test_server::SendBytesCallback& send, |
| 119 const net::test_server::SendCompleteCallback& done) override { | 121 const net::test_server::SendCompleteCallback& done) override { |
| (...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1469 EXPECT_TRUE(csd_service->enabled()); | 1471 EXPECT_TRUE(csd_service->enabled()); |
| 1470 | 1472 |
| 1471 // Delete the Profile. SBS stops again. | 1473 // Delete the Profile. SBS stops again. |
| 1472 pref_service2 = nullptr; | 1474 pref_service2 = nullptr; |
| 1473 profile2.reset(); | 1475 profile2.reset(); |
| 1474 EXPECT_FALSE(sb_service->enabled_by_prefs()); | 1476 EXPECT_FALSE(sb_service->enabled_by_prefs()); |
| 1475 WaitForIOAndCheckEnabled(sb_service, false); | 1477 WaitForIOAndCheckEnabled(sb_service, false); |
| 1476 EXPECT_FALSE(csd_service->enabled()); | 1478 EXPECT_FALSE(csd_service->enabled()); |
| 1477 } | 1479 } |
| 1478 | 1480 |
| 1481 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, MalwareWebSocketBlocked) { | |
|
vakh (use Gerrit instead)
2017/06/20 21:40:27
Please add the corresponding tests for V4SafeBrows
Adam Rice
2017/06/21 09:18:47
Done. They're almost exact copies, but if the old
| |
| 1482 // This test currently only passes when the network service is enabled. | |
| 1483 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 1484 ::switches::kEnableNetworkService)) { | |
| 1485 GURL main_url = embedded_test_server()->GetURL(kMalwareWebSocketPage); | |
| 1486 // This constructs the URL with the same logic as malware_websocket.html. | |
| 1487 GURL resolved = main_url.Resolve("/safe_browsing/malware-ws"); | |
| 1488 GURL::Replacements replace_scheme; | |
| 1489 replace_scheme.SetScheme("ws", url::Component(0, strlen("ws"))); | |
| 1490 GURL websocket_url = resolved.ReplaceComponents(replace_scheme); | |
| 1491 | |
| 1492 // Add the WebSocket url as malware. | |
| 1493 SBFullHashResult uws_full_hash; | |
| 1494 GenUrlFullHashResult(websocket_url, MALWARE, &uws_full_hash); | |
| 1495 SetupResponseForUrl(websocket_url, uws_full_hash); | |
| 1496 | |
| 1497 // Brute force method for waiting for the interstitial to be displayed. | |
| 1498 content::WindowedNotificationObserver load_stop_observer( | |
| 1499 content::NOTIFICATION_ALL, | |
| 1500 base::Bind( | |
| 1501 [](SafeBrowsingServiceTest* self, | |
| 1502 const content::NotificationSource& source, | |
| 1503 const content::NotificationDetails& details) { | |
| 1504 return self->ShowingInterstitialPage(); | |
| 1505 }, | |
| 1506 base::Unretained(this))); | |
| 1507 | |
| 1508 EXPECT_CALL(observer_, | |
| 1509 OnSafeBrowsingHit(IsUnsafeResourceFor(websocket_url))); | |
| 1510 ui_test_utils::NavigateToURL(browser(), main_url); | |
| 1511 | |
| 1512 // If the interstitial fails to be displayed, the test will hang here. | |
| 1513 load_stop_observer.Wait(); | |
| 1514 | |
| 1515 EXPECT_TRUE(ShowingInterstitialPage()); | |
| 1516 EXPECT_TRUE(got_hit_report()); | |
| 1517 } | |
| 1518 } | |
| 1519 | |
| 1520 IN_PROC_BROWSER_TEST_F(SafeBrowsingServiceTest, UnknownWebSocketNotBlocked) { | |
| 1521 GURL main_url = embedded_test_server()->GetURL(kMalwareWebSocketPage); | |
| 1522 | |
| 1523 auto expected_title = base::ASCIIToUTF16("COMPLETED"); | |
| 1524 content::TitleWatcher title_watcher( | |
| 1525 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | |
| 1526 | |
| 1527 // Load the parent page without marking the WebSocket as malware. | |
| 1528 ui_test_utils::NavigateToURL(browser(), main_url); | |
| 1529 | |
| 1530 // Wait for the WebSocket connection attempt to complete. | |
| 1531 auto new_title = title_watcher.WaitAndGetTitle(); | |
| 1532 EXPECT_EQ(expected_title, new_title); | |
| 1533 EXPECT_FALSE(ShowingInterstitialPage()); | |
| 1534 EXPECT_FALSE(got_hit_report()); | |
| 1535 } | |
| 1536 | |
| 1479 class SafeBrowsingServiceShutdownTest : public SafeBrowsingServiceTest { | 1537 class SafeBrowsingServiceShutdownTest : public SafeBrowsingServiceTest { |
| 1480 public: | 1538 public: |
| 1481 void TearDown() override { | 1539 void TearDown() override { |
| 1482 // Browser should be fully torn down by now, so we can safely check these | 1540 // Browser should be fully torn down by now, so we can safely check these |
| 1483 // counters. | 1541 // counters. |
| 1484 EXPECT_EQ(1, TestProtocolManager::create_count()); | 1542 EXPECT_EQ(1, TestProtocolManager::create_count()); |
| 1485 EXPECT_EQ(1, TestProtocolManager::delete_count()); | 1543 EXPECT_EQ(1, TestProtocolManager::delete_count()); |
| 1486 | 1544 |
| 1487 SafeBrowsingServiceTest::TearDown(); | 1545 SafeBrowsingServiceTest::TearDown(); |
| 1488 } | 1546 } |
| (...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2356 } | 2414 } |
| 2357 | 2415 |
| 2358 INSTANTIATE_TEST_CASE_P( | 2416 INSTANTIATE_TEST_CASE_P( |
| 2359 MaybeSetMetadata, | 2417 MaybeSetMetadata, |
| 2360 V4SafeBrowsingServiceMetadataTest, | 2418 V4SafeBrowsingServiceMetadataTest, |
| 2361 testing::Values(ThreatPatternType::NONE, | 2419 testing::Values(ThreatPatternType::NONE, |
| 2362 ThreatPatternType::MALWARE_LANDING, | 2420 ThreatPatternType::MALWARE_LANDING, |
| 2363 ThreatPatternType::MALWARE_DISTRIBUTION)); | 2421 ThreatPatternType::MALWARE_DISTRIBUTION)); |
| 2364 | 2422 |
| 2365 } // namespace safe_browsing | 2423 } // namespace safe_browsing |
| OLD | NEW |