| 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 // Only https is not supported for now for privacy reasons. | 226 // Only https is not supported for now for privacy reasons. |
| 227 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); | 227 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); |
| 228 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 228 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
| 229 info.download_url_chain.push_back(GURL("https://www.google.com/")); | 229 info.download_url_chain.push_back(GURL("https://www.google.com/")); |
| 230 download_service_->CheckClientDownload( | 230 download_service_->CheckClientDownload( |
| 231 info, | 231 info, |
| 232 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 232 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 233 base::Unretained(this))); | 233 base::Unretained(this))); |
| 234 msg_loop_.Run(); | 234 msg_loop_.Run(); |
| 235 ExpectResult(DownloadProtectionService::SAFE); | 235 ExpectResult(DownloadProtectionService::SAFE); |
| 236 |
| 237 info.download_url_chain.push_back(GURL("file://www.google.com/")); |
| 238 download_service_->CheckClientDownload( |
| 239 info, |
| 240 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 241 base::Unretained(this))); |
| 242 msg_loop_.Run(); |
| 243 ExpectResult(DownloadProtectionService::SAFE); |
| 236 } | 244 } |
| 237 | 245 |
| 238 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadWhitelistedUrl) { | 246 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadWhitelistedUrl) { |
| 239 DownloadProtectionService::DownloadInfo info; | 247 DownloadProtectionService::DownloadInfo info; |
| 240 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); | 248 info.local_file = FilePath(FILE_PATH_LITERAL("a.tmp")); |
| 241 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); | 249 info.target_file = FilePath(FILE_PATH_LITERAL("a.exe")); |
| 242 info.download_url_chain.push_back(GURL("http://www.evil.com/bla.exe")); | 250 info.download_url_chain.push_back(GURL("http://www.evil.com/bla.exe")); |
| 243 info.download_url_chain.push_back(GURL("http://www.google.com/a.exe")); | 251 info.download_url_chain.push_back(GURL("http://www.google.com/a.exe")); |
| 244 info.referrer_url = GURL("http://www.google.com/"); | 252 info.referrer_url = GURL("http://www.google.com/"); |
| 245 | 253 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 414 |
| 407 // Similar to above, but with an unsigned binary. | 415 // Similar to above, but with an unsigned binary. |
| 408 TEST_F(DownloadProtectionServiceTest, | 416 TEST_F(DownloadProtectionServiceTest, |
| 409 CheckClientDownloadValidateRequestNoSignature) { | 417 CheckClientDownloadValidateRequestNoSignature) { |
| 410 TestURLFetcherFactory factory; | 418 TestURLFetcherFactory factory; |
| 411 | 419 |
| 412 DownloadProtectionService::DownloadInfo info; | 420 DownloadProtectionService::DownloadInfo info; |
| 413 info.local_file = FilePath(FILE_PATH_LITERAL("bla.tmp")); | 421 info.local_file = FilePath(FILE_PATH_LITERAL("bla.tmp")); |
| 414 info.target_file = FilePath(FILE_PATH_LITERAL("bla.exe")); | 422 info.target_file = FilePath(FILE_PATH_LITERAL("bla.exe")); |
| 415 info.download_url_chain.push_back(GURL("http://www.google.com/")); | 423 info.download_url_chain.push_back(GURL("http://www.google.com/")); |
| 416 info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe")); | 424 info.download_url_chain.push_back(GURL("ftp://www.google.com/bla.exe")); |
| 417 info.referrer_url = GURL("http://www.google.com/"); | 425 info.referrer_url = GURL("http://www.google.com/"); |
| 418 info.sha256_hash = "hash"; | 426 info.sha256_hash = "hash"; |
| 419 info.total_bytes = 100; | 427 info.total_bytes = 100; |
| 420 info.user_initiated = false; | 428 info.user_initiated = false; |
| 421 | 429 |
| 422 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) | 430 EXPECT_CALL(*sb_service_, MatchDownloadWhitelistUrl(_)) |
| 423 .WillRepeatedly(Return(false)); | 431 .WillRepeatedly(Return(false)); |
| 424 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); | 432 EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)); |
| 425 | 433 |
| 426 download_service_->CheckClientDownload( | 434 download_service_->CheckClientDownload( |
| 427 info, | 435 info, |
| 428 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 436 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 429 base::Unretained(this))); | 437 base::Unretained(this))); |
| 430 // Run the message loop(s) until SendRequest is called. | 438 // Run the message loop(s) until SendRequest is called. |
| 431 FlushThreadMessageLoops(); | 439 FlushThreadMessageLoops(); |
| 432 | 440 |
| 433 TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 441 TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 434 ASSERT_TRUE(fetcher); | 442 ASSERT_TRUE(fetcher); |
| 435 ClientDownloadRequest request; | 443 ClientDownloadRequest request; |
| 436 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); | 444 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); |
| 437 EXPECT_EQ("http://www.google.com/bla.exe", request.url()); | 445 EXPECT_EQ("ftp://www.google.com/bla.exe", request.url()); |
| 438 EXPECT_EQ(info.sha256_hash, request.digests().sha256()); | 446 EXPECT_EQ(info.sha256_hash, request.digests().sha256()); |
| 439 EXPECT_EQ(info.total_bytes, request.length()); | 447 EXPECT_EQ(info.total_bytes, request.length()); |
| 440 EXPECT_EQ(info.user_initiated, request.user_initiated()); | 448 EXPECT_EQ(info.user_initiated, request.user_initiated()); |
| 441 EXPECT_EQ(2, request.resources_size()); | 449 EXPECT_EQ(2, request.resources_size()); |
| 442 EXPECT_TRUE(RequestContainsResource(request, | 450 EXPECT_TRUE(RequestContainsResource(request, |
| 443 ClientDownloadRequest::DOWNLOAD_REDIRECT, | 451 ClientDownloadRequest::DOWNLOAD_REDIRECT, |
| 444 "http://www.google.com/", "")); | 452 "http://www.google.com/", "")); |
| 445 EXPECT_TRUE(RequestContainsResource(request, | 453 EXPECT_TRUE(RequestContainsResource(request, |
| 446 ClientDownloadRequest::DOWNLOAD_URL, | 454 ClientDownloadRequest::DOWNLOAD_URL, |
| 447 "http://www.google.com/bla.exe", | 455 "ftp://www.google.com/bla.exe", |
| 448 info.referrer_url.spec())); | 456 info.referrer_url.spec())); |
| 449 EXPECT_TRUE(request.has_signature()); | 457 EXPECT_TRUE(request.has_signature()); |
| 450 EXPECT_EQ(0, request.signature().certificate_chain_size()); | 458 EXPECT_EQ(0, request.signature().certificate_chain_size()); |
| 451 | 459 |
| 452 // Simulate the request finishing. | 460 // Simulate the request finishing. |
| 453 MessageLoop::current()->PostTask( | 461 MessageLoop::current()->PostTask( |
| 454 FROM_HERE, | 462 FROM_HERE, |
| 455 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, | 463 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, |
| 456 base::Unretained(this), fetcher)); | 464 base::Unretained(this), fetcher)); |
| 457 msg_loop_.Run(); | 465 msg_loop_.Run(); |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 info, | 669 info, |
| 662 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 670 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 663 base::Unretained(this))); | 671 base::Unretained(this))); |
| 664 | 672 |
| 665 // The request should time out because the HTTP request hasn't returned | 673 // The request should time out because the HTTP request hasn't returned |
| 666 // anything yet. | 674 // anything yet. |
| 667 msg_loop_.Run(); | 675 msg_loop_.Run(); |
| 668 ExpectResult(DownloadProtectionService::SAFE); | 676 ExpectResult(DownloadProtectionService::SAFE); |
| 669 } | 677 } |
| 670 } // namespace safe_browsing | 678 } // namespace safe_browsing |
| OLD | NEW |