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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 #include "testing/gtest/include/gtest/gtest.h" | 59 #include "testing/gtest/include/gtest/gtest.h" |
60 #include "third_party/zlib/google/zip.h" | 60 #include "third_party/zlib/google/zip.h" |
61 #include "url/gurl.h" | 61 #include "url/gurl.h" |
62 | 62 |
63 using ::testing::Assign; | 63 using ::testing::Assign; |
64 using ::testing::ContainerEq; | 64 using ::testing::ContainerEq; |
65 using ::testing::DoAll; | 65 using ::testing::DoAll; |
66 using ::testing::ElementsAre; | 66 using ::testing::ElementsAre; |
67 using ::testing::Invoke; | 67 using ::testing::Invoke; |
68 using ::testing::Mock; | 68 using ::testing::Mock; |
| 69 using ::testing::NiceMock; |
69 using ::testing::NotNull; | 70 using ::testing::NotNull; |
70 using ::testing::Return; | 71 using ::testing::Return; |
71 using ::testing::ReturnRef; | 72 using ::testing::ReturnRef; |
72 using ::testing::SaveArg; | 73 using ::testing::SaveArg; |
73 using ::testing::StrictMock; | 74 using ::testing::StrictMock; |
74 using ::testing::_; | 75 using ::testing::_; |
75 using base::RunLoop; | 76 using base::RunLoop; |
76 using content::BrowserThread; | 77 using content::BrowserThread; |
77 | 78 |
78 namespace safe_browsing { | 79 namespace safe_browsing { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 run_loop_.Run(); | 187 run_loop_.Run(); |
187 return fetcher_id_; | 188 return fetcher_id_; |
188 } | 189 } |
189 | 190 |
190 private: | 191 private: |
191 net::TestURLFetcherFactory* factory_; | 192 net::TestURLFetcherFactory* factory_; |
192 int fetcher_id_; | 193 int fetcher_id_; |
193 RunLoop run_loop_; | 194 RunLoop run_loop_; |
194 }; | 195 }; |
195 | 196 |
| 197 using NiceMockDownloadItem = NiceMock<content::MockDownloadItem>; |
| 198 |
196 } // namespace | 199 } // namespace |
197 | 200 |
198 ACTION_P(SetCertificateContents, contents) { | 201 ACTION_P(SetCertificateContents, contents) { |
199 arg1->add_certificate_chain()->add_element()->set_certificate(contents); | 202 arg1->add_certificate_chain()->add_element()->set_certificate(contents); |
200 } | 203 } |
201 | 204 |
202 ACTION_P(SetDosHeaderContents, contents) { | 205 ACTION_P(SetDosHeaderContents, contents) { |
203 arg2->mutable_pe_headers()->set_dos_header(contents); | 206 arg2->mutable_pe_headers()->set_dos_header(contents); |
204 return true; | 207 return true; |
205 } | 208 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 ClientDownloadResponse response; | 402 ClientDownloadResponse response; |
400 response.set_verdict(verdict); | 403 response.set_verdict(verdict); |
401 response.set_upload(upload_requested); | 404 response.set_upload(upload_requested); |
402 factory->SetFakeResponse( | 405 factory->SetFakeResponse( |
403 DownloadProtectionService::GetDownloadRequestUrl(), | 406 DownloadProtectionService::GetDownloadRequestUrl(), |
404 response.SerializeAsString(), | 407 response.SerializeAsString(), |
405 response_code, status); | 408 response_code, status); |
406 } | 409 } |
407 | 410 |
408 void PrepareBasicDownloadItem( | 411 void PrepareBasicDownloadItem( |
409 content::MockDownloadItem* item, | 412 NiceMockDownloadItem* item, |
410 const std::vector<std::string> url_chain_items, | 413 const std::vector<std::string> url_chain_items, |
411 const std::string& referrer_url, | 414 const std::string& referrer_url, |
412 const base::FilePath::StringType& tmp_path_literal, | 415 const base::FilePath::StringType& tmp_path_literal, |
413 const base::FilePath::StringType& final_path_literal) { | 416 const base::FilePath::StringType& final_path_literal) { |
414 base::FilePath tmp_path = temp_dir_.GetPath().Append(tmp_path_literal); | 417 base::FilePath tmp_path = temp_dir_.GetPath().Append(tmp_path_literal); |
415 base::FilePath final_path = temp_dir_.GetPath().Append(final_path_literal); | 418 base::FilePath final_path = temp_dir_.GetPath().Append(final_path_literal); |
416 | 419 |
417 PrepareBasicDownloadItemWithFullPaths(item, url_chain_items, referrer_url, | 420 PrepareBasicDownloadItemWithFullPaths(item, url_chain_items, referrer_url, |
418 tmp_path, final_path); | 421 tmp_path, final_path); |
419 } | 422 } |
420 | 423 |
421 void PrepareBasicDownloadItemWithFullPaths( | 424 void PrepareBasicDownloadItemWithFullPaths( |
422 content::MockDownloadItem* item, | 425 NiceMockDownloadItem* item, |
423 const std::vector<std::string> url_chain_items, | 426 const std::vector<std::string> url_chain_items, |
424 const std::string& referrer_url, | 427 const std::string& referrer_url, |
425 const base::FilePath& tmp_full_path, | 428 const base::FilePath& tmp_full_path, |
426 const base::FilePath& final_full_path) { | 429 const base::FilePath& final_full_path) { |
427 url_chain_.clear(); | 430 url_chain_.clear(); |
428 for (std::string item: url_chain_items) | 431 for (std::string item: url_chain_items) |
429 url_chain_.push_back(GURL(item)); | 432 url_chain_.push_back(GURL(item)); |
| 433 if (url_chain_.empty()) |
| 434 url_chain_.push_back(GURL()); |
430 referrer_ = GURL(referrer_url); | 435 referrer_ = GURL(referrer_url); |
431 tmp_path_ = tmp_full_path; | 436 tmp_path_ = tmp_full_path; |
432 final_path_ = final_full_path; | 437 final_path_ = final_full_path; |
433 hash_ = "hash"; | 438 hash_ = "hash"; |
434 | 439 |
435 if (url_chain_.size() > 0) { | 440 EXPECT_CALL(*item, GetURL()).WillRepeatedly(ReturnRef(url_chain_.back())); |
436 EXPECT_CALL(*item, GetURL()).WillRepeatedly(ReturnRef(url_chain_.back())); | |
437 } else{ | |
438 GURL empty_url; | |
439 EXPECT_CALL(*item, GetURL()).WillRepeatedly(ReturnRef(empty_url)); | |
440 } | |
441 EXPECT_CALL(*item, GetFullPath()).WillRepeatedly(ReturnRef(tmp_path_)); | 441 EXPECT_CALL(*item, GetFullPath()).WillRepeatedly(ReturnRef(tmp_path_)); |
442 EXPECT_CALL(*item, GetTargetFilePath()) | 442 EXPECT_CALL(*item, GetTargetFilePath()) |
443 .WillRepeatedly(ReturnRef(final_path_)); | 443 .WillRepeatedly(ReturnRef(final_path_)); |
444 EXPECT_CALL(*item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain_)); | 444 EXPECT_CALL(*item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain_)); |
445 EXPECT_CALL(*item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer_)); | 445 EXPECT_CALL(*item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer_)); |
446 EXPECT_CALL(*item, GetTabUrl()) | 446 EXPECT_CALL(*item, GetTabUrl()) |
447 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); | 447 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); |
448 EXPECT_CALL(*item, GetTabReferrerUrl()) | 448 EXPECT_CALL(*item, GetTabReferrerUrl()) |
449 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); | 449 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); |
450 EXPECT_CALL(*item, GetHash()).WillRepeatedly(ReturnRef(hash_)); | 450 EXPECT_CALL(*item, GetHash()).WillRepeatedly(ReturnRef(hash_)); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; | 544 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; |
545 base::FilePath testdata_path_; | 545 base::FilePath testdata_path_; |
546 DownloadProtectionService::ClientDownloadRequestSubscription | 546 DownloadProtectionService::ClientDownloadRequestSubscription |
547 client_download_request_subscription_; | 547 client_download_request_subscription_; |
548 DownloadProtectionService::PPAPIDownloadRequestSubscription | 548 DownloadProtectionService::PPAPIDownloadRequestSubscription |
549 ppapi_download_request_subscription_; | 549 ppapi_download_request_subscription_; |
550 std::unique_ptr<ClientDownloadRequest> last_client_download_request_; | 550 std::unique_ptr<ClientDownloadRequest> last_client_download_request_; |
551 base::ScopedTempDir profile_dir_; | 551 base::ScopedTempDir profile_dir_; |
552 std::unique_ptr<TestingProfile> profile_; | 552 std::unique_ptr<TestingProfile> profile_; |
553 // The following 5 fields are used by PrepareBasicDownloadItem() function to | 553 // The following 5 fields are used by PrepareBasicDownloadItem() function to |
554 // store attributes of the last download item. | 554 // store attributes of the last download item. They can be modified |
| 555 // afterwards and the *item will return the new values. |
555 std::vector<GURL> url_chain_; | 556 std::vector<GURL> url_chain_; |
556 GURL referrer_; | 557 GURL referrer_; |
557 base::FilePath tmp_path_; | 558 base::FilePath tmp_path_; |
558 base::FilePath final_path_; | 559 base::FilePath final_path_; |
559 std::string hash_; | 560 std::string hash_; |
560 base::ScopedTempDir temp_dir_; | 561 base::ScopedTempDir temp_dir_; |
561 }; | 562 }; |
562 | 563 |
563 void DownloadProtectionServiceTest::CheckClientDownloadReportCorruptArchive( | 564 void DownloadProtectionServiceTest::CheckClientDownloadReportCorruptArchive( |
564 ArchiveType type) { | 565 ArchiveType type) { |
565 net::FakeURLFetcherFactory factory(NULL); | 566 net::FakeURLFetcherFactory factory(NULL); |
566 PrepareResponse( | 567 PrepareResponse( |
567 &factory, ClientDownloadResponse::SAFE, net::HTTP_OK, | 568 &factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
568 net::URLRequestStatus::SUCCESS); | 569 net::URLRequestStatus::SUCCESS); |
569 | 570 |
570 content::MockDownloadItem item; | 571 NiceMockDownloadItem item; |
571 if (type == ZIP) { | 572 if (type == ZIP) { |
572 PrepareBasicDownloadItem(&item, {"http://www.evil.com/a.zip"}, // url_chain | 573 PrepareBasicDownloadItem(&item, {"http://www.evil.com/a.zip"}, // url_chain |
573 "http://www.google.com/", // referrer | 574 "http://www.google.com/", // referrer |
574 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 575 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
575 FILE_PATH_LITERAL("a.zip")); // final_path | 576 FILE_PATH_LITERAL("a.zip")); // final_path |
576 } else if (type == DMG) { | 577 } else if (type == DMG) { |
577 PrepareBasicDownloadItem(&item, {"http://www.evil.com/a.dmg"}, // url_chain | 578 PrepareBasicDownloadItem(&item, {"http://www.evil.com/a.dmg"}, // url_chain |
578 "http://www.google.com/", // referrer | 579 "http://www.google.com/", // referrer |
579 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 580 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
580 FILE_PATH_LITERAL("a.dmg")); // final_path | 581 FILE_PATH_LITERAL("a.dmg")); // final_path |
(...skipping 17 matching lines...) Expand all Loading... |
598 type == ZIP ? ClientDownloadRequest_DownloadType_INVALID_ZIP | 599 type == ZIP ? ClientDownloadRequest_DownloadType_INVALID_ZIP |
599 : ClientDownloadRequest_DownloadType_INVALID_MAC_ARCHIVE; | 600 : ClientDownloadRequest_DownloadType_INVALID_MAC_ARCHIVE; |
600 EXPECT_EQ(expected_type, GetClientDownloadRequest()->download_type()); | 601 EXPECT_EQ(expected_type, GetClientDownloadRequest()->download_type()); |
601 ClearClientDownloadRequest(); | 602 ClearClientDownloadRequest(); |
602 | 603 |
603 Mock::VerifyAndClearExpectations(sb_service_.get()); | 604 Mock::VerifyAndClearExpectations(sb_service_.get()); |
604 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 605 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
605 } | 606 } |
606 | 607 |
607 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { | 608 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { |
608 content::MockDownloadItem item; | 609 NiceMockDownloadItem item; |
609 { | 610 { |
610 PrepareBasicDownloadItem(&item, | 611 PrepareBasicDownloadItem(&item, |
611 std::vector<std::string>(), // empty url_chain | 612 std::vector<std::string>(), // empty url_chain |
612 "http://www.google.com/", // referrer | 613 "http://www.google.com/", // referrer |
613 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 614 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
614 FILE_PATH_LITERAL("a.exe")); // final_path | 615 FILE_PATH_LITERAL("a.exe")); // final_path |
615 RunLoop run_loop; | 616 RunLoop run_loop; |
616 download_service_->CheckClientDownload( | 617 download_service_->CheckClientDownload( |
617 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 618 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
618 base::Unretained(this), run_loop.QuitClosure())); | 619 base::Unretained(this), run_loop.QuitClosure())); |
(...skipping 12 matching lines...) Expand all Loading... |
631 download_service_->CheckClientDownload( | 632 download_service_->CheckClientDownload( |
632 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 633 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
633 base::Unretained(this), run_loop.QuitClosure())); | 634 base::Unretained(this), run_loop.QuitClosure())); |
634 run_loop.Run(); | 635 run_loop.Run(); |
635 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 636 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
636 EXPECT_FALSE(HasClientDownloadRequest()); | 637 EXPECT_FALSE(HasClientDownloadRequest()); |
637 } | 638 } |
638 } | 639 } |
639 | 640 |
640 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadNotABinary) { | 641 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadNotABinary) { |
641 content::MockDownloadItem item; | 642 NiceMockDownloadItem item; |
642 PrepareBasicDownloadItem( | 643 PrepareBasicDownloadItem( |
643 &item, | 644 &item, |
644 std::vector<std::string>(), // empty url_chain | 645 std::vector<std::string>(), // empty url_chain |
645 "http://www.google.com/", // referrer | 646 "http://www.google.com/", // referrer |
646 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 647 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
647 FILE_PATH_LITERAL("a.txt")); // final_path | 648 FILE_PATH_LITERAL("a.txt")); // final_path |
648 RunLoop run_loop; | 649 RunLoop run_loop; |
649 download_service_->CheckClientDownload( | 650 download_service_->CheckClientDownload( |
650 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 651 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
651 base::Unretained(this), run_loop.QuitClosure())); | 652 base::Unretained(this), run_loop.QuitClosure())); |
652 run_loop.Run(); | 653 run_loop.Run(); |
653 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 654 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
654 EXPECT_FALSE(HasClientDownloadRequest()); | 655 EXPECT_FALSE(HasClientDownloadRequest()); |
655 } | 656 } |
656 | 657 |
657 TEST_F(DownloadProtectionServiceTest, | 658 TEST_F(DownloadProtectionServiceTest, |
658 CheckClientDownloadWhitelistedUrlWithoutSampling) { | 659 CheckClientDownloadWhitelistedUrlWithoutSampling) { |
659 // Response to any requests will be DANGEROUS. | 660 // Response to any requests will be DANGEROUS. |
660 net::FakeURLFetcherFactory factory(NULL); | 661 net::FakeURLFetcherFactory factory(NULL); |
661 PrepareResponse( | 662 PrepareResponse( |
662 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, | 663 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
663 net::URLRequestStatus::SUCCESS); | 664 net::URLRequestStatus::SUCCESS); |
664 | 665 |
665 content::MockDownloadItem item; | 666 NiceMockDownloadItem item; |
666 PrepareBasicDownloadItem( | 667 PrepareBasicDownloadItem( |
667 &item, | 668 &item, |
668 std::vector<std::string>(), // empty url_chain | 669 std::vector<std::string>(), // empty url_chain |
669 "", // referrer | 670 "", // referrer |
670 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 671 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
671 FILE_PATH_LITERAL("a.exe")); // final_path | 672 FILE_PATH_LITERAL("a.exe")); // final_path |
672 | 673 |
673 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)) | 674 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)) |
674 .Times(4); | 675 .Times(4); |
675 EXPECT_CALL(*binary_feature_extractor_.get(), | 676 EXPECT_CALL(*binary_feature_extractor_.get(), |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 | 752 |
752 TEST_F(DownloadProtectionServiceTest, | 753 TEST_F(DownloadProtectionServiceTest, |
753 CheckClientDownloadWhitelistedUrlWithSampling) { | 754 CheckClientDownloadWhitelistedUrlWithSampling) { |
754 // Server responses "SAFE" to every requests coming from whitelisted | 755 // Server responses "SAFE" to every requests coming from whitelisted |
755 // download. | 756 // download. |
756 net::FakeURLFetcherFactory factory(NULL); | 757 net::FakeURLFetcherFactory factory(NULL); |
757 PrepareResponse( | 758 PrepareResponse( |
758 &factory, ClientDownloadResponse::SAFE, net::HTTP_OK, | 759 &factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
759 net::URLRequestStatus::SUCCESS); | 760 net::URLRequestStatus::SUCCESS); |
760 | 761 |
761 content::MockDownloadItem item; | 762 NiceMockDownloadItem item; |
762 PrepareBasicDownloadItem( | 763 PrepareBasicDownloadItem( |
763 &item, | 764 &item, |
764 std::vector<std::string>(), // empty url_chain | 765 std::vector<std::string>(), // empty url_chain |
765 "http://www.google.com/", // referrer | 766 "http://www.google.com/", // referrer |
766 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 767 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
767 FILE_PATH_LITERAL("a.exe")); // final_path | 768 FILE_PATH_LITERAL("a.exe")); // final_path |
768 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)) | 769 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)) |
769 .Times(4); | 770 .Times(4); |
770 EXPECT_CALL(*binary_feature_extractor_.get(), | 771 EXPECT_CALL(*binary_feature_extractor_.get(), |
771 ExtractImageFeatures( | 772 ExtractImageFeatures( |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 } | 902 } |
902 } | 903 } |
903 | 904 |
904 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSampledFile) { | 905 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSampledFile) { |
905 // Server response will be discarded. | 906 // Server response will be discarded. |
906 net::FakeURLFetcherFactory factory(NULL); | 907 net::FakeURLFetcherFactory factory(NULL); |
907 PrepareResponse( | 908 PrepareResponse( |
908 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, | 909 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
909 net::URLRequestStatus::SUCCESS); | 910 net::URLRequestStatus::SUCCESS); |
910 | 911 |
911 content::MockDownloadItem item; | 912 NiceMockDownloadItem item; |
912 PrepareBasicDownloadItem( | 913 PrepareBasicDownloadItem( |
913 &item, | 914 &item, |
914 std::vector<std::string>(), // empty url_chain | 915 // Add paths so we can check they are properly removed. |
915 "http://www.google.com/", // referrer | 916 {"http://referrer.com/1/2", "http://referrer.com/3/4", |
916 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 917 "http://download.com/path/a.foobar_unknown_type"}, |
917 FILE_PATH_LITERAL("a.foobar_unknown_ype")); // final_path | 918 "http://referrer.com/3/4", // Referrer |
| 919 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
| 920 FILE_PATH_LITERAL("a.foobar_unknown_type")); // final_path |
918 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)) | 921 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)) |
919 .Times(1); | 922 .Times(1); |
920 EXPECT_CALL(*binary_feature_extractor_.get(), | 923 EXPECT_CALL(*binary_feature_extractor_.get(), |
921 ExtractImageFeatures( | 924 ExtractImageFeatures( |
922 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)) | 925 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)) |
923 .Times(1); | 926 .Times(1); |
924 url_chain_.push_back(GURL("http://www.whitelist.com/a.foobar_unknown_type")); | |
925 | 927 |
926 // Set ping sample rate to 1.00 so download_service_ will always send a | 928 // Set ping sample rate to 1.00 so download_service_ will always send a |
927 // "light" ping for unknown types if allowed. | 929 // "light" ping for unknown types if allowed. |
928 SetBinarySamplingProbability(1.0); | 930 SetBinarySamplingProbability(1.0); |
929 | 931 |
930 { | 932 { |
931 // Case (1): is_extended_reporting && is_incognito. | 933 // Case (1): is_extended_reporting && is_incognito. |
932 // ClientDownloadRequest should NOT be sent. | 934 // ClientDownloadRequest should NOT be sent. |
933 SetExtendedReportingPreference(true); | 935 SetExtendedReportingPreference(true); |
934 EXPECT_CALL(item, GetBrowserContext()) | 936 EXPECT_CALL(item, GetBrowserContext()) |
(...skipping 11 matching lines...) Expand all Loading... |
946 // A "light" ClientDownloadRequest should be sent. | 948 // A "light" ClientDownloadRequest should be sent. |
947 EXPECT_CALL(item, GetBrowserContext()) | 949 EXPECT_CALL(item, GetBrowserContext()) |
948 .WillRepeatedly(Return(profile_.get())); | 950 .WillRepeatedly(Return(profile_.get())); |
949 RunLoop run_loop; | 951 RunLoop run_loop; |
950 download_service_->CheckClientDownload( | 952 download_service_->CheckClientDownload( |
951 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 953 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
952 base::Unretained(this), run_loop.QuitClosure())); | 954 base::Unretained(this), run_loop.QuitClosure())); |
953 run_loop.Run(); | 955 run_loop.Run(); |
954 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 956 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
955 ASSERT_TRUE(HasClientDownloadRequest()); | 957 ASSERT_TRUE(HasClientDownloadRequest()); |
956 // Verify it's a "light" ping, check that URLs don't have paths, and | 958 |
957 // and verify filename is just an extension. | 959 // Verify it's a "light" ping, check that URLs don't have paths. |
958 auto* req = GetClientDownloadRequest(); | 960 auto* req = GetClientDownloadRequest(); |
959 EXPECT_EQ(ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE, | 961 EXPECT_EQ(ClientDownloadRequest::SAMPLED_UNSUPPORTED_FILE, |
960 req->download_type()); | 962 req->download_type()); |
961 EXPECT_EQ(GURL(req->url()).GetOrigin().spec(), req->url()); | 963 EXPECT_EQ(GURL(req->url()).GetOrigin().spec(), req->url()); |
962 for (auto resource : req->resources()) { | 964 for (auto resource : req->resources()) { |
963 EXPECT_EQ(GURL(resource.url()).GetOrigin().spec(), resource.url()); | 965 EXPECT_EQ(GURL(resource.url()).GetOrigin().spec(), resource.url()); |
964 EXPECT_EQ(GURL(resource.referrer()).GetOrigin().spec(), | 966 EXPECT_EQ(GURL(resource.referrer()).GetOrigin().spec(), |
965 resource.referrer()); | 967 resource.referrer()); |
966 } | 968 } |
967 EXPECT_EQ('.', req->file_basename()[0]); | |
968 ClearClientDownloadRequest(); | 969 ClearClientDownloadRequest(); |
969 } | 970 } |
970 { | 971 { |
971 // Case (3): !is_extended_reporting && is_incognito. | 972 // Case (3): !is_extended_reporting && is_incognito. |
972 // ClientDownloadRequest should NOT be sent. | 973 // ClientDownloadRequest should NOT be sent. |
973 SetExtendedReportingPreference(false); | 974 SetExtendedReportingPreference(false); |
974 EXPECT_CALL(item, GetBrowserContext()) | 975 EXPECT_CALL(item, GetBrowserContext()) |
975 .WillRepeatedly(Return(profile_->GetOffTheRecordProfile())); | 976 .WillRepeatedly(Return(profile_->GetOffTheRecordProfile())); |
976 RunLoop run_loop; | 977 RunLoop run_loop; |
977 download_service_->CheckClientDownload( | 978 download_service_->CheckClientDownload( |
(...skipping 18 matching lines...) Expand all Loading... |
996 } | 997 } |
997 } | 998 } |
998 | 999 |
999 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { | 1000 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { |
1000 // HTTP request will fail. | 1001 // HTTP request will fail. |
1001 net::FakeURLFetcherFactory factory(NULL); | 1002 net::FakeURLFetcherFactory factory(NULL); |
1002 PrepareResponse( | 1003 PrepareResponse( |
1003 &factory, ClientDownloadResponse::SAFE, net::HTTP_INTERNAL_SERVER_ERROR, | 1004 &factory, ClientDownloadResponse::SAFE, net::HTTP_INTERNAL_SERVER_ERROR, |
1004 net::URLRequestStatus::FAILED); | 1005 net::URLRequestStatus::FAILED); |
1005 | 1006 |
1006 content::MockDownloadItem item; | 1007 NiceMockDownloadItem item; |
1007 PrepareBasicDownloadItem( | 1008 PrepareBasicDownloadItem( |
1008 &item, | 1009 &item, |
1009 {"http://www.evil.com/a.exe"}, // url_chain | 1010 {"http://www.evil.com/a.exe"}, // url_chain |
1010 "http://www.google.com/", // referrer | 1011 "http://www.google.com/", // referrer |
1011 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 1012 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
1012 FILE_PATH_LITERAL("a.exe")); // final_path | 1013 FILE_PATH_LITERAL("a.exe")); // final_path |
1013 | 1014 |
1014 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1015 EXPECT_CALL(*sb_service_->mock_database_manager(), |
1015 MatchDownloadWhitelistUrl(_)) | 1016 MatchDownloadWhitelistUrl(_)) |
1016 .WillRepeatedly(Return(false)); | 1017 .WillRepeatedly(Return(false)); |
1017 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)); | 1018 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)); |
1018 EXPECT_CALL( | 1019 EXPECT_CALL( |
1019 *binary_feature_extractor_.get(), | 1020 *binary_feature_extractor_.get(), |
1020 ExtractImageFeatures(tmp_path_, BinaryFeatureExtractor::kDefaultOptions, | 1021 ExtractImageFeatures(tmp_path_, BinaryFeatureExtractor::kDefaultOptions, |
1021 _, _)); | 1022 _, _)); |
1022 RunLoop run_loop; | 1023 RunLoop run_loop; |
1023 download_service_->CheckClientDownload( | 1024 download_service_->CheckClientDownload( |
1024 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1025 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
1025 base::Unretained(this), run_loop.QuitClosure())); | 1026 base::Unretained(this), run_loop.QuitClosure())); |
1026 run_loop.Run(); | 1027 run_loop.Run(); |
1027 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1028 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
1028 } | 1029 } |
1029 | 1030 |
1030 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) { | 1031 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) { |
1031 net::FakeURLFetcherFactory factory(NULL); | 1032 net::FakeURLFetcherFactory factory(NULL); |
1032 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, | 1033 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
1033 net::URLRequestStatus::SUCCESS); | 1034 net::URLRequestStatus::SUCCESS); |
1034 | 1035 |
1035 content::MockDownloadItem item; | 1036 NiceMockDownloadItem item; |
1036 PrepareBasicDownloadItem(&item, {"http://www.evil.com/a.exe"}, // url_chain | 1037 PrepareBasicDownloadItem(&item, {"http://www.evil.com/a.exe"}, // url_chain |
1037 "http://www.google.com/", // referrer | 1038 "http://www.google.com/", // referrer |
1038 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 1039 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
1039 FILE_PATH_LITERAL("a.exe")); // final_path | 1040 FILE_PATH_LITERAL("a.exe")); // final_path |
1040 | 1041 |
1041 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1042 EXPECT_CALL(*sb_service_->mock_database_manager(), |
1042 MatchDownloadWhitelistUrl(_)) | 1043 MatchDownloadWhitelistUrl(_)) |
1043 .WillRepeatedly(Return(false)); | 1044 .WillRepeatedly(Return(false)); |
1044 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)) | 1045 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)) |
1045 .Times(8); | 1046 .Times(8); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 ClearClientDownloadRequest(); | 1184 ClearClientDownloadRequest(); |
1184 } | 1185 } |
1185 } | 1186 } |
1186 | 1187 |
1187 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { | 1188 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { |
1188 net::FakeURLFetcherFactory factory(NULL); | 1189 net::FakeURLFetcherFactory factory(NULL); |
1189 PrepareResponse( | 1190 PrepareResponse( |
1190 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, | 1191 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
1191 net::URLRequestStatus::SUCCESS); | 1192 net::URLRequestStatus::SUCCESS); |
1192 | 1193 |
1193 content::MockDownloadItem item; | 1194 NiceMockDownloadItem item; |
1194 PrepareBasicDownloadItem(&item, | 1195 PrepareBasicDownloadItem(&item, |
1195 {"http://www.evil.com/a.exe"}, // url_chain | 1196 {"http://www.evil.com/a.exe"}, // url_chain |
1196 "http://www.google.com/", // referrer | 1197 "http://www.google.com/", // referrer |
1197 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 1198 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
1198 FILE_PATH_LITERAL("a.exe")); // final_path | 1199 FILE_PATH_LITERAL("a.exe")); // final_path |
1199 | 1200 |
1200 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1201 EXPECT_CALL(*sb_service_->mock_database_manager(), |
1201 MatchDownloadWhitelistUrl(_)) | 1202 MatchDownloadWhitelistUrl(_)) |
1202 .WillRepeatedly(Return(false)); | 1203 .WillRepeatedly(Return(false)); |
1203 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)) | 1204 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)) |
(...skipping 12 matching lines...) Expand all Loading... |
1216 EXPECT_TRUE(HasClientDownloadRequest()); | 1217 EXPECT_TRUE(HasClientDownloadRequest()); |
1217 ClearClientDownloadRequest(); | 1218 ClearClientDownloadRequest(); |
1218 } | 1219 } |
1219 | 1220 |
1220 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadBlob) { | 1221 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadBlob) { |
1221 net::FakeURLFetcherFactory factory(NULL); | 1222 net::FakeURLFetcherFactory factory(NULL); |
1222 PrepareResponse( | 1223 PrepareResponse( |
1223 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, | 1224 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
1224 net::URLRequestStatus::SUCCESS); | 1225 net::URLRequestStatus::SUCCESS); |
1225 | 1226 |
1226 content::MockDownloadItem item; | 1227 NiceMockDownloadItem item; |
1227 PrepareBasicDownloadItem( | 1228 PrepareBasicDownloadItem( |
1228 &item, | 1229 &item, |
1229 {"blob:http://www.evil.com/50b85f60-71e4-11e4-82f8-0800200c9a66"}, | 1230 {"blob:http://www.evil.com/50b85f60-71e4-11e4-82f8-0800200c9a66"}, |
1230 "http://www.google.com/", // referrer | 1231 "http://www.google.com/", // referrer |
1231 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 1232 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
1232 FILE_PATH_LITERAL("a.exe")); // final_path | 1233 FILE_PATH_LITERAL("a.exe")); // final_path |
1233 | 1234 |
1234 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1235 EXPECT_CALL(*sb_service_->mock_database_manager(), |
1235 MatchDownloadWhitelistUrl(_)).WillRepeatedly(Return(false)); | 1236 MatchDownloadWhitelistUrl(_)).WillRepeatedly(Return(false)); |
1236 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)) | 1237 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)) |
(...skipping 13 matching lines...) Expand all Loading... |
1250 EXPECT_TRUE(HasClientDownloadRequest()); | 1251 EXPECT_TRUE(HasClientDownloadRequest()); |
1251 ClearClientDownloadRequest(); | 1252 ClearClientDownloadRequest(); |
1252 } | 1253 } |
1253 | 1254 |
1254 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadData) { | 1255 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadData) { |
1255 net::FakeURLFetcherFactory factory(NULL); | 1256 net::FakeURLFetcherFactory factory(NULL); |
1256 PrepareResponse( | 1257 PrepareResponse( |
1257 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, | 1258 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
1258 net::URLRequestStatus::SUCCESS); | 1259 net::URLRequestStatus::SUCCESS); |
1259 | 1260 |
1260 content::MockDownloadItem item; | 1261 NiceMockDownloadItem item; |
1261 PrepareBasicDownloadItem( | 1262 PrepareBasicDownloadItem( |
1262 &item, | 1263 &item, |
1263 {"data:text/html:base64,", "data:text/html:base64,blahblahblah", | 1264 {"data:text/html:base64,", "data:text/html:base64,blahblahblah", |
1264 "data:application/octet-stream:base64,blahblah"}, // url_chain | 1265 "data:application/octet-stream:base64,blahblah"}, // url_chain |
1265 "data:text/html:base64,foobar", // referrer | 1266 "data:text/html:base64,foobar", // referrer |
1266 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 1267 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
1267 FILE_PATH_LITERAL("a.exe")); // final_path | 1268 FILE_PATH_LITERAL("a.exe")); // final_path |
1268 | 1269 |
1269 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1270 EXPECT_CALL(*sb_service_->mock_database_manager(), |
1270 MatchDownloadWhitelistUrl(_)).WillRepeatedly(Return(false)); | 1271 MatchDownloadWhitelistUrl(_)).WillRepeatedly(Return(false)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 kExpectedUrl, kExpectedReferrer)); | 1309 kExpectedUrl, kExpectedReferrer)); |
1309 ClearClientDownloadRequest(); | 1310 ClearClientDownloadRequest(); |
1310 } | 1311 } |
1311 | 1312 |
1312 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) { | 1313 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) { |
1313 net::FakeURLFetcherFactory factory(NULL); | 1314 net::FakeURLFetcherFactory factory(NULL); |
1314 PrepareResponse( | 1315 PrepareResponse( |
1315 &factory, ClientDownloadResponse::SAFE, net::HTTP_OK, | 1316 &factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
1316 net::URLRequestStatus::SUCCESS); | 1317 net::URLRequestStatus::SUCCESS); |
1317 | 1318 |
1318 content::MockDownloadItem item; | 1319 NiceMockDownloadItem item; |
1319 PrepareBasicDownloadItem( | 1320 PrepareBasicDownloadItem( |
1320 &item, | 1321 &item, |
1321 {"http://www.evil.com/a.zip"}, // url_chain | 1322 {"http://www.evil.com/a.zip"}, // url_chain |
1322 "http://www.google.com/", // referrer | 1323 "http://www.google.com/", // referrer |
1323 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 1324 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
1324 FILE_PATH_LITERAL("a.zip")); // final_path | 1325 FILE_PATH_LITERAL("a.zip")); // final_path |
1325 | 1326 |
1326 // Write out a zip archive to the temporary file. | 1327 // Write out a zip archive to the temporary file. |
1327 base::ScopedTempDir zip_source_dir; | 1328 base::ScopedTempDir zip_source_dir; |
1328 ASSERT_TRUE(zip_source_dir.CreateUniqueTempDir()); | 1329 ASSERT_TRUE(zip_source_dir.CreateUniqueTempDir()); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1440 #if defined(OS_MACOSX) | 1441 #if defined(OS_MACOSX) |
1441 TEST_F(DownloadProtectionServiceTest, | 1442 TEST_F(DownloadProtectionServiceTest, |
1442 CheckClientDownloadReportCorruptDmg) { | 1443 CheckClientDownloadReportCorruptDmg) { |
1443 CheckClientDownloadReportCorruptArchive(DMG); | 1444 CheckClientDownloadReportCorruptArchive(DMG); |
1444 } | 1445 } |
1445 #endif | 1446 #endif |
1446 | 1447 |
1447 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { | 1448 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { |
1448 net::TestURLFetcherFactory factory; | 1449 net::TestURLFetcherFactory factory; |
1449 | 1450 |
1450 content::MockDownloadItem item; | 1451 NiceMockDownloadItem item; |
1451 PrepareBasicDownloadItem( | 1452 PrepareBasicDownloadItem( |
1452 &item, | 1453 &item, |
1453 {"http://www.google.com/", | 1454 {"http://www.google.com/", |
1454 "http://www.google.com/bla.exe"}, // url_chain | 1455 "http://www.google.com/bla.exe"}, // url_chain |
1455 "http://www.google.com/", // referrer | 1456 "http://www.google.com/", // referrer |
1456 FILE_PATH_LITERAL("bla.tmp"), // tmp_path | 1457 FILE_PATH_LITERAL("bla.tmp"), // tmp_path |
1457 FILE_PATH_LITERAL("bla.exe")); // final_path | 1458 FILE_PATH_LITERAL("bla.exe")); // final_path |
1458 | 1459 |
1459 std::string remote_address = "10.11.12.13"; | 1460 std::string remote_address = "10.11.12.13"; |
1460 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address)); | 1461 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address)); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 base::BindOnce(&DownloadProtectionServiceTest::SendURLFetchComplete, | 1515 base::BindOnce(&DownloadProtectionServiceTest::SendURLFetchComplete, |
1515 base::Unretained(this), fetcher)); | 1516 base::Unretained(this), fetcher)); |
1516 run_loop.Run(); | 1517 run_loop.Run(); |
1517 } | 1518 } |
1518 | 1519 |
1519 // Similar to above, but with an unsigned binary. | 1520 // Similar to above, but with an unsigned binary. |
1520 TEST_F(DownloadProtectionServiceTest, | 1521 TEST_F(DownloadProtectionServiceTest, |
1521 CheckClientDownloadValidateRequestNoSignature) { | 1522 CheckClientDownloadValidateRequestNoSignature) { |
1522 net::TestURLFetcherFactory factory; | 1523 net::TestURLFetcherFactory factory; |
1523 | 1524 |
1524 content::MockDownloadItem item; | 1525 NiceMockDownloadItem item; |
1525 PrepareBasicDownloadItem( | 1526 PrepareBasicDownloadItem( |
1526 &item, | 1527 &item, |
1527 {"http://www.google.com/", | 1528 {"http://www.google.com/", |
1528 "ftp://www.google.com/bla.exe"}, // url_chain | 1529 "ftp://www.google.com/bla.exe"}, // url_chain |
1529 "http://www.google.com/", // referrer | 1530 "http://www.google.com/", // referrer |
1530 FILE_PATH_LITERAL("bla.tmp"), // tmp_path | 1531 FILE_PATH_LITERAL("bla.tmp"), // tmp_path |
1531 FILE_PATH_LITERAL("bla.exe")); // final_path | 1532 FILE_PATH_LITERAL("bla.exe")); // final_path |
1532 std::string remote_address = "10.11.12.13"; | 1533 std::string remote_address = "10.11.12.13"; |
1533 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address)); | 1534 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address)); |
1534 | 1535 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1574 base::BindOnce(&DownloadProtectionServiceTest::SendURLFetchComplete, | 1575 base::BindOnce(&DownloadProtectionServiceTest::SendURLFetchComplete, |
1575 base::Unretained(this), fetcher)); | 1576 base::Unretained(this), fetcher)); |
1576 run_loop.Run(); | 1577 run_loop.Run(); |
1577 } | 1578 } |
1578 | 1579 |
1579 // Similar to above, but with tab history. | 1580 // Similar to above, but with tab history. |
1580 TEST_F(DownloadProtectionServiceTest, | 1581 TEST_F(DownloadProtectionServiceTest, |
1581 CheckClientDownloadValidateRequestTabHistory) { | 1582 CheckClientDownloadValidateRequestTabHistory) { |
1582 net::TestURLFetcherFactory factory; | 1583 net::TestURLFetcherFactory factory; |
1583 | 1584 |
1584 content::MockDownloadItem item; | 1585 NiceMockDownloadItem item; |
1585 PrepareBasicDownloadItem( | 1586 PrepareBasicDownloadItem( |
1586 &item, | 1587 &item, |
1587 {"http://www.google.com/", | 1588 {"http://www.google.com/", |
1588 "http://www.google.com/bla.exe"}, // url_chain | 1589 "http://www.google.com/bla.exe"}, // url_chain |
1589 "http://www.google.com/", // referrer | 1590 "http://www.google.com/", // referrer |
1590 FILE_PATH_LITERAL("bla.tmp"), // tmp_path | 1591 FILE_PATH_LITERAL("bla.tmp"), // tmp_path |
1591 FILE_PATH_LITERAL("bla.exe")); // final_path | 1592 FILE_PATH_LITERAL("bla.exe")); // final_path |
1592 | 1593 |
1593 GURL tab_url("http://tab.com/final"); | 1594 GURL tab_url("http://tab.com/final"); |
1594 GURL tab_referrer("http://tab.com/referrer"); | 1595 GURL tab_referrer("http://tab.com/referrer"); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1739 | 1740 |
1740 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) { | 1741 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) { |
1741 net::TestURLFetcherFactory factory; | 1742 net::TestURLFetcherFactory factory; |
1742 | 1743 |
1743 std::vector<GURL> url_chain; | 1744 std::vector<GURL> url_chain; |
1744 url_chain.push_back(GURL("http://www.google.com/")); | 1745 url_chain.push_back(GURL("http://www.google.com/")); |
1745 url_chain.push_back(GURL("http://www.google.com/bla.exe")); | 1746 url_chain.push_back(GURL("http://www.google.com/bla.exe")); |
1746 GURL referrer("http://www.google.com/"); | 1747 GURL referrer("http://www.google.com/"); |
1747 std::string hash = "hash"; | 1748 std::string hash = "hash"; |
1748 | 1749 |
1749 content::MockDownloadItem item; | 1750 NiceMockDownloadItem item; |
1750 EXPECT_CALL(item, GetURL()).WillRepeatedly(ReturnRef(url_chain.back())); | 1751 EXPECT_CALL(item, GetURL()).WillRepeatedly(ReturnRef(url_chain.back())); |
1751 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); | 1752 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); |
1752 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); | 1753 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); |
1753 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); | 1754 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); |
1754 | 1755 |
1755 { | 1756 { |
1756 // CheckDownloadURL returns immediately which means the client object | 1757 // CheckDownloadURL returns immediately which means the client object |
1757 // callback will never be called. Nevertheless the callback provided | 1758 // callback will never be called. Nevertheless the callback provided |
1758 // to CheckClientDownload must still be called. | 1759 // to CheckClientDownload must still be called. |
1759 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1760 EXPECT_CALL(*sb_service_->mock_database_manager(), |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1803 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1804 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
1804 base::Unretained(this), run_loop.QuitClosure())); | 1805 base::Unretained(this), run_loop.QuitClosure())); |
1805 run_loop.Run(); | 1806 run_loop.Run(); |
1806 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 1807 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
1807 } | 1808 } |
1808 } | 1809 } |
1809 | 1810 |
1810 TEST_F(DownloadProtectionServiceTest, TestDownloadRequestTimeout) { | 1811 TEST_F(DownloadProtectionServiceTest, TestDownloadRequestTimeout) { |
1811 net::TestURLFetcherFactory factory; | 1812 net::TestURLFetcherFactory factory; |
1812 | 1813 |
1813 content::MockDownloadItem item; | 1814 NiceMockDownloadItem item; |
1814 PrepareBasicDownloadItem( | 1815 PrepareBasicDownloadItem( |
1815 &item, | 1816 &item, |
1816 {"http://www.evil.com/bla.exe"}, // url_chain | 1817 {"http://www.evil.com/bla.exe"}, // url_chain |
1817 "http://www.google.com/", // referrer | 1818 "http://www.google.com/", // referrer |
1818 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 1819 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
1819 FILE_PATH_LITERAL("a.exe")); // final_path | 1820 FILE_PATH_LITERAL("a.exe")); // final_path |
1820 | 1821 |
1821 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1822 EXPECT_CALL(*sb_service_->mock_database_manager(), |
1822 MatchDownloadWhitelistUrl(_)) | 1823 MatchDownloadWhitelistUrl(_)) |
1823 .WillRepeatedly(Return(false)); | 1824 .WillRepeatedly(Return(false)); |
(...skipping 12 matching lines...) Expand all Loading... |
1836 // The request should time out because the HTTP request hasn't returned | 1837 // The request should time out because the HTTP request hasn't returned |
1837 // anything yet. | 1838 // anything yet. |
1838 run_loop.Run(); | 1839 run_loop.Run(); |
1839 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1840 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
1840 EXPECT_TRUE(HasClientDownloadRequest()); | 1841 EXPECT_TRUE(HasClientDownloadRequest()); |
1841 ClearClientDownloadRequest(); | 1842 ClearClientDownloadRequest(); |
1842 } | 1843 } |
1843 | 1844 |
1844 TEST_F(DownloadProtectionServiceTest, TestDownloadItemDestroyed) { | 1845 TEST_F(DownloadProtectionServiceTest, TestDownloadItemDestroyed) { |
1845 { | 1846 { |
1846 content::MockDownloadItem item; | 1847 NiceMockDownloadItem item; |
1847 PrepareBasicDownloadItem( | 1848 PrepareBasicDownloadItem( |
1848 &item, | 1849 &item, |
1849 {"http://www.evil.com/bla.exe"}, // url_chain | 1850 {"http://www.evil.com/bla.exe"}, // url_chain |
1850 "http://www.google.com/", // referrer | 1851 "http://www.google.com/", // referrer |
1851 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 1852 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
1852 FILE_PATH_LITERAL("a.exe")); // final_path | 1853 FILE_PATH_LITERAL("a.exe")); // final_path |
1853 GURL tab_url("http://www.google.com/tab"); | 1854 GURL tab_url("http://www.google.com/tab"); |
1854 EXPECT_CALL(item, GetTabUrl()).WillRepeatedly(ReturnRef(tab_url)); | 1855 EXPECT_CALL(item, GetTabUrl()).WillRepeatedly(ReturnRef(tab_url)); |
1855 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1856 EXPECT_CALL(*sb_service_->mock_database_manager(), |
1856 MatchDownloadWhitelistUrl(_)) | 1857 MatchDownloadWhitelistUrl(_)) |
(...skipping 11 matching lines...) Expand all Loading... |
1868 // notification. | 1869 // notification. |
1869 } | 1870 } |
1870 | 1871 |
1871 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1872 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
1872 EXPECT_FALSE(HasClientDownloadRequest()); | 1873 EXPECT_FALSE(HasClientDownloadRequest()); |
1873 } | 1874 } |
1874 | 1875 |
1875 TEST_F(DownloadProtectionServiceTest, | 1876 TEST_F(DownloadProtectionServiceTest, |
1876 TestDownloadItemDestroyedDuringWhitelistCheck) { | 1877 TestDownloadItemDestroyedDuringWhitelistCheck) { |
1877 net::TestURLFetcherFactory factory; | 1878 net::TestURLFetcherFactory factory; |
1878 std::unique_ptr<content::MockDownloadItem> item( | 1879 std::unique_ptr<NiceMockDownloadItem> item(new NiceMockDownloadItem); |
1879 new content::MockDownloadItem); | |
1880 PrepareBasicDownloadItem( | 1880 PrepareBasicDownloadItem( |
1881 item.get(), | 1881 item.get(), |
1882 {"http://www.evil.com/bla.exe"}, // url_chain | 1882 {"http://www.evil.com/bla.exe"}, // url_chain |
1883 "http://www.google.com/", // referrer | 1883 "http://www.google.com/", // referrer |
1884 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 1884 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
1885 FILE_PATH_LITERAL("a.exe")); // final_path | 1885 FILE_PATH_LITERAL("a.exe")); // final_path |
1886 GURL tab_url("http://www.google.com/tab"); | 1886 GURL tab_url("http://www.google.com/tab"); |
1887 EXPECT_CALL(*item, GetTabUrl()).WillRepeatedly(ReturnRef(tab_url)); | 1887 EXPECT_CALL(*item, GetTabUrl()).WillRepeatedly(ReturnRef(tab_url)); |
1888 | 1888 |
1889 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1889 EXPECT_CALL(*sb_service_->mock_database_manager(), |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2023 | 2023 |
2024 EXPECT_CALL(mock_download_item, GetDangerType()) | 2024 EXPECT_CALL(mock_download_item, GetDangerType()) |
2025 .WillOnce(Return(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST)); | 2025 .WillOnce(Return(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST)); |
2026 EXPECT_CALL(mock_page_navigator, OpenURL(OpenURLParamsWithContextValue("7"))); | 2026 EXPECT_CALL(mock_page_navigator, OpenURL(OpenURLParamsWithContextValue("7"))); |
2027 | 2027 |
2028 download_service_->ShowDetailsForDownload(mock_download_item, | 2028 download_service_->ShowDetailsForDownload(mock_download_item, |
2029 &mock_page_navigator); | 2029 &mock_page_navigator); |
2030 } | 2030 } |
2031 | 2031 |
2032 TEST_F(DownloadProtectionServiceTest, GetAndSetDownloadPingToken) { | 2032 TEST_F(DownloadProtectionServiceTest, GetAndSetDownloadPingToken) { |
2033 content::MockDownloadItem item; | 2033 NiceMockDownloadItem item; |
2034 EXPECT_TRUE(DownloadProtectionService::GetDownloadPingToken(&item).empty()); | 2034 EXPECT_TRUE(DownloadProtectionService::GetDownloadPingToken(&item).empty()); |
2035 std::string token = "download_ping_token"; | 2035 std::string token = "download_ping_token"; |
2036 DownloadProtectionService::SetDownloadPingToken(&item, token); | 2036 DownloadProtectionService::SetDownloadPingToken(&item, token); |
2037 EXPECT_EQ(token, DownloadProtectionService::GetDownloadPingToken(&item)); | 2037 EXPECT_EQ(token, DownloadProtectionService::GetDownloadPingToken(&item)); |
2038 | 2038 |
2039 DownloadProtectionService::SetDownloadPingToken(&item, std::string()); | 2039 DownloadProtectionService::SetDownloadPingToken(&item, std::string()); |
2040 EXPECT_TRUE(DownloadProtectionService::GetDownloadPingToken(&item).empty()); | 2040 EXPECT_TRUE(DownloadProtectionService::GetDownloadPingToken(&item).empty()); |
2041 } | 2041 } |
2042 | 2042 |
2043 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_Unsupported) { | 2043 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_Unsupported) { |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2289 DownloadProtectionServiceTest::SetUp(); | 2289 DownloadProtectionServiceTest::SetUp(); |
2290 } | 2290 } |
2291 | 2291 |
2292 // Hex 64 chars | 2292 // Hex 64 chars |
2293 const std::string blacklisted_hash_hex_; | 2293 const std::string blacklisted_hash_hex_; |
2294 // Binary 32 bytes | 2294 // Binary 32 bytes |
2295 std::string blacklisted_hash_; | 2295 std::string blacklisted_hash_; |
2296 }; | 2296 }; |
2297 | 2297 |
2298 TEST_F(DownloadProtectionServiceFlagTest, CheckClientDownloadOverridenByFlag) { | 2298 TEST_F(DownloadProtectionServiceFlagTest, CheckClientDownloadOverridenByFlag) { |
2299 content::MockDownloadItem item; | 2299 NiceMockDownloadItem item; |
2300 PrepareBasicDownloadItem( | 2300 PrepareBasicDownloadItem( |
2301 &item, | 2301 &item, |
2302 {"http://www.evil.com/a.exe"}, // url_chain | 2302 {"http://www.evil.com/a.exe"}, // url_chain |
2303 "http://www.google.com/", // referrer | 2303 "http://www.google.com/", // referrer |
2304 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 2304 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
2305 FILE_PATH_LITERAL("a.exe")); // final_path | 2305 FILE_PATH_LITERAL("a.exe")); // final_path |
2306 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(blacklisted_hash_)); | 2306 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(blacklisted_hash_)); |
2307 EXPECT_CALL(*sb_service_->mock_database_manager(), | 2307 EXPECT_CALL(*sb_service_->mock_database_manager(), |
2308 MatchDownloadWhitelistUrl(_)) | 2308 MatchDownloadWhitelistUrl(_)) |
2309 .WillRepeatedly(Return(false)); | 2309 .WillRepeatedly(Return(false)); |
(...skipping 10 matching lines...) Expand all Loading... |
2320 | 2320 |
2321 EXPECT_FALSE(HasClientDownloadRequest()); | 2321 EXPECT_FALSE(HasClientDownloadRequest()); |
2322 // Overriden by flag: | 2322 // Overriden by flag: |
2323 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 2323 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
2324 } | 2324 } |
2325 | 2325 |
2326 // Test a real .zip with a real .exe in it, where the .exe is manually | 2326 // Test a real .zip with a real .exe in it, where the .exe is manually |
2327 // blacklisted by hash. | 2327 // blacklisted by hash. |
2328 TEST_F(DownloadProtectionServiceFlagTest, | 2328 TEST_F(DownloadProtectionServiceFlagTest, |
2329 CheckClientDownloadZipOverridenByFlag) { | 2329 CheckClientDownloadZipOverridenByFlag) { |
2330 content::MockDownloadItem item; | 2330 NiceMockDownloadItem item; |
2331 | 2331 |
2332 PrepareBasicDownloadItemWithFullPaths( | 2332 PrepareBasicDownloadItemWithFullPaths( |
2333 &item, {"http://www.evil.com/a.exe"}, // url_chain | 2333 &item, {"http://www.evil.com/a.exe"}, // url_chain |
2334 "http://www.google.com/", // referrer | 2334 "http://www.google.com/", // referrer |
2335 testdata_path_.AppendASCII( | 2335 testdata_path_.AppendASCII( |
2336 "zipfile_one_unsigned_binary.zip"), // tmp_path | 2336 "zipfile_one_unsigned_binary.zip"), // tmp_path |
2337 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("a.zip"))); // final_path | 2337 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("a.zip"))); // final_path |
2338 | 2338 |
2339 EXPECT_CALL(*sb_service_->mock_database_manager(), | 2339 EXPECT_CALL(*sb_service_->mock_database_manager(), |
2340 MatchDownloadWhitelistUrl(_)) | 2340 MatchDownloadWhitelistUrl(_)) |
2341 .WillRepeatedly(Return(false)); | 2341 .WillRepeatedly(Return(false)); |
2342 | 2342 |
2343 RunLoop run_loop; | 2343 RunLoop run_loop; |
2344 download_service_->CheckClientDownload( | 2344 download_service_->CheckClientDownload( |
2345 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2345 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
2346 base::Unretained(this), run_loop.QuitClosure())); | 2346 base::Unretained(this), run_loop.QuitClosure())); |
2347 run_loop.Run(); | 2347 run_loop.Run(); |
2348 | 2348 |
2349 EXPECT_FALSE(HasClientDownloadRequest()); | 2349 EXPECT_FALSE(HasClientDownloadRequest()); |
2350 // Overriden by flag: | 2350 // Overriden by flag: |
2351 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 2351 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
2352 } | 2352 } |
2353 | 2353 |
2354 } // namespace safe_browsing | 2354 } // namespace safe_browsing |
OLD | NEW |