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

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

Issue 8536035: Include the full certificate chain in the download pingback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 virtual ~MockSignatureUtil() {} 56 virtual ~MockSignatureUtil() {}
57 MOCK_METHOD2(CheckSignature, 57 MOCK_METHOD2(CheckSignature,
58 void(const FilePath&, ClientDownloadRequest_SignatureInfo*)); 58 void(const FilePath&, ClientDownloadRequest_SignatureInfo*));
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->set_certificate_contents(contents); 66 arg1->add_certificate_chain()->add_element()->set_certificate(contents);
67 } 67 }
68 68
69 // We can't call OnSafeBrowsingResult directly because SafeBrowsingCheck does 69 // 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 70 // 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 71 // easily. Note: check will be deleted automatically when the callback is
72 // deleted. 72 // deleted.
73 void OnSafeBrowsingResult(SafeBrowsingService::SafeBrowsingCheck* check) { 73 void OnSafeBrowsingResult(SafeBrowsingService::SafeBrowsingCheck* check) {
74 check->client->OnSafeBrowsingResult(*check); 74 check->client->OnSafeBrowsingResult(*check);
75 } 75 }
76 76
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 EXPECT_EQ(info.user_initiated, request.user_initiated()); 377 EXPECT_EQ(info.user_initiated, request.user_initiated());
378 EXPECT_EQ(2, request.resources_size()); 378 EXPECT_EQ(2, request.resources_size());
379 EXPECT_TRUE(RequestContainsResource(request, 379 EXPECT_TRUE(RequestContainsResource(request,
380 ClientDownloadRequest::DOWNLOAD_REDIRECT, 380 ClientDownloadRequest::DOWNLOAD_REDIRECT,
381 "http://www.google.com/", "")); 381 "http://www.google.com/", ""));
382 EXPECT_TRUE(RequestContainsResource(request, 382 EXPECT_TRUE(RequestContainsResource(request,
383 ClientDownloadRequest::DOWNLOAD_URL, 383 ClientDownloadRequest::DOWNLOAD_URL,
384 "http://www.google.com/bla.exe", 384 "http://www.google.com/bla.exe",
385 info.referrer_url.spec())); 385 info.referrer_url.spec()));
386 EXPECT_TRUE(request.has_signature()); 386 EXPECT_TRUE(request.has_signature());
387 EXPECT_TRUE(request.signature().has_certificate_contents()); 387 ASSERT_EQ(1, request.signature().certificate_chain_size());
388 EXPECT_EQ("dummy cert data", request.signature().certificate_contents()); 388 const ClientDownloadRequest_CertificateChain& chain =
389 request.signature().certificate_chain(0);
390 ASSERT_EQ(1, chain.element_size());
391 EXPECT_EQ("dummy cert data", chain.element(0).certificate());
389 392
390 // Simulate the request finishing. 393 // Simulate the request finishing.
391 MessageLoop::current()->PostTask( 394 MessageLoop::current()->PostTask(
392 FROM_HERE, 395 FROM_HERE,
393 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, 396 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete,
394 base::Unretained(this), fetcher)); 397 base::Unretained(this), fetcher));
395 msg_loop_.Run(); 398 msg_loop_.Run();
396 } 399 }
397 400
398 // Similar to above, but with an unsigned binary. 401 // Similar to above, but with an unsigned binary.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 EXPECT_EQ(info.user_initiated, request.user_initiated()); 433 EXPECT_EQ(info.user_initiated, request.user_initiated());
431 EXPECT_EQ(2, request.resources_size()); 434 EXPECT_EQ(2, request.resources_size());
432 EXPECT_TRUE(RequestContainsResource(request, 435 EXPECT_TRUE(RequestContainsResource(request,
433 ClientDownloadRequest::DOWNLOAD_REDIRECT, 436 ClientDownloadRequest::DOWNLOAD_REDIRECT,
434 "http://www.google.com/", "")); 437 "http://www.google.com/", ""));
435 EXPECT_TRUE(RequestContainsResource(request, 438 EXPECT_TRUE(RequestContainsResource(request,
436 ClientDownloadRequest::DOWNLOAD_URL, 439 ClientDownloadRequest::DOWNLOAD_URL,
437 "http://www.google.com/bla.exe", 440 "http://www.google.com/bla.exe",
438 info.referrer_url.spec())); 441 info.referrer_url.spec()));
439 EXPECT_TRUE(request.has_signature()); 442 EXPECT_TRUE(request.has_signature());
440 EXPECT_FALSE(request.signature().has_certificate_contents()); 443 EXPECT_EQ(0, request.signature().certificate_chain_size());
441 444
442 // Simulate the request finishing. 445 // Simulate the request finishing.
443 MessageLoop::current()->PostTask( 446 MessageLoop::current()->PostTask(
444 FROM_HERE, 447 FROM_HERE,
445 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, 448 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete,
446 base::Unretained(this), fetcher)); 449 base::Unretained(this), fetcher));
447 msg_loop_.Run(); 450 msg_loop_.Run();
448 } 451 }
449 452
450 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadDigestList) { 453 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadDigestList) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 CheckDownloadUrlDone(SafeBrowsingService::BINARY_MALWARE_URL), 608 CheckDownloadUrlDone(SafeBrowsingService::BINARY_MALWARE_URL),
606 Return(false))); 609 Return(false)));
607 download_service_->CheckDownloadUrl( 610 download_service_->CheckDownloadUrl(
608 info, 611 info,
609 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 612 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
610 base::Unretained(this))); 613 base::Unretained(this)));
611 msg_loop_.Run(); 614 msg_loop_.Run();
612 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_); 615 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_);
613 } 616 }
614 } // namespace safe_browsing 617 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698