| 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 "chrome/browser/safe_browsing/download_protection_service.h" | 5 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 true); | 448 true); |
| 449 | 449 |
| 450 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); | 450 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); |
| 451 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); | 451 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); |
| 452 std::vector<GURL> url_chain; | 452 std::vector<GURL> url_chain; |
| 453 url_chain.push_back(GURL("http://www.evil.com/a.exe")); | 453 url_chain.push_back(GURL("http://www.evil.com/a.exe")); |
| 454 GURL referrer("http://www.google.com/"); | 454 GURL referrer("http://www.google.com/"); |
| 455 std::string hash = "hash"; | 455 std::string hash = "hash"; |
| 456 | 456 |
| 457 content::MockDownloadItem item; | 457 content::MockDownloadItem item; |
| 458 EXPECT_CALL(item, AddObserver(_)).Times(5); | 458 EXPECT_CALL(item, AddObserver(_)).Times(6); |
| 459 EXPECT_CALL(item, RemoveObserver(_)).Times(5); | 459 EXPECT_CALL(item, RemoveObserver(_)).Times(6); |
| 460 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp)); | 460 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp)); |
| 461 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe)); | 461 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe)); |
| 462 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); | 462 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); |
| 463 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); | 463 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); |
| 464 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); | 464 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); |
| 465 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); | 465 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); |
| 466 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); | 466 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); |
| 467 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return("")); | 467 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return("")); |
| 468 | 468 |
| 469 EXPECT_CALL(*sb_service_->mock_database_manager(), | 469 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 470 MatchDownloadWhitelistUrl(_)) | 470 MatchDownloadWhitelistUrl(_)) |
| 471 .WillRepeatedly(Return(false)); | 471 .WillRepeatedly(Return(false)); |
| 472 EXPECT_CALL(*signature_util_.get(), CheckSignature(a_tmp, _)).Times(5); | 472 EXPECT_CALL(*signature_util_.get(), CheckSignature(a_tmp, _)).Times(6); |
| 473 | 473 |
| 474 download_service_->CheckClientDownload( | 474 download_service_->CheckClientDownload( |
| 475 &item, | 475 &item, |
| 476 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 476 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 477 base::Unretained(this))); | 477 base::Unretained(this))); |
| 478 MessageLoop::current()->Run(); | 478 MessageLoop::current()->Run(); |
| 479 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 479 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 480 | 480 |
| 481 // Invalid response should be safe too. | 481 // Invalid response should be safe too. |
| 482 response.Clear(); | 482 response.Clear(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 base::Unretained(this))); | 554 base::Unretained(this))); |
| 555 MessageLoop::current()->Run(); | 555 MessageLoop::current()->Run(); |
| 556 #if defined(OS_WIN) | 556 #if defined(OS_WIN) |
| 557 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS_HOST)); | 557 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS_HOST)); |
| 558 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 558 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
| 559 item, &feedback_ping, &feedback_response)); | 559 item, &feedback_ping, &feedback_response)); |
| 560 EXPECT_EQ(response.SerializeAsString(), feedback_response); | 560 EXPECT_EQ(response.SerializeAsString(), feedback_response); |
| 561 #else | 561 #else |
| 562 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 562 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 563 #endif | 563 #endif |
| 564 |
| 565 // If the response is POTENTIALLY_UNWANTED the result should also be marked as |
| 566 // POTENTIALLY_UNWANTED. |
| 567 response.set_verdict(ClientDownloadResponse::POTENTIALLY_UNWANTED); |
| 568 factory.SetFakeResponse( |
| 569 DownloadProtectionService::GetDownloadRequestUrl(), |
| 570 response.SerializeAsString(), |
| 571 true); |
| 572 |
| 573 download_service_->CheckClientDownload( |
| 574 &item, |
| 575 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 576 base::Unretained(this))); |
| 577 MessageLoop::current()->Run(); |
| 578 #if defined(OS_WIN) |
| 579 EXPECT_TRUE(IsResult(DownloadProtectionService::POTENTIALLY_UNWANTED)); |
| 580 #else |
| 581 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 582 #endif |
| 564 } | 583 } |
| 565 | 584 |
| 566 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { | 585 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { |
| 567 ClientDownloadResponse response; | 586 ClientDownloadResponse response; |
| 568 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 587 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
| 569 net::FakeURLFetcherFactory factory(NULL); | 588 net::FakeURLFetcherFactory factory(NULL); |
| 570 factory.SetFakeResponse( | 589 factory.SetFakeResponse( |
| 571 DownloadProtectionService::GetDownloadRequestUrl(), | 590 DownloadProtectionService::GetDownloadRequestUrl(), |
| 572 response.SerializeAsString(), | 591 response.SerializeAsString(), |
| 573 true); | 592 true); |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1151 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); | 1170 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); |
| 1152 | 1171 |
| 1153 cert = ReadTestCertificate("test_c.pem"); | 1172 cert = ReadTestCertificate("test_c.pem"); |
| 1154 ASSERT_TRUE(cert.get()); | 1173 ASSERT_TRUE(cert.get()); |
| 1155 whitelist_strings.clear(); | 1174 whitelist_strings.clear(); |
| 1156 GetCertificateWhitelistStrings( | 1175 GetCertificateWhitelistStrings( |
| 1157 *cert.get(), *issuer_cert.get(), &whitelist_strings); | 1176 *cert.get(), *issuer_cert.get(), &whitelist_strings); |
| 1158 EXPECT_THAT(whitelist_strings, ElementsAre()); | 1177 EXPECT_THAT(whitelist_strings, ElementsAre()); |
| 1159 } | 1178 } |
| 1160 } // namespace safe_browsing | 1179 } // namespace safe_browsing |
| OLD | NEW |