OLD | NEW |
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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 207 |
208 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { | 208 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { |
209 DownloadProtectionService::DownloadInfo info; | 209 DownloadProtectionService::DownloadInfo info; |
210 download_service_->CheckClientDownload( | 210 download_service_->CheckClientDownload( |
211 info, | 211 info, |
212 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 212 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
213 base::Unretained(this))); | 213 base::Unretained(this))); |
214 msg_loop_.Run(); | 214 msg_loop_.Run(); |
215 EXPECT_EQ(DownloadProtectionService::SAFE, result_); | 215 EXPECT_EQ(DownloadProtectionService::SAFE, result_); |
216 | 216 |
217 // Only http is supported for now. | 217 // Only https is not supported for now for privacy reasons. |
218 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 218 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
219 info.download_url_chain.push_back(GURL("https://www.google.com/")); | 219 info.download_url_chain.push_back(GURL("https://www.google.com/")); |
220 download_service_->CheckClientDownload( | 220 download_service_->CheckClientDownload( |
221 info, | 221 info, |
222 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 222 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
223 base::Unretained(this))); | 223 base::Unretained(this))); |
224 msg_loop_.Run(); | 224 msg_loop_.Run(); |
225 EXPECT_EQ(DownloadProtectionService::SAFE, result_); | 225 EXPECT_EQ(DownloadProtectionService::SAFE, result_); |
226 | |
227 info.download_url_chain[0] = GURL("ftp://www.google.com/"); | |
228 download_service_->CheckClientDownload( | |
229 info, | |
230 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | |
231 base::Unretained(this))); | |
232 msg_loop_.Run(); | |
233 EXPECT_EQ(DownloadProtectionService::SAFE, result_); | |
234 } | 226 } |
235 | 227 |
236 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadWhitelistedUrl) { | 228 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadWhitelistedUrl) { |
237 DownloadProtectionService::DownloadInfo info; | 229 DownloadProtectionService::DownloadInfo info; |
238 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 230 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
239 info.download_url_chain.push_back(GURL("http://www.evil.com/bla.exe")); | 231 info.download_url_chain.push_back(GURL("http://www.evil.com/bla.exe")); |
240 info.download_url_chain.push_back(GURL("http://www.google.com/a.exe")); | 232 info.download_url_chain.push_back(GURL("http://www.google.com/a.exe")); |
241 info.referrer_url = GURL("http://www.google.com/"); | 233 info.referrer_url = GURL("http://www.google.com/"); |
242 | 234 |
243 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) | 235 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_URL), | 483 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_URL), |
492 Return(false))); | 484 Return(false))); |
493 download_service_->CheckClientDownload( | 485 download_service_->CheckClientDownload( |
494 info, | 486 info, |
495 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 487 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
496 base::Unretained(this))); | 488 base::Unretained(this))); |
497 msg_loop_.Run(); | 489 msg_loop_.Run(); |
498 EXPECT_EQ(DownloadProtectionService::SAFE, result_); | 490 EXPECT_EQ(DownloadProtectionService::SAFE, result_); |
499 Mock::VerifyAndClearExpectations(sb_service_); | 491 Mock::VerifyAndClearExpectations(sb_service_); |
500 | 492 |
501 // A match is found with the bad binary digest list. | 493 // A match is found with the bad binary digest list. We currently do not |
| 494 // warn based on the digest list. Hence we should always return SAFE. |
502 EXPECT_CALL(*sb_service_, | 495 EXPECT_CALL(*sb_service_, |
503 CheckDownloadHash(info.sha256_hash, NotNull())) | 496 CheckDownloadHash(info.sha256_hash, NotNull())) |
504 .WillOnce(DoAll( | 497 .WillOnce(DoAll( |
505 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_HASH), | 498 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_HASH), |
506 Return(false))); | 499 Return(false))); |
507 download_service_->CheckClientDownload( | 500 download_service_->CheckClientDownload( |
508 info, | 501 info, |
509 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 502 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
510 base::Unretained(this))); | 503 base::Unretained(this))); |
511 msg_loop_.Run(); | 504 msg_loop_.Run(); |
512 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_); | 505 EXPECT_EQ(DownloadProtectionService::SAFE, result_); |
513 Mock::VerifyAndClearExpectations(sb_service_); | 506 Mock::VerifyAndClearExpectations(sb_service_); |
514 | 507 |
515 // If the download is not an executable we do not send a server ping but we | 508 // If the download is not an executable we do not send a server ping but we |
516 // still want to lookup the binary digest list. | 509 // still want to lookup the binary digest list. |
517 info.local_file = FilePath(FILE_PATH_LITERAL("a.pdf")); | 510 info.local_file = FilePath(FILE_PATH_LITERAL("a.pdf")); |
518 info.download_url_chain[0] = GURL("http://www.evil.com/a.pdf"); | 511 info.download_url_chain[0] = GURL("http://www.evil.com/a.pdf"); |
519 EXPECT_CALL(*sb_service_, | 512 EXPECT_CALL(*sb_service_, |
520 CheckDownloadHash(info.sha256_hash, NotNull())) | 513 CheckDownloadHash(info.sha256_hash, NotNull())) |
521 .WillOnce(DoAll( | 514 .WillOnce(DoAll( |
522 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_HASH), | 515 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_HASH), |
523 Return(false))); | 516 Return(false))); |
524 download_service_->CheckClientDownload( | 517 download_service_->CheckClientDownload( |
525 info, | 518 info, |
526 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 519 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
527 base::Unretained(this))); | 520 base::Unretained(this))); |
528 msg_loop_.Run(); | 521 msg_loop_.Run(); |
529 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_); | 522 EXPECT_EQ(DownloadProtectionService::SAFE, result_); |
530 Mock::VerifyAndClearExpectations(sb_service_); | 523 Mock::VerifyAndClearExpectations(sb_service_); |
531 | 524 |
532 // If the URL or the referrer matches the download whitelist we cannot send | 525 // If the URL or the referrer matches the download whitelist we cannot send |
533 // a server ping for privacy reasons but we still match the digest against | 526 // a server ping for privacy reasons but we still match the digest against |
534 // the bad binary digest list. | 527 // the bad binary digest list. |
535 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 528 info.local_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
536 info.download_url_chain[0] = GURL("http://www.evil.com/a.exe"); | 529 info.download_url_chain[0] = GURL("http://www.evil.com/a.exe"); |
537 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) | 530 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) |
538 .WillRepeatedly(Return(true)); | 531 .WillRepeatedly(Return(true)); |
539 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); | 532 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); |
540 EXPECT_CALL(*sb_service_, | 533 EXPECT_CALL(*sb_service_, |
541 CheckDownloadHash(info.sha256_hash, NotNull())) | 534 CheckDownloadHash(info.sha256_hash, NotNull())) |
542 .WillOnce(DoAll( | 535 .WillOnce(DoAll( |
543 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_HASH), | 536 CheckDownloadHashDone(SafeBrowsingService::BINARY_MALWARE_HASH), |
544 Return(false))); | 537 Return(false))); |
545 download_service_->CheckClientDownload( | 538 download_service_->CheckClientDownload( |
546 info, | 539 info, |
547 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 540 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
548 base::Unretained(this))); | 541 base::Unretained(this))); |
549 msg_loop_.Run(); | 542 msg_loop_.Run(); |
550 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_); | 543 EXPECT_EQ(DownloadProtectionService::SAFE, result_); |
551 } | 544 } |
552 | 545 |
553 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) { | 546 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) { |
554 DownloadProtectionService::DownloadInfo info; | 547 DownloadProtectionService::DownloadInfo info; |
555 info.download_url_chain.push_back(GURL("http://www.google.com/")); | 548 info.download_url_chain.push_back(GURL("http://www.google.com/")); |
556 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); | 549 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); |
557 info.referrer_url = GURL("http://www.google.com/"); | 550 info.referrer_url = GURL("http://www.google.com/"); |
558 | 551 |
559 // CheckDownloadURL returns immediately which means the client object callback | 552 // CheckDownloadURL returns immediately which means the client object callback |
560 // will never be called. Nevertheless the callback provided to | 553 // will never be called. Nevertheless the callback provided to |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 CheckDownloadUrlDone(SafeBrowsingService::BINARY_MALWARE_URL), | 598 CheckDownloadUrlDone(SafeBrowsingService::BINARY_MALWARE_URL), |
606 Return(false))); | 599 Return(false))); |
607 download_service_->CheckDownloadUrl( | 600 download_service_->CheckDownloadUrl( |
608 info, | 601 info, |
609 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 602 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
610 base::Unretained(this))); | 603 base::Unretained(this))); |
611 msg_loop_.Run(); | 604 msg_loop_.Run(); |
612 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_); | 605 EXPECT_EQ(DownloadProtectionService::DANGEROUS, result_); |
613 } | 606 } |
614 } // namespace safe_browsing | 607 } // namespace safe_browsing |
OLD | NEW |