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

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: 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
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 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 EXPECT_CALL(*sb_service_, 548 EXPECT_CALL(*sb_service_,
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_);
mattm 2011/11/16 01:38:01 add VerifyAndClearExpectations call
noelutz 2011/11/16 01:57:18 Done.
559
560 // If the binary is a trusted executable we will not ping the server but
561 // we will still lookup the digest list.
562 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_))
563 .WillRepeatedly(Return(false));
564 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _))
565 .WillOnce(TrustSignature());
566 EXPECT_CALL(*sb_service_,
567 CheckDownloadHash(info.sha256_hash, NotNull()))
568 .WillOnce(DoAll(CheckDownloadHashDone(SafeBrowsingService::SAFE),
569 Return(false)));
570 download_service_->CheckClientDownload(
571 info,
572 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
573 base::Unretained(this)));
574 msg_loop_.Run();
575 EXPECT_EQ(DownloadProtectionService::SAFE, result_);
555 } 576 }
556 577
557 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) { 578 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) {
558 DownloadProtectionService::DownloadInfo info; 579 DownloadProtectionService::DownloadInfo info;
559 info.download_url_chain.push_back(GURL("http://www.google.com/")); 580 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")); 581 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe"));
561 info.referrer_url = GURL("http://www.google.com/"); 582 info.referrer_url = GURL("http://www.google.com/");
562 583
563 // CheckDownloadURL returns immediately which means the client object callback 584 // CheckDownloadURL returns immediately which means the client object callback
564 // will never be called. Nevertheless the callback provided to 585 // 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), 630 CheckDownloadUrlDone(SafeBrowsingService::BINARY_MALWARE_URL),
610 Return(false))); 631 Return(false)));
611 download_service_->CheckDownloadUrl( 632 download_service_->CheckDownloadUrl(
612 info, 633 info,
613 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 634 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
614 base::Unretained(this))); 635 base::Unretained(this)));
615 msg_loop_.Run(); 636 msg_loop_.Run();
616 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_); 637 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_);
617 } 638 }
618 } // namespace safe_browsing 639 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698