| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 "Enabled")); | 210 "Enabled")); |
| 211 #endif | 211 #endif |
| 212 // Start real threads for the IO and File threads so that the DCHECKs | 212 // Start real threads for the IO and File threads so that the DCHECKs |
| 213 // to test that we're on the correct thread work. | 213 // to test that we're on the correct thread work. |
| 214 sb_service_ = new StrictMock<FakeSafeBrowsingService>(); | 214 sb_service_ = new StrictMock<FakeSafeBrowsingService>(); |
| 215 sb_service_->Initialize(); | 215 sb_service_->Initialize(); |
| 216 binary_feature_extractor_ = new StrictMock<MockBinaryFeatureExtractor>(); | 216 binary_feature_extractor_ = new StrictMock<MockBinaryFeatureExtractor>(); |
| 217 download_service_ = sb_service_->download_protection_service(); | 217 download_service_ = sb_service_->download_protection_service(); |
| 218 download_service_->binary_feature_extractor_ = binary_feature_extractor_; | 218 download_service_->binary_feature_extractor_ = binary_feature_extractor_; |
| 219 download_service_->SetEnabled(true); | 219 download_service_->SetEnabled(true); |
| 220 client_download_request_subscription_ = |
| 221 download_service_->RegisterClientDownloadRequestCallback( |
| 222 base::Bind(&DownloadProtectionServiceTest::OnClientDownloadRequest, |
| 223 base::Unretained(this))); |
| 220 base::RunLoop().RunUntilIdle(); | 224 base::RunLoop().RunUntilIdle(); |
| 221 has_result_ = false; | 225 has_result_ = false; |
| 222 | 226 |
| 223 base::FilePath source_path; | 227 base::FilePath source_path; |
| 224 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source_path)); | 228 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &source_path)); |
| 225 testdata_path_ = source_path | 229 testdata_path_ = source_path |
| 226 .AppendASCII("chrome") | 230 .AppendASCII("chrome") |
| 227 .AppendASCII("test") | 231 .AppendASCII("test") |
| 228 .AppendASCII("data") | 232 .AppendASCII("data") |
| 229 .AppendASCII("safe_browsing") | 233 .AppendASCII("safe_browsing") |
| 230 .AppendASCII("download_protection"); | 234 .AppendASCII("download_protection"); |
| 231 } | 235 } |
| 232 | 236 |
| 233 void TearDown() override { | 237 void TearDown() override { |
| 238 client_download_request_subscription_.reset(); |
| 234 sb_service_->ShutDown(); | 239 sb_service_->ShutDown(); |
| 235 // Flush all of the thread message loops to ensure that there are no | 240 // Flush all of the thread message loops to ensure that there are no |
| 236 // tasks currently running. | 241 // tasks currently running. |
| 237 FlushThreadMessageLoops(); | 242 FlushThreadMessageLoops(); |
| 238 sb_service_ = NULL; | 243 sb_service_ = NULL; |
| 239 } | 244 } |
| 240 | 245 |
| 241 bool RequestContainsResource(const ClientDownloadRequest& request, | 246 bool RequestContainsResource(const ClientDownloadRequest& request, |
| 242 ClientDownloadRequest::ResourceType type, | 247 ClientDownloadRequest::ResourceType type, |
| 243 const std::string& url, | 248 const std::string& url, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 return NULL; | 298 return NULL; |
| 294 } | 299 } |
| 295 net::CertificateList certs = | 300 net::CertificateList certs = |
| 296 net::X509Certificate::CreateCertificateListFromBytes( | 301 net::X509Certificate::CreateCertificateListFromBytes( |
| 297 cert_data.data(), | 302 cert_data.data(), |
| 298 cert_data.size(), | 303 cert_data.size(), |
| 299 net::X509Certificate::FORMAT_PEM_CERT_SEQUENCE); | 304 net::X509Certificate::FORMAT_PEM_CERT_SEQUENCE); |
| 300 return certs.empty() ? NULL : certs[0]; | 305 return certs.empty() ? NULL : certs[0]; |
| 301 } | 306 } |
| 302 | 307 |
| 308 bool HasClientDownloadRequest() const { |
| 309 return last_client_download_request_.get() != NULL; |
| 310 } |
| 311 |
| 312 void ClearClientDownloadRequest() { last_client_download_request_.reset(); } |
| 313 |
| 303 private: | 314 private: |
| 304 // Helper functions for FlushThreadMessageLoops. | 315 // Helper functions for FlushThreadMessageLoops. |
| 305 void RunAllPendingAndQuitUI() { | 316 void RunAllPendingAndQuitUI() { |
| 306 base::MessageLoop::current()->RunUntilIdle(); | 317 base::MessageLoop::current()->RunUntilIdle(); |
| 307 BrowserThread::PostTask( | 318 BrowserThread::PostTask( |
| 308 BrowserThread::UI, | 319 BrowserThread::UI, |
| 309 FROM_HERE, | 320 FROM_HERE, |
| 310 base::Bind(&DownloadProtectionServiceTest::QuitMessageLoop, | 321 base::Bind(&DownloadProtectionServiceTest::QuitMessageLoop, |
| 311 base::Unretained(this))); | 322 base::Unretained(this))); |
| 312 } | 323 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 325 | 336 |
| 326 void FlushMessageLoop(BrowserThread::ID thread) { | 337 void FlushMessageLoop(BrowserThread::ID thread) { |
| 327 BrowserThread::PostTask( | 338 BrowserThread::PostTask( |
| 328 BrowserThread::UI, | 339 BrowserThread::UI, |
| 329 FROM_HERE, | 340 FROM_HERE, |
| 330 base::Bind(&DownloadProtectionServiceTest::PostRunMessageLoopTask, | 341 base::Bind(&DownloadProtectionServiceTest::PostRunMessageLoopTask, |
| 331 base::Unretained(this), thread)); | 342 base::Unretained(this), thread)); |
| 332 MessageLoop::current()->Run(); | 343 MessageLoop::current()->Run(); |
| 333 } | 344 } |
| 334 | 345 |
| 346 void OnClientDownloadRequest(content::DownloadItem* download, |
| 347 const ClientDownloadRequest* request) { |
| 348 if (request) |
| 349 last_client_download_request_.reset(new ClientDownloadRequest(*request)); |
| 350 else |
| 351 last_client_download_request_.reset(); |
| 352 } |
| 353 |
| 335 public: | 354 public: |
| 336 void CheckDoneCallback( | 355 void CheckDoneCallback( |
| 337 DownloadProtectionService::DownloadCheckResult result) { | 356 DownloadProtectionService::DownloadCheckResult result) { |
| 338 result_ = result; | 357 result_ = result; |
| 339 has_result_ = true; | 358 has_result_ = true; |
| 340 MessageLoop::current()->Quit(); | 359 MessageLoop::current()->Quit(); |
| 341 } | 360 } |
| 342 | 361 |
| 343 void SyncCheckDoneCallback( | 362 void SyncCheckDoneCallback( |
| 344 DownloadProtectionService::DownloadCheckResult result) { | 363 DownloadProtectionService::DownloadCheckResult result) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 366 scoped_refptr<MockBinaryFeatureExtractor> binary_feature_extractor_; | 385 scoped_refptr<MockBinaryFeatureExtractor> binary_feature_extractor_; |
| 367 DownloadProtectionService* download_service_; | 386 DownloadProtectionService* download_service_; |
| 368 DownloadProtectionService::DownloadCheckResult result_; | 387 DownloadProtectionService::DownloadCheckResult result_; |
| 369 bool has_result_; | 388 bool has_result_; |
| 370 content::TestBrowserThreadBundle test_browser_thread_bundle_; | 389 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
| 371 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; | 390 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_; |
| 372 base::FilePath testdata_path_; | 391 base::FilePath testdata_path_; |
| 373 #if defined(OS_MACOSX) | 392 #if defined(OS_MACOSX) |
| 374 scoped_ptr<base::FieldTrialList> field_trial_list_; | 393 scoped_ptr<base::FieldTrialList> field_trial_list_; |
| 375 #endif | 394 #endif |
| 395 DownloadProtectionService::ClientDownloadRequestSubscription |
| 396 client_download_request_subscription_; |
| 397 scoped_ptr<ClientDownloadRequest> last_client_download_request_; |
| 376 }; | 398 }; |
| 377 | 399 |
| 378 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { | 400 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) { |
| 379 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); | 401 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); |
| 380 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); | 402 base::FilePath a_exe(FILE_PATH_LITERAL("a.exe")); |
| 381 std::vector<GURL> url_chain; | 403 std::vector<GURL> url_chain; |
| 382 GURL referrer("http://www.google.com/"); | 404 GURL referrer("http://www.google.com/"); |
| 383 | 405 |
| 384 content::MockDownloadItem item; | 406 content::MockDownloadItem item; |
| 385 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp)); | 407 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp)); |
| 386 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe)); | 408 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe)); |
| 387 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); | 409 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); |
| 388 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); | 410 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); |
| 389 EXPECT_CALL(item, GetTabUrl()).WillRepeatedly(ReturnRef(GURL::EmptyGURL())); | 411 EXPECT_CALL(item, GetTabUrl()).WillRepeatedly(ReturnRef(GURL::EmptyGURL())); |
| 390 EXPECT_CALL(item, GetTabReferrerUrl()) | 412 EXPECT_CALL(item, GetTabReferrerUrl()) |
| 391 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); | 413 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); |
| 392 download_service_->CheckClientDownload( | 414 download_service_->CheckClientDownload( |
| 393 &item, | 415 &item, |
| 394 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 416 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 395 base::Unretained(this))); | 417 base::Unretained(this))); |
| 396 MessageLoop::current()->Run(); | 418 MessageLoop::current()->Run(); |
| 397 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 419 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 420 EXPECT_FALSE(HasClientDownloadRequest()); |
| 398 Mock::VerifyAndClearExpectations(&item); | 421 Mock::VerifyAndClearExpectations(&item); |
| 399 | 422 |
| 400 url_chain.push_back(GURL("file://www.google.com/")); | 423 url_chain.push_back(GURL("file://www.google.com/")); |
| 401 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp)); | 424 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp)); |
| 402 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe)); | 425 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe)); |
| 403 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); | 426 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); |
| 404 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); | 427 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); |
| 405 EXPECT_CALL(item, GetTabUrl()).WillRepeatedly(ReturnRef(GURL::EmptyGURL())); | 428 EXPECT_CALL(item, GetTabUrl()).WillRepeatedly(ReturnRef(GURL::EmptyGURL())); |
| 406 EXPECT_CALL(item, GetTabReferrerUrl()) | 429 EXPECT_CALL(item, GetTabReferrerUrl()) |
| 407 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); | 430 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); |
| 408 download_service_->CheckClientDownload( | 431 download_service_->CheckClientDownload( |
| 409 &item, | 432 &item, |
| 410 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 433 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 411 base::Unretained(this))); | 434 base::Unretained(this))); |
| 412 MessageLoop::current()->Run(); | 435 MessageLoop::current()->Run(); |
| 413 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 436 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 437 EXPECT_FALSE(HasClientDownloadRequest()); |
| 414 } | 438 } |
| 415 | 439 |
| 416 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadNotABinary) { | 440 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadNotABinary) { |
| 417 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); | 441 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); |
| 418 base::FilePath a_txt(FILE_PATH_LITERAL("a.txt")); | 442 base::FilePath a_txt(FILE_PATH_LITERAL("a.txt")); |
| 419 std::vector<GURL> url_chain; | 443 std::vector<GURL> url_chain; |
| 420 GURL referrer("http://www.google.com/"); | 444 GURL referrer("http://www.google.com/"); |
| 421 | 445 |
| 422 content::MockDownloadItem item; | 446 content::MockDownloadItem item; |
| 423 url_chain.push_back(GURL("http://www.example.com/foo")); | 447 url_chain.push_back(GURL("http://www.example.com/foo")); |
| 424 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp)); | 448 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp)); |
| 425 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_txt)); | 449 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_txt)); |
| 426 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); | 450 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); |
| 427 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); | 451 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); |
| 428 EXPECT_CALL(item, GetTabUrl()).WillRepeatedly(ReturnRef(GURL::EmptyGURL())); | 452 EXPECT_CALL(item, GetTabUrl()).WillRepeatedly(ReturnRef(GURL::EmptyGURL())); |
| 429 EXPECT_CALL(item, GetTabReferrerUrl()) | 453 EXPECT_CALL(item, GetTabReferrerUrl()) |
| 430 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); | 454 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); |
| 431 download_service_->CheckClientDownload( | 455 download_service_->CheckClientDownload( |
| 432 &item, | 456 &item, |
| 433 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 457 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 434 base::Unretained(this))); | 458 base::Unretained(this))); |
| 435 MessageLoop::current()->Run(); | 459 MessageLoop::current()->Run(); |
| 436 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 460 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 461 EXPECT_FALSE(HasClientDownloadRequest()); |
| 437 } | 462 } |
| 438 | 463 |
| 439 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadWhitelistedUrl) { | 464 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadWhitelistedUrl) { |
| 440 // Response to any requests will be DANGEROUS. | 465 // Response to any requests will be DANGEROUS. |
| 441 ClientDownloadResponse response; | 466 ClientDownloadResponse response; |
| 442 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 467 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
| 443 net::FakeURLFetcherFactory factory(NULL); | 468 net::FakeURLFetcherFactory factory(NULL); |
| 444 factory.SetFakeResponse( | 469 factory.SetFakeResponse( |
| 445 DownloadProtectionService::GetDownloadRequestUrl(), | 470 DownloadProtectionService::GetDownloadRequestUrl(), |
| 446 response.SerializeAsString(), | 471 response.SerializeAsString(), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 &item, | 510 &item, |
| 486 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 511 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 487 base::Unretained(this))); | 512 base::Unretained(this))); |
| 488 MessageLoop::current()->Run(); | 513 MessageLoop::current()->Run(); |
| 489 #if defined(OS_WIN) | 514 #if defined(OS_WIN) |
| 490 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 515 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 491 #else | 516 #else |
| 492 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 517 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 493 #endif | 518 #endif |
| 494 | 519 |
| 520 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 521 // OSX sends pings for evaluation purposes. |
| 522 EXPECT_TRUE(HasClientDownloadRequest()); |
| 523 ClearClientDownloadRequest(); |
| 524 #else |
| 525 EXPECT_FALSE(HasClientDownloadRequest()); |
| 526 #endif |
| 527 |
| 495 // Check that the referrer is not matched against the whitelist. | 528 // Check that the referrer is not matched against the whitelist. |
| 496 referrer = GURL("http://www.google.com/"); | 529 referrer = GURL("http://www.google.com/"); |
| 497 download_service_->CheckClientDownload( | 530 download_service_->CheckClientDownload( |
| 498 &item, | 531 &item, |
| 499 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 532 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 500 base::Unretained(this))); | 533 base::Unretained(this))); |
| 501 MessageLoop::current()->Run(); | 534 MessageLoop::current()->Run(); |
| 502 #if defined(OS_WIN) | 535 #if defined(OS_WIN) |
| 503 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 536 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 504 #else | 537 #else |
| 505 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 538 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 506 #endif | 539 #endif |
| 507 | 540 |
| 541 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 542 // OSX sends pings for evaluation purposes. |
| 543 EXPECT_TRUE(HasClientDownloadRequest()); |
| 544 ClearClientDownloadRequest(); |
| 545 #else |
| 546 EXPECT_FALSE(HasClientDownloadRequest()); |
| 547 #endif |
| 548 |
| 508 // Redirect from a site shouldn't be checked either. | 549 // Redirect from a site shouldn't be checked either. |
| 509 url_chain.insert(url_chain.begin(), GURL("http://www.google.com/redirect")); | 550 url_chain.insert(url_chain.begin(), GURL("http://www.google.com/redirect")); |
| 510 download_service_->CheckClientDownload( | 551 download_service_->CheckClientDownload( |
| 511 &item, | 552 &item, |
| 512 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 553 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 513 base::Unretained(this))); | 554 base::Unretained(this))); |
| 514 MessageLoop::current()->Run(); | 555 MessageLoop::current()->Run(); |
| 515 #if defined(OS_WIN) | 556 #if defined(OS_WIN) |
| 516 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 557 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 517 #else | 558 #else |
| 518 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 559 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 519 #endif | 560 #endif |
| 520 | 561 |
| 562 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 563 // OSX sends pings for evaluation purposes. |
| 564 EXPECT_TRUE(HasClientDownloadRequest()); |
| 565 ClearClientDownloadRequest(); |
| 566 #else |
| 567 EXPECT_FALSE(HasClientDownloadRequest()); |
| 568 #endif |
| 569 |
| 521 // Only if the final url is whitelisted should it be SAFE. | 570 // Only if the final url is whitelisted should it be SAFE. |
| 522 url_chain.push_back(GURL("http://www.google.com/a.exe")); | 571 url_chain.push_back(GURL("http://www.google.com/a.exe")); |
| 523 download_service_->CheckClientDownload( | 572 download_service_->CheckClientDownload( |
| 524 &item, | 573 &item, |
| 525 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 574 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 526 base::Unretained(this))); | 575 base::Unretained(this))); |
| 527 MessageLoop::current()->Run(); | 576 MessageLoop::current()->Run(); |
| 528 #if defined(OS_MACOSX) | 577 #if defined(OS_MACOSX) |
| 529 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 578 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 530 #else | 579 #else |
| 531 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 580 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 532 #endif | 581 #endif |
| 582 // TODO(grt): Make the service produce the request even when the URL is |
| 583 // whitelisted. |
| 584 EXPECT_FALSE(HasClientDownloadRequest()); |
| 533 } | 585 } |
| 534 | 586 |
| 535 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { | 587 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) { |
| 536 net::FakeURLFetcherFactory factory(NULL); | 588 net::FakeURLFetcherFactory factory(NULL); |
| 537 // HTTP request will fail. | 589 // HTTP request will fail. |
| 538 factory.SetFakeResponse( | 590 factory.SetFakeResponse( |
| 539 DownloadProtectionService::GetDownloadRequestUrl(), std::string(), | 591 DownloadProtectionService::GetDownloadRequestUrl(), std::string(), |
| 540 net::HTTP_INTERNAL_SERVER_ERROR, net::URLRequestStatus::FAILED); | 592 net::HTTP_INTERNAL_SERVER_ERROR, net::URLRequestStatus::FAILED); |
| 541 | 593 |
| 542 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); | 594 base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp")); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 .Times(6); | 664 .Times(6); |
| 613 | 665 |
| 614 download_service_->CheckClientDownload( | 666 download_service_->CheckClientDownload( |
| 615 &item, | 667 &item, |
| 616 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 668 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 617 base::Unretained(this))); | 669 base::Unretained(this))); |
| 618 MessageLoop::current()->Run(); | 670 MessageLoop::current()->Run(); |
| 619 #if defined(OS_WIN) | 671 #if defined(OS_WIN) |
| 620 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 672 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 621 #else | 673 #else |
| 622 // On !OS_WIN, no file types are currently supported. Hence all erquests to | 674 // On !OS_WIN, no file types are currently supported. Hence all requests to |
| 623 // CheckClientDownload() result in a verdict of UNKNOWN. | 675 // CheckClientDownload() result in a verdict of UNKNOWN. |
| 624 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 676 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 625 #endif | 677 #endif |
| 626 | 678 |
| 679 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 680 // OSX sends pings for evaluation purposes. |
| 681 EXPECT_TRUE(HasClientDownloadRequest()); |
| 682 ClearClientDownloadRequest(); |
| 683 #else |
| 684 EXPECT_FALSE(HasClientDownloadRequest()); |
| 685 #endif |
| 686 |
| 627 // Invalid response should result in UNKNOWN. | 687 // Invalid response should result in UNKNOWN. |
| 628 response.Clear(); | 688 response.Clear(); |
| 629 factory.SetFakeResponse( | 689 factory.SetFakeResponse( |
| 630 DownloadProtectionService::GetDownloadRequestUrl(), | 690 DownloadProtectionService::GetDownloadRequestUrl(), |
| 631 response.SerializePartialAsString(), | 691 response.SerializePartialAsString(), |
| 632 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 692 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 633 | 693 |
| 634 download_service_->CheckClientDownload( | 694 download_service_->CheckClientDownload( |
| 635 &item, | 695 &item, |
| 636 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 696 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 637 base::Unretained(this))); | 697 base::Unretained(this))); |
| 638 MessageLoop::current()->Run(); | 698 MessageLoop::current()->Run(); |
| 639 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 699 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 700 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 701 EXPECT_TRUE(HasClientDownloadRequest()); |
| 702 ClearClientDownloadRequest(); |
| 703 #else |
| 704 EXPECT_FALSE(HasClientDownloadRequest()); |
| 705 #endif |
| 640 std::string feedback_ping; | 706 std::string feedback_ping; |
| 641 std::string feedback_response; | 707 std::string feedback_response; |
| 642 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 708 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
| 643 item, &feedback_ping, &feedback_response)); | 709 item, &feedback_ping, &feedback_response)); |
| 644 | 710 |
| 645 // If the response is dangerous the result should also be marked as dangerous. | 711 // If the response is dangerous the result should also be marked as dangerous. |
| 646 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 712 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
| 647 factory.SetFakeResponse( | 713 factory.SetFakeResponse( |
| 648 DownloadProtectionService::GetDownloadRequestUrl(), | 714 DownloadProtectionService::GetDownloadRequestUrl(), |
| 649 response.SerializeAsString(), | 715 response.SerializeAsString(), |
| 650 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 716 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 651 | 717 |
| 652 download_service_->CheckClientDownload( | 718 download_service_->CheckClientDownload( |
| 653 &item, | 719 &item, |
| 654 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 720 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 655 base::Unretained(this))); | 721 base::Unretained(this))); |
| 656 MessageLoop::current()->Run(); | 722 MessageLoop::current()->Run(); |
| 657 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 723 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
| 658 item, &feedback_ping, &feedback_response)); | 724 item, &feedback_ping, &feedback_response)); |
| 659 #if defined(OS_WIN) | 725 #if defined(OS_WIN) |
| 660 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 726 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 661 #else | 727 #else |
| 662 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 728 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 663 #endif | 729 #endif |
| 664 | 730 |
| 731 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 732 // OSX sends pings for evaluation purposes. |
| 733 EXPECT_TRUE(HasClientDownloadRequest()); |
| 734 ClearClientDownloadRequest(); |
| 735 #else |
| 736 EXPECT_FALSE(HasClientDownloadRequest()); |
| 737 #endif |
| 738 |
| 665 // If the response is uncommon the result should also be marked as uncommon. | 739 // If the response is uncommon the result should also be marked as uncommon. |
| 666 response.set_verdict(ClientDownloadResponse::UNCOMMON); | 740 response.set_verdict(ClientDownloadResponse::UNCOMMON); |
| 667 factory.SetFakeResponse( | 741 factory.SetFakeResponse( |
| 668 DownloadProtectionService::GetDownloadRequestUrl(), | 742 DownloadProtectionService::GetDownloadRequestUrl(), |
| 669 response.SerializeAsString(), | 743 response.SerializeAsString(), |
| 670 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 744 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 671 | 745 |
| 672 download_service_->CheckClientDownload( | 746 download_service_->CheckClientDownload( |
| 673 &item, | 747 &item, |
| 674 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 748 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 675 base::Unretained(this))); | 749 base::Unretained(this))); |
| 676 MessageLoop::current()->Run(); | 750 MessageLoop::current()->Run(); |
| 677 #if defined(OS_WIN) | 751 #if defined(OS_WIN) |
| 678 EXPECT_TRUE(IsResult(DownloadProtectionService::UNCOMMON)); | 752 EXPECT_TRUE(IsResult(DownloadProtectionService::UNCOMMON)); |
| 679 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 753 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
| 680 item, &feedback_ping, &feedback_response)); | 754 item, &feedback_ping, &feedback_response)); |
| 681 ClientDownloadRequest decoded_request; | 755 ClientDownloadRequest decoded_request; |
| 682 EXPECT_TRUE(decoded_request.ParseFromString(feedback_ping)); | 756 EXPECT_TRUE(decoded_request.ParseFromString(feedback_ping)); |
| 683 EXPECT_EQ(url_chain.back().spec(), decoded_request.url()); | 757 EXPECT_EQ(url_chain.back().spec(), decoded_request.url()); |
| 684 EXPECT_EQ(response.SerializeAsString(), feedback_response); | 758 EXPECT_EQ(response.SerializeAsString(), feedback_response); |
| 759 EXPECT_TRUE(HasClientDownloadRequest()); |
| 760 ClearClientDownloadRequest(); |
| 685 #else | 761 #else |
| 686 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 762 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 687 #endif | 763 #endif |
| 688 | 764 |
| 689 // If the response is dangerous_host the result should also be marked as | 765 // If the response is dangerous_host the result should also be marked as |
| 690 // dangerous_host. | 766 // dangerous_host. |
| 691 response.set_verdict(ClientDownloadResponse::DANGEROUS_HOST); | 767 response.set_verdict(ClientDownloadResponse::DANGEROUS_HOST); |
| 692 factory.SetFakeResponse( | 768 factory.SetFakeResponse( |
| 693 DownloadProtectionService::GetDownloadRequestUrl(), | 769 DownloadProtectionService::GetDownloadRequestUrl(), |
| 694 response.SerializeAsString(), | 770 response.SerializeAsString(), |
| 695 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 771 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 696 | 772 |
| 697 download_service_->CheckClientDownload( | 773 download_service_->CheckClientDownload( |
| 698 &item, | 774 &item, |
| 699 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 775 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 700 base::Unretained(this))); | 776 base::Unretained(this))); |
| 701 MessageLoop::current()->Run(); | 777 MessageLoop::current()->Run(); |
| 702 #if defined(OS_WIN) | 778 #if defined(OS_WIN) |
| 703 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS_HOST)); | 779 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS_HOST)); |
| 704 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 780 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
| 705 item, &feedback_ping, &feedback_response)); | 781 item, &feedback_ping, &feedback_response)); |
| 706 EXPECT_EQ(response.SerializeAsString(), feedback_response); | 782 EXPECT_EQ(response.SerializeAsString(), feedback_response); |
| 783 EXPECT_TRUE(HasClientDownloadRequest()); |
| 784 ClearClientDownloadRequest(); |
| 707 #else | 785 #else |
| 708 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 786 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 709 #endif | 787 #endif |
| 710 | 788 |
| 711 // If the response is POTENTIALLY_UNWANTED the result should also be marked as | 789 // If the response is POTENTIALLY_UNWANTED the result should also be marked as |
| 712 // POTENTIALLY_UNWANTED. | 790 // POTENTIALLY_UNWANTED. |
| 713 response.set_verdict(ClientDownloadResponse::POTENTIALLY_UNWANTED); | 791 response.set_verdict(ClientDownloadResponse::POTENTIALLY_UNWANTED); |
| 714 factory.SetFakeResponse( | 792 factory.SetFakeResponse( |
| 715 DownloadProtectionService::GetDownloadRequestUrl(), | 793 DownloadProtectionService::GetDownloadRequestUrl(), |
| 716 response.SerializeAsString(), | 794 response.SerializeAsString(), |
| 717 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 795 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 718 | 796 |
| 719 download_service_->CheckClientDownload( | 797 download_service_->CheckClientDownload( |
| 720 &item, | 798 &item, |
| 721 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 799 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 722 base::Unretained(this))); | 800 base::Unretained(this))); |
| 723 MessageLoop::current()->Run(); | 801 MessageLoop::current()->Run(); |
| 724 #if defined(OS_WIN) | 802 #if defined(OS_WIN) |
| 725 EXPECT_TRUE(IsResult(DownloadProtectionService::POTENTIALLY_UNWANTED)); | 803 EXPECT_TRUE(IsResult(DownloadProtectionService::POTENTIALLY_UNWANTED)); |
| 726 #else | 804 #else |
| 727 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 805 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 728 #endif | 806 #endif |
| 807 |
| 808 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 809 // OSX sends pings for evaluation purposes. |
| 810 EXPECT_TRUE(HasClientDownloadRequest()); |
| 811 ClearClientDownloadRequest(); |
| 812 #else |
| 813 EXPECT_FALSE(HasClientDownloadRequest()); |
| 814 #endif |
| 729 } | 815 } |
| 730 | 816 |
| 731 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { | 817 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { |
| 732 ClientDownloadResponse response; | 818 ClientDownloadResponse response; |
| 733 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 819 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
| 734 net::FakeURLFetcherFactory factory(NULL); | 820 net::FakeURLFetcherFactory factory(NULL); |
| 735 factory.SetFakeResponse( | 821 factory.SetFakeResponse( |
| 736 DownloadProtectionService::GetDownloadRequestUrl(), | 822 DownloadProtectionService::GetDownloadRequestUrl(), |
| 737 response.SerializeAsString(), | 823 response.SerializeAsString(), |
| 738 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 824 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 768 download_service_->CheckClientDownload( | 854 download_service_->CheckClientDownload( |
| 769 &item, | 855 &item, |
| 770 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 856 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 771 base::Unretained(this))); | 857 base::Unretained(this))); |
| 772 MessageLoop::current()->Run(); | 858 MessageLoop::current()->Run(); |
| 773 #if defined(OS_WIN) | 859 #if defined(OS_WIN) |
| 774 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 860 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 775 #else | 861 #else |
| 776 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 862 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 777 #endif | 863 #endif |
| 864 |
| 865 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 866 // OSX sends pings for evaluation purposes. |
| 867 EXPECT_TRUE(HasClientDownloadRequest()); |
| 868 ClearClientDownloadRequest(); |
| 869 #else |
| 870 EXPECT_FALSE(HasClientDownloadRequest()); |
| 871 #endif |
| 778 } | 872 } |
| 779 | 873 |
| 780 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) { | 874 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) { |
| 781 ClientDownloadResponse response; | 875 ClientDownloadResponse response; |
| 782 response.set_verdict(ClientDownloadResponse::SAFE); | 876 response.set_verdict(ClientDownloadResponse::SAFE); |
| 783 net::FakeURLFetcherFactory factory(NULL); | 877 net::FakeURLFetcherFactory factory(NULL); |
| 784 // Empty response means SAFE. | 878 // Empty response means SAFE. |
| 785 factory.SetFakeResponse( | 879 factory.SetFakeResponse( |
| 786 DownloadProtectionService::GetDownloadRequestUrl(), | 880 DownloadProtectionService::GetDownloadRequestUrl(), |
| 787 response.SerializeAsString(), | 881 response.SerializeAsString(), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")), | 913 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")), |
| 820 file_contents.data(), file_contents.size())); | 914 file_contents.data(), file_contents.size())); |
| 821 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false)); | 915 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false)); |
| 822 | 916 |
| 823 download_service_->CheckClientDownload( | 917 download_service_->CheckClientDownload( |
| 824 &item, | 918 &item, |
| 825 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 919 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 826 base::Unretained(this))); | 920 base::Unretained(this))); |
| 827 MessageLoop::current()->Run(); | 921 MessageLoop::current()->Run(); |
| 828 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 922 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 923 EXPECT_FALSE(HasClientDownloadRequest()); |
| 829 Mock::VerifyAndClearExpectations(sb_service_.get()); | 924 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 830 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 925 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 831 | 926 |
| 832 // Now check with an executable in the zip file as well. | 927 // Now check with an executable in the zip file as well. |
| 833 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile( | 928 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile( |
| 834 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.exe")), | 929 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.exe")), |
| 835 file_contents.data(), file_contents.size())); | 930 file_contents.data(), file_contents.size())); |
| 836 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false)); | 931 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false)); |
| 837 | 932 |
| 838 EXPECT_CALL(*sb_service_->mock_database_manager(), | 933 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 839 MatchDownloadWhitelistUrl(_)) | 934 MatchDownloadWhitelistUrl(_)) |
| 840 .WillRepeatedly(Return(false)); | 935 .WillRepeatedly(Return(false)); |
| 841 | 936 |
| 842 download_service_->CheckClientDownload( | 937 download_service_->CheckClientDownload( |
| 843 &item, | 938 &item, |
| 844 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 939 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 845 base::Unretained(this))); | 940 base::Unretained(this))); |
| 846 MessageLoop::current()->Run(); | 941 MessageLoop::current()->Run(); |
| 847 #if defined(OS_WIN) | 942 #if defined(OS_WIN) |
| 848 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 943 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 849 #else | 944 #else |
| 850 // For !OS_WIN, no file types are currently supported. Hence the resulting | 945 // For !OS_WIN, no file types are currently supported. Hence the resulting |
| 851 // verdict is UNKNOWN. | 946 // verdict is UNKNOWN. |
| 852 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 947 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 853 #endif | 948 #endif |
| 949 |
| 950 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 951 // OSX sends pings for evaluation purposes. |
| 952 EXPECT_TRUE(HasClientDownloadRequest()); |
| 953 ClearClientDownloadRequest(); |
| 954 #else |
| 955 EXPECT_FALSE(HasClientDownloadRequest()); |
| 956 #endif |
| 854 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 957 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 855 | 958 |
| 856 // If the response is dangerous the result should also be marked as | 959 // If the response is dangerous the result should also be marked as |
| 857 // dangerous. | 960 // dangerous. |
| 858 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 961 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
| 859 factory.SetFakeResponse( | 962 factory.SetFakeResponse( |
| 860 DownloadProtectionService::GetDownloadRequestUrl(), | 963 DownloadProtectionService::GetDownloadRequestUrl(), |
| 861 response.SerializeAsString(), | 964 response.SerializeAsString(), |
| 862 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 965 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 863 | 966 |
| 864 download_service_->CheckClientDownload( | 967 download_service_->CheckClientDownload( |
| 865 &item, | 968 &item, |
| 866 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 969 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 867 base::Unretained(this))); | 970 base::Unretained(this))); |
| 868 MessageLoop::current()->Run(); | 971 MessageLoop::current()->Run(); |
| 869 #if defined(OS_WIN) | 972 #if defined(OS_WIN) |
| 870 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 973 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 871 #else | 974 #else |
| 872 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 975 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 873 #endif | 976 #endif |
| 977 |
| 978 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 979 // OSX sends pings for evaluation purposes. |
| 980 EXPECT_TRUE(HasClientDownloadRequest()); |
| 981 ClearClientDownloadRequest(); |
| 982 #else |
| 983 EXPECT_FALSE(HasClientDownloadRequest()); |
| 984 #endif |
| 874 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 985 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 875 } | 986 } |
| 876 | 987 |
| 877 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) { | 988 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) { |
| 878 base::ScopedTempDir download_dir; | 989 base::ScopedTempDir download_dir; |
| 879 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); | 990 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); |
| 880 | 991 |
| 881 base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp"))); | 992 base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp"))); |
| 882 base::FilePath a_zip(FILE_PATH_LITERAL("a.zip")); | 993 base::FilePath a_zip(FILE_PATH_LITERAL("a.zip")); |
| 883 std::vector<GURL> url_chain; | 994 std::vector<GURL> url_chain; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 901 std::string file_contents = "corrupt zip file"; | 1012 std::string file_contents = "corrupt zip file"; |
| 902 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile( | 1013 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile( |
| 903 a_tmp, file_contents.data(), file_contents.size())); | 1014 a_tmp, file_contents.data(), file_contents.size())); |
| 904 | 1015 |
| 905 download_service_->CheckClientDownload( | 1016 download_service_->CheckClientDownload( |
| 906 &item, | 1017 &item, |
| 907 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1018 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 908 base::Unretained(this))); | 1019 base::Unretained(this))); |
| 909 MessageLoop::current()->Run(); | 1020 MessageLoop::current()->Run(); |
| 910 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1021 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 1022 EXPECT_FALSE(HasClientDownloadRequest()); |
| 911 Mock::VerifyAndClearExpectations(sb_service_.get()); | 1023 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 912 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 1024 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 913 } | 1025 } |
| 914 | 1026 |
| 915 TEST_F(DownloadProtectionServiceTest, CheckClientCrxDownloadSuccess) { | 1027 TEST_F(DownloadProtectionServiceTest, CheckClientCrxDownloadSuccess) { |
| 916 ClientDownloadResponse response; | 1028 ClientDownloadResponse response; |
| 917 // Even if the server verdict is dangerous we should return SAFE because | 1029 // Even if the server verdict is dangerous we should return SAFE because |
| 918 // DownloadProtectionService::IsSupportedDownload() will return false | 1030 // DownloadProtectionService::IsSupportedDownload() will return false |
| 919 // for crx downloads. | 1031 // for crx downloads. |
| 920 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 1032 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 .WillOnce(SetDosHeaderContents("dummy dos header")); | 1115 .WillOnce(SetDosHeaderContents("dummy dos header")); |
| 1004 download_service_->CheckClientDownload( | 1116 download_service_->CheckClientDownload( |
| 1005 &item, | 1117 &item, |
| 1006 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1118 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1007 base::Unretained(this))); | 1119 base::Unretained(this))); |
| 1008 | 1120 |
| 1009 // SendRequest is not called. Wait for FinishRequest to call our callback. | 1121 // SendRequest is not called. Wait for FinishRequest to call our callback. |
| 1010 MessageLoop::current()->Run(); | 1122 MessageLoop::current()->Run(); |
| 1011 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1123 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 1012 EXPECT_EQ(NULL, fetcher); | 1124 EXPECT_EQ(NULL, fetcher); |
| 1125 EXPECT_FALSE(HasClientDownloadRequest()); |
| 1013 } | 1126 } |
| 1014 #endif | 1127 #endif |
| 1015 | 1128 |
| 1016 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { | 1129 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { |
| 1017 net::TestURLFetcherFactory factory; | 1130 net::TestURLFetcherFactory factory; |
| 1018 | 1131 |
| 1019 base::FilePath tmp_path(FILE_PATH_LITERAL("bla.tmp")); | 1132 base::FilePath tmp_path(FILE_PATH_LITERAL("bla.tmp")); |
| 1020 base::FilePath final_path(FILE_PATH_LITERAL("bla.exe")); | 1133 base::FilePath final_path(FILE_PATH_LITERAL("bla.exe")); |
| 1021 std::vector<GURL> url_chain; | 1134 std::vector<GURL> url_chain; |
| 1022 url_chain.push_back(GURL("http://www.google.com/")); | 1135 url_chain.push_back(GURL("http://www.google.com/")); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1049 download_service_->CheckClientDownload( | 1162 download_service_->CheckClientDownload( |
| 1050 &item, | 1163 &item, |
| 1051 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1164 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1052 base::Unretained(this))); | 1165 base::Unretained(this))); |
| 1053 | 1166 |
| 1054 #if !defined(OS_WIN) && !defined(OS_MACOSX) | 1167 #if !defined(OS_WIN) && !defined(OS_MACOSX) |
| 1055 // SendRequest is not called. Wait for FinishRequest to call our callback. | 1168 // SendRequest is not called. Wait for FinishRequest to call our callback. |
| 1056 MessageLoop::current()->Run(); | 1169 MessageLoop::current()->Run(); |
| 1057 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1170 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 1058 EXPECT_EQ(NULL, fetcher); | 1171 EXPECT_EQ(NULL, fetcher); |
| 1172 EXPECT_FALSE(HasClientDownloadRequest()); |
| 1059 #else | 1173 #else |
| 1060 // Run the message loop(s) until SendRequest is called. | 1174 // Run the message loop(s) until SendRequest is called. |
| 1061 FlushThreadMessageLoops(); | 1175 FlushThreadMessageLoops(); |
| 1176 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1177 ClearClientDownloadRequest(); |
| 1062 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1178 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 1063 ASSERT_TRUE(fetcher); | 1179 ASSERT_TRUE(fetcher); |
| 1064 ClientDownloadRequest request; | 1180 ClientDownloadRequest request; |
| 1065 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); | 1181 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); |
| 1066 EXPECT_EQ("http://www.google.com/bla.exe", request.url()); | 1182 EXPECT_EQ("http://www.google.com/bla.exe", request.url()); |
| 1067 EXPECT_EQ(hash, request.digests().sha256()); | 1183 EXPECT_EQ(hash, request.digests().sha256()); |
| 1068 EXPECT_EQ(item.GetReceivedBytes(), request.length()); | 1184 EXPECT_EQ(item.GetReceivedBytes(), request.length()); |
| 1069 EXPECT_EQ(item.HasUserGesture(), request.user_initiated()); | 1185 EXPECT_EQ(item.HasUserGesture(), request.user_initiated()); |
| 1070 EXPECT_TRUE(RequestContainsServerIp(request, remote_address)); | 1186 EXPECT_TRUE(RequestContainsServerIp(request, remote_address)); |
| 1071 EXPECT_EQ(2, request.resources_size()); | 1187 EXPECT_EQ(2, request.resources_size()); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 download_service_->CheckClientDownload( | 1250 download_service_->CheckClientDownload( |
| 1135 &item, | 1251 &item, |
| 1136 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1252 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1137 base::Unretained(this))); | 1253 base::Unretained(this))); |
| 1138 | 1254 |
| 1139 #if !defined(OS_WIN) && !defined(OS_MACOSX) | 1255 #if !defined(OS_WIN) && !defined(OS_MACOSX) |
| 1140 // SendRequest is not called. Wait for FinishRequest to call our callback. | 1256 // SendRequest is not called. Wait for FinishRequest to call our callback. |
| 1141 MessageLoop::current()->Run(); | 1257 MessageLoop::current()->Run(); |
| 1142 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1258 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 1143 EXPECT_EQ(NULL, fetcher); | 1259 EXPECT_EQ(NULL, fetcher); |
| 1260 EXPECT_FALSE(HasClientDownloadRequest()); |
| 1144 #else | 1261 #else |
| 1145 // Run the message loop(s) until SendRequest is called. | 1262 // Run the message loop(s) until SendRequest is called. |
| 1146 FlushThreadMessageLoops(); | 1263 FlushThreadMessageLoops(); |
| 1264 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1265 ClearClientDownloadRequest(); |
| 1147 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1266 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 1148 ASSERT_TRUE(fetcher); | 1267 ASSERT_TRUE(fetcher); |
| 1149 ClientDownloadRequest request; | 1268 ClientDownloadRequest request; |
| 1150 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); | 1269 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); |
| 1151 EXPECT_EQ("ftp://www.google.com/bla.exe", request.url()); | 1270 EXPECT_EQ("ftp://www.google.com/bla.exe", request.url()); |
| 1152 EXPECT_EQ(hash, request.digests().sha256()); | 1271 EXPECT_EQ(hash, request.digests().sha256()); |
| 1153 EXPECT_EQ(item.GetReceivedBytes(), request.length()); | 1272 EXPECT_EQ(item.GetReceivedBytes(), request.length()); |
| 1154 EXPECT_EQ(item.HasUserGesture(), request.user_initiated()); | 1273 EXPECT_EQ(item.HasUserGesture(), request.user_initiated()); |
| 1155 EXPECT_EQ(2, request.resources_size()); | 1274 EXPECT_EQ(2, request.resources_size()); |
| 1156 EXPECT_TRUE(RequestContainsResource(request, | 1275 EXPECT_TRUE(RequestContainsResource(request, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 download_service_->CheckClientDownload( | 1341 download_service_->CheckClientDownload( |
| 1223 &item, | 1342 &item, |
| 1224 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1343 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1225 base::Unretained(this))); | 1344 base::Unretained(this))); |
| 1226 | 1345 |
| 1227 #if !defined(OS_WIN) && !defined(OS_MACOSX) | 1346 #if !defined(OS_WIN) && !defined(OS_MACOSX) |
| 1228 // SendRequest is not called. Wait for FinishRequest to call our callback. | 1347 // SendRequest is not called. Wait for FinishRequest to call our callback. |
| 1229 MessageLoop::current()->Run(); | 1348 MessageLoop::current()->Run(); |
| 1230 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1349 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 1231 EXPECT_EQ(NULL, fetcher); | 1350 EXPECT_EQ(NULL, fetcher); |
| 1351 EXPECT_FALSE(HasClientDownloadRequest()); |
| 1232 #else | 1352 #else |
| 1233 EXPECT_EQ(0, fetcher_watcher.WaitForRequest()); | 1353 EXPECT_EQ(0, fetcher_watcher.WaitForRequest()); |
| 1354 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1355 ClearClientDownloadRequest(); |
| 1234 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1356 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 1235 ASSERT_TRUE(fetcher); | 1357 ASSERT_TRUE(fetcher); |
| 1236 ClientDownloadRequest request; | 1358 ClientDownloadRequest request; |
| 1237 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); | 1359 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); |
| 1238 EXPECT_EQ("http://www.google.com/bla.exe", request.url()); | 1360 EXPECT_EQ("http://www.google.com/bla.exe", request.url()); |
| 1239 EXPECT_EQ(hash, request.digests().sha256()); | 1361 EXPECT_EQ(hash, request.digests().sha256()); |
| 1240 EXPECT_EQ(item.GetReceivedBytes(), request.length()); | 1362 EXPECT_EQ(item.GetReceivedBytes(), request.length()); |
| 1241 EXPECT_EQ(item.HasUserGesture(), request.user_initiated()); | 1363 EXPECT_EQ(item.HasUserGesture(), request.user_initiated()); |
| 1242 EXPECT_TRUE(RequestContainsServerIp(request, remote_address)); | 1364 EXPECT_TRUE(RequestContainsServerIp(request, remote_address)); |
| 1243 EXPECT_EQ(3, request.resources_size()); | 1365 EXPECT_EQ(3, request.resources_size()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1297 TestURLFetcherWatcher fetcher_watcher(&factory); | 1419 TestURLFetcherWatcher fetcher_watcher(&factory); |
| 1298 download_service_->CheckClientDownload( | 1420 download_service_->CheckClientDownload( |
| 1299 &item, | 1421 &item, |
| 1300 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1422 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1301 base::Unretained(this))); | 1423 base::Unretained(this))); |
| 1302 #if !defined(OS_WIN) && !defined(OS_MACOSX) | 1424 #if !defined(OS_WIN) && !defined(OS_MACOSX) |
| 1303 // SendRequest is not called. Wait for FinishRequest to call our callback. | 1425 // SendRequest is not called. Wait for FinishRequest to call our callback. |
| 1304 MessageLoop::current()->Run(); | 1426 MessageLoop::current()->Run(); |
| 1305 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1427 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 1306 EXPECT_EQ(NULL, fetcher); | 1428 EXPECT_EQ(NULL, fetcher); |
| 1429 EXPECT_FALSE(HasClientDownloadRequest()); |
| 1307 #else | 1430 #else |
| 1308 EXPECT_EQ(0, fetcher_watcher.WaitForRequest()); | 1431 EXPECT_EQ(0, fetcher_watcher.WaitForRequest()); |
| 1432 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1433 ClearClientDownloadRequest(); |
| 1309 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1434 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 1310 ASSERT_TRUE(fetcher); | 1435 ASSERT_TRUE(fetcher); |
| 1311 ClientDownloadRequest request; | 1436 ClientDownloadRequest request; |
| 1312 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); | 1437 EXPECT_TRUE(request.ParseFromString(fetcher->upload_data())); |
| 1313 EXPECT_EQ("http://www.google.com/bla.exe", request.url()); | 1438 EXPECT_EQ("http://www.google.com/bla.exe", request.url()); |
| 1314 EXPECT_EQ(hash, request.digests().sha256()); | 1439 EXPECT_EQ(hash, request.digests().sha256()); |
| 1315 EXPECT_EQ(item.GetReceivedBytes(), request.length()); | 1440 EXPECT_EQ(item.GetReceivedBytes(), request.length()); |
| 1316 EXPECT_EQ(item.HasUserGesture(), request.user_initiated()); | 1441 EXPECT_EQ(item.HasUserGesture(), request.user_initiated()); |
| 1317 EXPECT_TRUE(RequestContainsServerIp(request, remote_address)); | 1442 EXPECT_TRUE(RequestContainsServerIp(request, remote_address)); |
| 1318 EXPECT_EQ(5, request.resources_size()); | 1443 EXPECT_EQ(5, request.resources_size()); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 download_service_->download_request_timeout_ms_ = 10; | 1578 download_service_->download_request_timeout_ms_ = 10; |
| 1454 download_service_->CheckClientDownload( | 1579 download_service_->CheckClientDownload( |
| 1455 &item, | 1580 &item, |
| 1456 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1581 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1457 base::Unretained(this))); | 1582 base::Unretained(this))); |
| 1458 | 1583 |
| 1459 // The request should time out because the HTTP request hasn't returned | 1584 // The request should time out because the HTTP request hasn't returned |
| 1460 // anything yet. | 1585 // anything yet. |
| 1461 MessageLoop::current()->Run(); | 1586 MessageLoop::current()->Run(); |
| 1462 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1587 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 1588 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 1589 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1590 ClearClientDownloadRequest(); |
| 1591 #else |
| 1592 EXPECT_FALSE(HasClientDownloadRequest()); |
| 1593 #endif |
| 1463 } | 1594 } |
| 1464 | 1595 |
| 1465 TEST_F(DownloadProtectionServiceTest, TestDownloadItemDestroyed) { | 1596 TEST_F(DownloadProtectionServiceTest, TestDownloadItemDestroyed) { |
| 1466 net::TestURLFetcherFactory factory; | 1597 net::TestURLFetcherFactory factory; |
| 1467 | 1598 |
| 1468 std::vector<GURL> url_chain; | 1599 std::vector<GURL> url_chain; |
| 1469 url_chain.push_back(GURL("http://www.evil.com/bla.exe")); | 1600 url_chain.push_back(GURL("http://www.evil.com/bla.exe")); |
| 1470 GURL referrer("http://www.google.com/"); | 1601 GURL referrer("http://www.google.com/"); |
| 1471 base::FilePath tmp_path(FILE_PATH_LITERAL("a.tmp")); | 1602 base::FilePath tmp_path(FILE_PATH_LITERAL("a.tmp")); |
| 1472 base::FilePath final_path(FILE_PATH_LITERAL("a.exe")); | 1603 base::FilePath final_path(FILE_PATH_LITERAL("a.exe")); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1496 | 1627 |
| 1497 download_service_->CheckClientDownload( | 1628 download_service_->CheckClientDownload( |
| 1498 &item, | 1629 &item, |
| 1499 base::Bind(&DownloadProtectionServiceTest::SyncCheckDoneCallback, | 1630 base::Bind(&DownloadProtectionServiceTest::SyncCheckDoneCallback, |
| 1500 base::Unretained(this))); | 1631 base::Unretained(this))); |
| 1501 // MockDownloadItem going out of scope triggers the OnDownloadDestroyed | 1632 // MockDownloadItem going out of scope triggers the OnDownloadDestroyed |
| 1502 // notification. | 1633 // notification. |
| 1503 } | 1634 } |
| 1504 | 1635 |
| 1505 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1636 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 1637 EXPECT_FALSE(HasClientDownloadRequest()); |
| 1506 } | 1638 } |
| 1507 | 1639 |
| 1508 TEST_F(DownloadProtectionServiceTest, GetCertificateWhitelistStrings) { | 1640 TEST_F(DownloadProtectionServiceTest, GetCertificateWhitelistStrings) { |
| 1509 // We'll pass this cert in as the "issuer", even though it isn't really | 1641 // We'll pass this cert in as the "issuer", even though it isn't really |
| 1510 // used to sign the certs below. GetCertificateWhitelistStirngs doesn't care | 1642 // used to sign the certs below. GetCertificateWhitelistStirngs doesn't care |
| 1511 // about this. | 1643 // about this. |
| 1512 scoped_refptr<net::X509Certificate> issuer_cert( | 1644 scoped_refptr<net::X509Certificate> issuer_cert( |
| 1513 ReadTestCertificate("issuer.pem")); | 1645 ReadTestCertificate("issuer.pem")); |
| 1514 ASSERT_TRUE(issuer_cert.get()); | 1646 ASSERT_TRUE(issuer_cert.get()); |
| 1515 std::string cert_base = "cert/" + base::HexEncode( | 1647 std::string cert_base = "cert/" + base::HexEncode( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1584 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); | 1716 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); |
| 1585 | 1717 |
| 1586 cert = ReadTestCertificate("test_c.pem"); | 1718 cert = ReadTestCertificate("test_c.pem"); |
| 1587 ASSERT_TRUE(cert.get()); | 1719 ASSERT_TRUE(cert.get()); |
| 1588 whitelist_strings.clear(); | 1720 whitelist_strings.clear(); |
| 1589 GetCertificateWhitelistStrings( | 1721 GetCertificateWhitelistStrings( |
| 1590 *cert.get(), *issuer_cert.get(), &whitelist_strings); | 1722 *cert.get(), *issuer_cert.get(), &whitelist_strings); |
| 1591 EXPECT_THAT(whitelist_strings, ElementsAre()); | 1723 EXPECT_THAT(whitelist_strings, ElementsAre()); |
| 1592 } | 1724 } |
| 1593 } // namespace safe_browsing | 1725 } // namespace safe_browsing |
| OLD | NEW |