Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/safe_browsing_db/v4_local_database_manager.h" | 5 #include "components/safe_browsing_db/v4_local_database_manager.h" |
| 6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 store_and_hash_prefixes.emplace_back(GetUrlMalwareId(), bad_hash_prefix); | 419 store_and_hash_prefixes.emplace_back(GetUrlMalwareId(), bad_hash_prefix); |
| 420 ReplaceV4Database(store_and_hash_prefixes); | 420 ReplaceV4Database(store_and_hash_prefixes); |
| 421 | 421 |
| 422 const GURL url_bad("https://" + url_bad_no_scheme); | 422 const GURL url_bad("https://" + url_bad_no_scheme); |
| 423 EXPECT_FALSE(v4_local_database_manager_->CheckBrowseUrl(url_bad, nullptr)); | 423 EXPECT_FALSE(v4_local_database_manager_->CheckBrowseUrl(url_bad, nullptr)); |
| 424 | 424 |
| 425 // Wait for PerformFullHashCheck to complete. | 425 // Wait for PerformFullHashCheck to complete. |
| 426 WaitForTasksOnTaskRunner(); | 426 WaitForTasksOnTaskRunner(); |
| 427 } | 427 } |
| 428 | 428 |
| 429 TEST_F(V4LocalDatabaseManagerTest, TestCheckCsdWhitelistWithPrefixMatch) { | |
| 430 WaitForTasksOnTaskRunner(); | |
| 431 net::TestURLFetcherFactory factory; | |
| 432 | |
| 433 std::string url_white_no_scheme("example.com/white/"); | |
| 434 FullHash white_full_hash(crypto::SHA256HashString(url_white_no_scheme)); | |
| 435 const HashPrefix white_hash_prefix(white_full_hash.substr(0, 5)); | |
| 436 StoreAndHashPrefixes store_and_hash_prefixes; | |
| 437 store_and_hash_prefixes.emplace_back(GetUrlMalwareId(), white_hash_prefix); | |
| 438 ReplaceV4Database(store_and_hash_prefixes, true /* stores_available */); | |
| 439 | |
| 440 const GURL url_check("https://" + url_white_no_scheme); | |
| 441 EXPECT_EQ(AsyncMatch::ASYNC, v4_local_database_manager_->CheckCsdWhitelistUrl( | |
|
vakh (use Gerrit instead)
2017/05/24 16:01:17
Either I am reading this incorrectly, or there's a
Nathan Parker
2017/05/31 23:40:11
Huh! Ah -- found a missing check in the fake GetS
| |
| 442 url_check, nullptr)); | |
| 443 | |
| 444 // Wait for PerformFullHashCheck to complete. | |
| 445 WaitForTasksOnTaskRunner(); | |
| 446 // TODO(nparker): Verify full-hash-check fired? | |
|
vakh (use Gerrit instead)
2017/05/24 16:01:17
For the TODO, you could use the TestClient to veri
Nathan Parker
2017/05/31 23:40:11
Good idea -- this also check that the callback is
| |
| 447 } | |
| 448 | |
| 449 TEST_F(V4LocalDatabaseManagerTest, TestCheckCsdWhitelistWithFullMatch) { | |
| 450 WaitForTasksOnTaskRunner(); | |
| 451 net::TestURLFetcherFactory factory; | |
| 452 | |
| 453 std::string url_white_no_scheme("example.com/white/"); | |
| 454 FullHash white_full_hash(crypto::SHA256HashString(url_white_no_scheme)); | |
| 455 StoreAndHashPrefixes store_and_hash_prefixes; | |
| 456 store_and_hash_prefixes.emplace_back(GetUrlMalwareId(), white_full_hash); | |
| 457 ReplaceV4Database(store_and_hash_prefixes, true /* stores_available */); | |
| 458 | |
| 459 const GURL url_check("https://" + url_white_no_scheme); | |
| 460 EXPECT_EQ(AsyncMatch::MATCH, v4_local_database_manager_->CheckCsdWhitelistUrl( | |
| 461 url_check, nullptr)); | |
| 462 | |
| 463 // TODO(nparker): Verify no hash-check was scheduled. | |
| 464 WaitForTasksOnTaskRunner(); | |
| 465 } | |
| 466 | |
| 467 TEST_F(V4LocalDatabaseManagerTest, TestCheckCsdWhitelistWithNoMatch) { | |
| 468 WaitForTasksOnTaskRunner(); | |
| 469 net::TestURLFetcherFactory factory; | |
| 470 | |
| 471 // Add a full hash that won't match the URL we check. | |
| 472 std::string url_white_no_scheme("example.com/white/"); | |
| 473 FullHash white_full_hash(crypto::SHA256HashString(url_white_no_scheme)); | |
| 474 StoreAndHashPrefixes store_and_hash_prefixes; | |
| 475 store_and_hash_prefixes.emplace_back(GetUrlMalwareId(), white_full_hash); | |
| 476 ReplaceV4Database(store_and_hash_prefixes, true /* stores_available */); | |
| 477 | |
| 478 const GURL url_check("https://other.com/"); | |
| 479 EXPECT_EQ( | |
| 480 AsyncMatch::NO_MATCH, | |
| 481 v4_local_database_manager_->CheckCsdWhitelistUrl(url_check, nullptr)); | |
| 482 | |
| 483 // TODO(nparker): Verify no hash-check was scheduled. | |
| 484 WaitForTasksOnTaskRunner(); | |
| 485 } | |
| 486 | |
| 487 // When whitelist is unavailable, all URLS should be whitelisted. | |
| 488 TEST_F(V4LocalDatabaseManagerTest, TestCheckCsdWhitelistUnavailable) { | |
| 489 WaitForTasksOnTaskRunner(); | |
| 490 net::TestURLFetcherFactory factory; | |
| 491 | |
| 492 StoreAndHashPrefixes store_and_hash_prefixes; | |
| 493 ReplaceV4Database(store_and_hash_prefixes, false /* stores_available */); | |
| 494 | |
| 495 const GURL url_check("https://other.com/"); | |
| 496 EXPECT_EQ(AsyncMatch::MATCH, v4_local_database_manager_->CheckCsdWhitelistUrl( | |
| 497 url_check, nullptr)); | |
| 498 | |
| 499 // TODO(nparker): Verify no hash-check was scheduled. | |
| 500 WaitForTasksOnTaskRunner(); | |
| 501 } | |
| 502 | |
| 429 TEST_F(V4LocalDatabaseManagerTest, | 503 TEST_F(V4LocalDatabaseManagerTest, |
| 430 TestCheckBrowseUrlReturnsNoMatchWhenDisabled) { | 504 TestCheckBrowseUrlReturnsNoMatchWhenDisabled) { |
| 431 WaitForTasksOnTaskRunner(); | 505 WaitForTasksOnTaskRunner(); |
| 432 | 506 |
| 433 // The same URL returns |false| in the previous test because | 507 // The same URL returns |false| in the previous test because |
| 434 // v4_local_database_manager_ is enabled. | 508 // v4_local_database_manager_ is enabled. |
| 435 ForceDisableLocalDatabaseManager(); | 509 ForceDisableLocalDatabaseManager(); |
| 436 | 510 |
| 437 EXPECT_TRUE(v4_local_database_manager_->CheckBrowseUrl( | 511 EXPECT_TRUE(v4_local_database_manager_->CheckBrowseUrl( |
| 438 GURL("http://example.com/a/"), nullptr)); | 512 GURL("http://example.com/a/"), nullptr)); |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 960 | 1034 |
| 961 TestClient client(SB_THREAT_TYPE_BINARY_MALWARE_URL, url_chain); | 1035 TestClient client(SB_THREAT_TYPE_BINARY_MALWARE_URL, url_chain); |
| 962 EXPECT_FALSE( | 1036 EXPECT_FALSE( |
| 963 v4_local_database_manager_->CheckDownloadUrl(url_chain, &client)); | 1037 v4_local_database_manager_->CheckDownloadUrl(url_chain, &client)); |
| 964 EXPECT_FALSE(client.on_check_download_urls_result_called_); | 1038 EXPECT_FALSE(client.on_check_download_urls_result_called_); |
| 965 WaitForTasksOnTaskRunner(); | 1039 WaitForTasksOnTaskRunner(); |
| 966 EXPECT_TRUE(client.on_check_download_urls_result_called_); | 1040 EXPECT_TRUE(client.on_check_download_urls_result_called_); |
| 967 } | 1041 } |
| 968 | 1042 |
| 969 } // namespace safe_browsing | 1043 } // namespace safe_browsing |
| OLD | NEW |