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

Side by Side Diff: chrome/browser/safe_browsing/download_protection_service_unittest.cc

Issue 8572037: Whitelist executables that are trusted in the SafeBrowsing download protection. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Address Matt's comments Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/safe_browsing/download_protection_service.cc ('k') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/bind.h" 10 #include "base/bind.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 private: 60 private:
61 DISALLOW_COPY_AND_ASSIGN(MockSignatureUtil); 61 DISALLOW_COPY_AND_ASSIGN(MockSignatureUtil);
62 }; 62 };
63 } // namespace 63 } // namespace
64 64
65 ACTION_P(SetCertificateContents, contents) { 65 ACTION_P(SetCertificateContents, contents) {
66 arg1->add_certificate_chain()->add_element()->set_certificate(contents); 66 arg1->add_certificate_chain()->add_element()->set_certificate(contents);
67 } 67 }
68 68
69 ACTION(TrustSignature) {
70 arg1->set_trusted(true);
71 }
72
69 // We can't call OnSafeBrowsingResult directly because SafeBrowsingCheck does 73 // We can't call OnSafeBrowsingResult directly because SafeBrowsingCheck does
70 // not have any copy constructor which means it can't be stored in a callback 74 // not have any copy constructor which means it can't be stored in a callback
71 // easily. Note: check will be deleted automatically when the callback is 75 // easily. Note: check will be deleted automatically when the callback is
72 // deleted. 76 // deleted.
73 void OnSafeBrowsingResult(SafeBrowsingService::SafeBrowsingCheck* check) { 77 void OnSafeBrowsingResult(SafeBrowsingService::SafeBrowsingCheck* check) {
74 check->client->OnSafeBrowsingResult(*check); 78 check->client->OnSafeBrowsingResult(*check);
75 } 79 }
76 80
77 ACTION_P(CheckDownloadUrlDone, result) { 81 ACTION_P(CheckDownloadUrlDone, result) {
78 SafeBrowsingService::SafeBrowsingCheck* check = 82 SafeBrowsingService::SafeBrowsingCheck* check =
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 CheckDownloadHash(info.sha256_hash, NotNull())) 549 CheckDownloadHash(info.sha256_hash, NotNull()))
546 .WillOnce(DoAll( 550 .WillOnce(DoAll(
547 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_HASH), 551 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_HASH),
548 Return(false))); 552 Return(false)));
549 download_service_->CheckClientDownload( 553 download_service_->CheckClientDownload(
550 info, 554 info,
551 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 555 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
552 base::Unretained(this))); 556 base::Unretained(this)));
553 msg_loop_.Run(); 557 msg_loop_.Run();
554 EXPECT_EQ(DownloadProtectionService::SAFE, result_); 558 EXPECT_EQ(DownloadProtectionService::SAFE, result_);
559 Mock::VerifyAndClearExpectations(sb_service_);
560
561 // If the binary is a trusted executable we will not ping the server but
562 // we will still lookup the digest list.
563 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_))
564 .WillRepeatedly(Return(false));
565 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _))
566 .WillOnce(TrustSignature());
567 EXPECT_CALL(*sb_service_,
568 CheckDownloadHash(info.sha256_hash, NotNull()))
569 .WillOnce(DoAll(CheckDownloadHashDone(SafeBrowsingService::SAFE),
570 Return(false)));
571 download_service_->CheckClientDownload(
572 info,
573 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
574 base::Unretained(this)));
575 msg_loop_.Run();
576 EXPECT_EQ(DownloadProtectionService::SAFE, result_);
555 } 577 }
556 578
557 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) { 579 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) {
558 DownloadProtectionService::DownloadInfo info; 580 DownloadProtectionService::DownloadInfo info;
559 info.download_url_chain.push_back(GURL("http://www.google.com/")); 581 info.download_url_chain.push_back(GURL("http://www.google.com/"));
560 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); 582 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe"));
561 info.referrer_url = GURL("http://www.google.com/"); 583 info.referrer_url = GURL("http://www.google.com/");
562 584
563 // CheckDownloadURL returns immediately which means the client object callback 585 // CheckDownloadURL returns immediately which means the client object callback
564 // will never be called. Nevertheless the callback provided to 586 // will never be called. Nevertheless the callback provided to
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 CheckDownloadUrlDone(SafeBrowsingService::BINARY_MALWARE_URL), 631 CheckDownloadUrlDone(SafeBrowsingService::BINARY_MALWARE_URL),
610 Return(false))); 632 Return(false)));
611 download_service_->CheckDownloadUrl( 633 download_service_->CheckDownloadUrl(
612 info, 634 info,
613 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 635 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
614 base::Unretained(this))); 636 base::Unretained(this)));
615 msg_loop_.Run(); 637 msg_loop_.Run();
616 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_); 638 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_);
617 } 639 }
618 } // namespace safe_browsing 640 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/download_protection_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698