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 13 matching lines...) Expand all Loading... | |
| 24 typedef std::vector<FullHashInfo> FullHashInfos; | 24 typedef std::vector<FullHashInfo> FullHashInfos; |
| 25 | 25 |
| 26 // Utility function for populating hashes. | 26 // Utility function for populating hashes. |
| 27 FullHash HashForUrl(const GURL& url) { | 27 FullHash HashForUrl(const GURL& url) { |
| 28 std::vector<FullHash> full_hashes; | 28 std::vector<FullHash> full_hashes; |
| 29 V4ProtocolManagerUtil::UrlToFullHashes(url, &full_hashes); | 29 V4ProtocolManagerUtil::UrlToFullHashes(url, &full_hashes); |
| 30 // ASSERT_GE(full_hashes.size(), 1u); | 30 // ASSERT_GE(full_hashes.size(), 1u); |
| 31 return full_hashes[0]; | 31 return full_hashes[0]; |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Always returns misses from GetFullHashes(). | 34 // Use this if you want GetFullHashes() to always return prescribed results. |
| 35 class FakeGetHashProtocolManager : public V4GetHashProtocolManager { | 35 class FakeGetHashProtocolManager : public V4GetHashProtocolManager { |
| 36 public: | 36 public: |
| 37 FakeGetHashProtocolManager( | 37 FakeGetHashProtocolManager( |
| 38 net::URLRequestContextGetter* request_context_getter, | 38 net::URLRequestContextGetter* request_context_getter, |
| 39 const StoresToCheck& stores_to_check, | 39 const StoresToCheck& stores_to_check, |
| 40 const V4ProtocolConfig& config, | 40 const V4ProtocolConfig& config, |
| 41 const FullHashInfos& full_hash_infos) | 41 const FullHashInfos& full_hash_infos) |
| 42 : V4GetHashProtocolManager(request_context_getter, | 42 : V4GetHashProtocolManager(request_context_getter, |
| 43 stores_to_check, | 43 stores_to_check, |
| 44 config), | 44 config), |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 67 const V4ProtocolConfig& config) override { | 67 const V4ProtocolConfig& config) override { |
| 68 return base::MakeUnique<FakeGetHashProtocolManager>( | 68 return base::MakeUnique<FakeGetHashProtocolManager>( |
| 69 request_context_getter, stores_to_check, config, full_hash_infos_); | 69 request_context_getter, stores_to_check, config, full_hash_infos_); |
| 70 } | 70 } |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 FullHashInfos full_hash_infos_; | 73 FullHashInfos full_hash_infos_; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 // Use FakeGetHashProtocolManagerFactory in scope, then reset. | 76 // Use FakeGetHashProtocolManagerFactory in scope, then reset. |
| 77 // You should make sure the DatabaseManager is created _after_ this. | |
| 77 class ScopedFakeGetHashProtocolManagerFactory { | 78 class ScopedFakeGetHashProtocolManagerFactory { |
| 78 public: | 79 public: |
| 79 ScopedFakeGetHashProtocolManagerFactory( | 80 ScopedFakeGetHashProtocolManagerFactory( |
| 80 const FullHashInfos& full_hash_infos) { | 81 const FullHashInfos& full_hash_infos) { |
| 81 V4GetHashProtocolManager::RegisterFactory( | 82 V4GetHashProtocolManager::RegisterFactory( |
| 82 base::MakeUnique<FakeGetHashProtocolManagerFactory>(full_hash_infos)); | 83 base::MakeUnique<FakeGetHashProtocolManagerFactory>(full_hash_infos)); |
| 83 } | 84 } |
| 84 ~ScopedFakeGetHashProtocolManagerFactory() { | 85 ~ScopedFakeGetHashProtocolManagerFactory() { |
| 85 V4GetHashProtocolManager::RegisterFactory(nullptr); | 86 V4GetHashProtocolManager::RegisterFactory(nullptr); |
| 86 } | 87 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 106 callback_task_runner, new_db_callback, stores_available)); | 107 callback_task_runner, new_db_callback, stores_available)); |
| 107 } | 108 } |
| 108 | 109 |
| 109 // V4Database implementation | 110 // V4Database implementation |
| 110 void GetStoresMatchingFullHash( | 111 void GetStoresMatchingFullHash( |
| 111 const FullHash& full_hash, | 112 const FullHash& full_hash, |
| 112 const StoresToCheck& stores_to_check, | 113 const StoresToCheck& stores_to_check, |
| 113 StoreAndHashPrefixes* store_and_hash_prefixes) override { | 114 StoreAndHashPrefixes* store_and_hash_prefixes) override { |
| 114 store_and_hash_prefixes->clear(); | 115 store_and_hash_prefixes->clear(); |
| 115 for (const StoreAndHashPrefix& stored_sahp : store_and_hash_prefixes_) { | 116 for (const StoreAndHashPrefix& stored_sahp : store_and_hash_prefixes_) { |
| 117 if (stores_to_check.count(stored_sahp.list_id) == 0) | |
| 118 continue; | |
| 116 const PrefixSize& prefix_size = stored_sahp.hash_prefix.size(); | 119 const PrefixSize& prefix_size = stored_sahp.hash_prefix.size(); |
| 117 if (!full_hash.compare(0, prefix_size, stored_sahp.hash_prefix)) { | 120 if (!full_hash.compare(0, prefix_size, stored_sahp.hash_prefix)) { |
| 118 store_and_hash_prefixes->push_back(stored_sahp); | 121 store_and_hash_prefixes->push_back(stored_sahp); |
| 119 } | 122 } |
| 120 } | 123 } |
| 121 } | 124 } |
| 122 | 125 |
| 123 bool AreAllStoresAvailable( | 126 bool AreAllStoresAvailable( |
| 124 const StoresToCheck& stores_to_check) const override { | 127 const StoresToCheck& stores_to_check) const override { |
| 125 return stores_available_; | 128 return stores_available_; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 152 const StoreAndHashPrefixes& store_and_hash_prefixes, | 155 const StoreAndHashPrefixes& store_and_hash_prefixes, |
| 153 bool stores_available) | 156 bool stores_available) |
| 154 : V4Database(db_task_runner, std::move(store_map)), | 157 : V4Database(db_task_runner, std::move(store_map)), |
| 155 store_and_hash_prefixes_(store_and_hash_prefixes), | 158 store_and_hash_prefixes_(store_and_hash_prefixes), |
| 156 stores_available_(stores_available) {} | 159 stores_available_(stores_available) {} |
| 157 | 160 |
| 158 const StoreAndHashPrefixes store_and_hash_prefixes_; | 161 const StoreAndHashPrefixes store_and_hash_prefixes_; |
| 159 const bool stores_available_; | 162 const bool stores_available_; |
| 160 }; | 163 }; |
| 161 | 164 |
| 165 // TODO(nparker): This might be simpler with a mock and EXPECT calls. | |
|
vakh (use Gerrit instead)
2017/06/01 00:54:36
Feel free to assign it to me.
| |
| 166 // That would also catch unexpected calls. | |
| 162 class TestClient : public SafeBrowsingDatabaseManager::Client { | 167 class TestClient : public SafeBrowsingDatabaseManager::Client { |
| 163 public: | 168 public: |
| 164 TestClient(SBThreatType sb_threat_type, | 169 TestClient(SBThreatType sb_threat_type, |
| 165 const GURL& url, | 170 const GURL& url, |
| 166 V4LocalDatabaseManager* manager_to_cancel = nullptr) | 171 V4LocalDatabaseManager* manager_to_cancel = nullptr) |
| 167 : expected_sb_threat_type(sb_threat_type), | 172 : expected_sb_threat_type(sb_threat_type), |
| 168 expected_urls(1, url), | 173 expected_urls(1, url), |
| 169 on_check_browse_url_result_called_(false), | |
| 170 on_check_download_urls_result_called_(false), | |
| 171 on_check_resource_url_result_called_(false), | |
| 172 manager_to_cancel_(manager_to_cancel) {} | 174 manager_to_cancel_(manager_to_cancel) {} |
| 173 | 175 |
| 174 TestClient(SBThreatType sb_threat_type, const std::vector<GURL>& url_chain) | 176 TestClient(SBThreatType sb_threat_type, const std::vector<GURL>& url_chain) |
| 175 : expected_sb_threat_type(sb_threat_type), | 177 : expected_sb_threat_type(sb_threat_type), expected_urls(url_chain) {} |
| 176 expected_urls(url_chain), | |
| 177 on_check_browse_url_result_called_(false), | |
| 178 on_check_download_urls_result_called_(false), | |
| 179 on_check_resource_url_result_called_(false) {} | |
| 180 | 178 |
| 181 void OnCheckBrowseUrlResult(const GURL& url, | 179 void OnCheckBrowseUrlResult(const GURL& url, |
| 182 SBThreatType threat_type, | 180 SBThreatType threat_type, |
| 183 const ThreatMetadata& metadata) override { | 181 const ThreatMetadata& metadata) override { |
| 184 ASSERT_EQ(expected_urls[0], url); | 182 ASSERT_EQ(expected_urls[0], url); |
| 185 ASSERT_EQ(expected_sb_threat_type, threat_type); | 183 ASSERT_EQ(expected_sb_threat_type, threat_type); |
| 186 on_check_browse_url_result_called_ = true; | 184 on_check_browse_url_result_called_ = true; |
| 187 if (manager_to_cancel_) { | 185 if (manager_to_cancel_) { |
| 188 manager_to_cancel_->CancelCheck(this); | 186 manager_to_cancel_->CancelCheck(this); |
| 189 } | 187 } |
| 190 } | 188 } |
| 191 | 189 |
| 192 void OnCheckResourceUrlResult(const GURL& url, | 190 void OnCheckResourceUrlResult(const GURL& url, |
| 193 SBThreatType threat_type, | 191 SBThreatType threat_type, |
| 194 const std::string& threat_hash) override { | 192 const std::string& threat_hash) override { |
| 195 ASSERT_EQ(expected_urls[0], url); | 193 ASSERT_EQ(expected_urls[0], url); |
| 196 ASSERT_EQ(expected_sb_threat_type, threat_type); | 194 ASSERT_EQ(expected_sb_threat_type, threat_type); |
| 197 ASSERT_EQ(threat_type == SB_THREAT_TYPE_SAFE, threat_hash.empty()); | 195 ASSERT_EQ(threat_type == SB_THREAT_TYPE_SAFE, threat_hash.empty()); |
| 198 on_check_resource_url_result_called_ = true; | 196 on_check_resource_url_result_called_ = true; |
| 199 } | 197 } |
| 198 | |
| 200 void OnCheckDownloadUrlResult(const std::vector<GURL>& url_chain, | 199 void OnCheckDownloadUrlResult(const std::vector<GURL>& url_chain, |
| 201 SBThreatType threat_type) override { | 200 SBThreatType threat_type) override { |
| 202 ASSERT_EQ(expected_urls, url_chain); | 201 ASSERT_EQ(expected_urls, url_chain); |
| 203 ASSERT_EQ(expected_sb_threat_type, threat_type); | 202 ASSERT_EQ(expected_sb_threat_type, threat_type); |
| 204 on_check_download_urls_result_called_ = true; | 203 on_check_download_urls_result_called_ = true; |
| 205 } | 204 } |
| 206 | 205 |
| 207 SBThreatType expected_sb_threat_type; | 206 SBThreatType expected_sb_threat_type; |
| 208 std::vector<GURL> expected_urls; | 207 std::vector<GURL> expected_urls; |
| 209 bool on_check_browse_url_result_called_; | 208 bool on_check_browse_url_result_called_ = false; |
| 210 bool on_check_download_urls_result_called_; | 209 bool on_check_download_urls_result_called_ = false; |
| 211 bool on_check_resource_url_result_called_; | 210 bool on_check_resource_url_result_called_ = false; |
| 212 V4LocalDatabaseManager* manager_to_cancel_; | 211 V4LocalDatabaseManager* manager_to_cancel_; |
| 213 }; | 212 }; |
| 214 | 213 |
| 214 class TestWhitelistClient : public SafeBrowsingDatabaseManager::Client { | |
| 215 public: | |
| 216 explicit TestWhitelistClient(bool whitelist_expected) | |
| 217 : whitelist_expected_(whitelist_expected) {} | |
| 218 | |
| 219 void OnCheckWhitelistUrlResult(bool is_whitelisted) override { | |
| 220 EXPECT_EQ(whitelist_expected_, is_whitelisted); | |
| 221 callback_called_ = true; | |
| 222 } | |
| 223 | |
| 224 const bool whitelist_expected_; | |
| 225 bool callback_called_ = false; | |
| 226 }; | |
| 227 | |
| 215 class TestExtensionClient : public SafeBrowsingDatabaseManager::Client { | 228 class TestExtensionClient : public SafeBrowsingDatabaseManager::Client { |
| 216 public: | 229 public: |
| 217 TestExtensionClient(const std::set<FullHash>& expected_bad_crxs) | 230 TestExtensionClient(const std::set<FullHash>& expected_bad_crxs) |
| 218 : expected_bad_crxs(expected_bad_crxs), | 231 : expected_bad_crxs(expected_bad_crxs), |
| 219 on_check_extensions_result_called_(false) {} | 232 on_check_extensions_result_called_(false) {} |
| 220 | 233 |
| 221 void OnCheckExtensionsResult(const std::set<FullHash>& bad_crxs) override { | 234 void OnCheckExtensionsResult(const std::set<FullHash>& bad_crxs) override { |
| 222 EXPECT_EQ(expected_bad_crxs, bad_crxs); | 235 EXPECT_EQ(expected_bad_crxs, bad_crxs); |
| 223 on_check_extensions_result_called_ = true; | 236 on_check_extensions_result_called_ = true; |
| 224 } | 237 } |
| 225 | 238 |
| 226 const std::set<FullHash> expected_bad_crxs; | 239 const std::set<FullHash> expected_bad_crxs; |
| 227 bool on_check_extensions_result_called_; | 240 bool on_check_extensions_result_called_; |
| 228 }; | 241 }; |
| 229 | 242 |
| 230 class FakeV4LocalDatabaseManager : public V4LocalDatabaseManager { | 243 class FakeV4LocalDatabaseManager : public V4LocalDatabaseManager { |
| 231 public: | 244 public: |
| 245 FakeV4LocalDatabaseManager( | |
| 246 const base::FilePath& base_path, | |
| 247 ExtendedReportingLevelCallback extended_reporting_level_callback) | |
| 248 : V4LocalDatabaseManager(base_path, extended_reporting_level_callback), | |
| 249 perform_full_hash_check_called_(false) {} | |
| 250 | |
| 251 // V4LocalDatabaseManager impl: | |
| 232 void PerformFullHashCheck(std::unique_ptr<PendingCheck> check, | 252 void PerformFullHashCheck(std::unique_ptr<PendingCheck> check, |
| 233 const FullHashToStoreAndHashPrefixesMap& | 253 const FullHashToStoreAndHashPrefixesMap& |
| 234 full_hash_to_store_and_hash_prefixes) override { | 254 full_hash_to_store_and_hash_prefixes) override { |
| 235 perform_full_hash_check_called_ = true; | 255 perform_full_hash_check_called_ = true; |
| 236 } | 256 } |
| 237 | 257 |
| 238 FakeV4LocalDatabaseManager( | |
| 239 const base::FilePath& base_path, | |
| 240 ExtendedReportingLevelCallback extended_reporting_level_callback) | |
| 241 : V4LocalDatabaseManager(base_path, extended_reporting_level_callback), | |
| 242 perform_full_hash_check_called_(false) {} | |
| 243 | |
| 244 static bool PerformFullHashCheckCalled( | 258 static bool PerformFullHashCheckCalled( |
| 245 scoped_refptr<safe_browsing::V4LocalDatabaseManager>& v4_ldbm) { | 259 scoped_refptr<safe_browsing::V4LocalDatabaseManager>& v4_ldbm) { |
| 246 FakeV4LocalDatabaseManager* fake = | 260 FakeV4LocalDatabaseManager* fake = |
| 247 static_cast<FakeV4LocalDatabaseManager*>(v4_ldbm.get()); | 261 static_cast<FakeV4LocalDatabaseManager*>(v4_ldbm.get()); |
| 248 return fake->perform_full_hash_check_called_; | 262 return fake->perform_full_hash_check_called_; |
| 249 } | 263 } |
| 250 | 264 |
| 251 private: | 265 private: |
| 252 ~FakeV4LocalDatabaseManager() override {} | 266 ~FakeV4LocalDatabaseManager() override {} |
| 253 | 267 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 store_and_hash_prefixes.emplace_back(GetUrlMalwareId(), bad_hash_prefix); | 433 store_and_hash_prefixes.emplace_back(GetUrlMalwareId(), bad_hash_prefix); |
| 420 ReplaceV4Database(store_and_hash_prefixes); | 434 ReplaceV4Database(store_and_hash_prefixes); |
| 421 | 435 |
| 422 const GURL url_bad("https://" + url_bad_no_scheme); | 436 const GURL url_bad("https://" + url_bad_no_scheme); |
| 423 EXPECT_FALSE(v4_local_database_manager_->CheckBrowseUrl(url_bad, nullptr)); | 437 EXPECT_FALSE(v4_local_database_manager_->CheckBrowseUrl(url_bad, nullptr)); |
| 424 | 438 |
| 425 // Wait for PerformFullHashCheck to complete. | 439 // Wait for PerformFullHashCheck to complete. |
| 426 WaitForTasksOnTaskRunner(); | 440 WaitForTasksOnTaskRunner(); |
| 427 } | 441 } |
| 428 | 442 |
| 443 TEST_F(V4LocalDatabaseManagerTest, TestCheckCsdWhitelistWithPrefixMatch) { | |
| 444 // Setup to receive full-hash misses. We won't make URL requests. | |
| 445 ScopedFakeGetHashProtocolManagerFactory pin(FullHashInfos({})); | |
| 446 ResetLocalDatabaseManager(); | |
| 447 WaitForTasksOnTaskRunner(); | |
| 448 | |
| 449 std::string url_white_no_scheme("example.com/white/"); | |
| 450 FullHash white_full_hash(crypto::SHA256HashString(url_white_no_scheme)); | |
| 451 const HashPrefix white_hash_prefix(white_full_hash.substr(0, 5)); | |
| 452 StoreAndHashPrefixes store_and_hash_prefixes; | |
| 453 store_and_hash_prefixes.emplace_back(GetUrlCsdWhitelistId(), | |
| 454 white_hash_prefix); | |
| 455 ReplaceV4Database(store_and_hash_prefixes, true /* stores_available */); | |
| 456 | |
| 457 TestWhitelistClient client(false /* whitelist_expected */); | |
| 458 const GURL url_check("https://" + url_white_no_scheme); | |
| 459 EXPECT_EQ(AsyncMatch::ASYNC, v4_local_database_manager_->CheckCsdWhitelistUrl( | |
| 460 url_check, &client)); | |
| 461 | |
| 462 EXPECT_FALSE(client.callback_called_); | |
| 463 | |
| 464 // Wait for PerformFullHashCheck to complete. | |
| 465 WaitForTasksOnTaskRunner(); | |
| 466 EXPECT_TRUE(client.callback_called_); | |
| 467 } | |
| 468 | |
| 469 // This is like CsdWhitelistWithPrefixMatch, but we also verify the | |
| 470 // full-hash-match results in an appropriate callback value. | |
| 471 TEST_F(V4LocalDatabaseManagerTest, | |
| 472 TestCheckCsdWhitelistWithPrefixTheFullMatch) { | |
| 473 std::string url_white_no_scheme("example.com/white/"); | |
| 474 FullHash white_full_hash(crypto::SHA256HashString(url_white_no_scheme)); | |
| 475 | |
| 476 // Setup to receive full-hash hit. We won't make URL requests. | |
| 477 FullHashInfos infos( | |
| 478 {{white_full_hash, GetUrlCsdWhitelistId(), base::Time::Now()}}); | |
| 479 ScopedFakeGetHashProtocolManagerFactory pin(infos); | |
| 480 ResetLocalDatabaseManager(); | |
| 481 WaitForTasksOnTaskRunner(); | |
| 482 | |
| 483 const HashPrefix white_hash_prefix(white_full_hash.substr(0, 5)); | |
| 484 StoreAndHashPrefixes store_and_hash_prefixes; | |
| 485 store_and_hash_prefixes.emplace_back(GetUrlCsdWhitelistId(), | |
| 486 white_hash_prefix); | |
| 487 ReplaceV4Database(store_and_hash_prefixes, true /* stores_available */); | |
| 488 | |
| 489 TestWhitelistClient client(true /* whitelist_expected */); | |
| 490 const GURL url_check("https://" + url_white_no_scheme); | |
| 491 EXPECT_EQ(AsyncMatch::ASYNC, v4_local_database_manager_->CheckCsdWhitelistUrl( | |
| 492 url_check, &client)); | |
| 493 | |
| 494 EXPECT_FALSE(client.callback_called_); | |
| 495 | |
| 496 // Wait for PerformFullHashCheck to complete. | |
| 497 WaitForTasksOnTaskRunner(); | |
| 498 EXPECT_TRUE(client.callback_called_); | |
| 499 } | |
| 500 | |
| 501 TEST_F(V4LocalDatabaseManagerTest, TestCheckCsdWhitelistWithFullMatch) { | |
| 502 // Setup to receive full-hash misses. We won't make URL requests. | |
| 503 ScopedFakeGetHashProtocolManagerFactory pin(FullHashInfos({})); | |
| 504 ResetLocalDatabaseManager(); | |
| 505 WaitForTasksOnTaskRunner(); | |
| 506 | |
| 507 std::string url_white_no_scheme("example.com/white/"); | |
| 508 FullHash white_full_hash(crypto::SHA256HashString(url_white_no_scheme)); | |
| 509 StoreAndHashPrefixes store_and_hash_prefixes; | |
| 510 store_and_hash_prefixes.emplace_back(GetUrlCsdWhitelistId(), white_full_hash); | |
| 511 ReplaceV4Database(store_and_hash_prefixes, true /* stores_available */); | |
| 512 | |
| 513 TestWhitelistClient client(false /* whitelist_expected */); | |
| 514 const GURL url_check("https://" + url_white_no_scheme); | |
| 515 EXPECT_EQ(AsyncMatch::MATCH, v4_local_database_manager_->CheckCsdWhitelistUrl( | |
| 516 url_check, &client)); | |
| 517 | |
| 518 WaitForTasksOnTaskRunner(); | |
| 519 EXPECT_FALSE(client.callback_called_); | |
| 520 } | |
| 521 | |
| 522 TEST_F(V4LocalDatabaseManagerTest, TestCheckCsdWhitelistWithNoMatch) { | |
| 523 // Setup to receive full-hash misses. We won't make URL requests. | |
| 524 ScopedFakeGetHashProtocolManagerFactory pin(FullHashInfos({})); | |
| 525 ResetLocalDatabaseManager(); | |
| 526 WaitForTasksOnTaskRunner(); | |
| 527 | |
| 528 // Add a full hash that won't match the URL we check. | |
| 529 std::string url_white_no_scheme("example.com/white/"); | |
| 530 FullHash white_full_hash(crypto::SHA256HashString(url_white_no_scheme)); | |
| 531 StoreAndHashPrefixes store_and_hash_prefixes; | |
| 532 store_and_hash_prefixes.emplace_back(GetUrlMalwareId(), white_full_hash); | |
| 533 ReplaceV4Database(store_and_hash_prefixes, true /* stores_available */); | |
| 534 | |
| 535 TestWhitelistClient client(true /* whitelist_expected */); | |
| 536 const GURL url_check("https://other.com/"); | |
| 537 EXPECT_EQ( | |
| 538 AsyncMatch::NO_MATCH, | |
| 539 v4_local_database_manager_->CheckCsdWhitelistUrl(url_check, &client)); | |
| 540 | |
| 541 WaitForTasksOnTaskRunner(); | |
| 542 EXPECT_FALSE(client.callback_called_); | |
| 543 } | |
| 544 | |
| 545 // When whitelist is unavailable, all URLS should be whitelisted. | |
| 546 TEST_F(V4LocalDatabaseManagerTest, TestCheckCsdWhitelistUnavailable) { | |
| 547 // Setup to receive full-hash misses. We won't make URL requests. | |
| 548 ScopedFakeGetHashProtocolManagerFactory pin(FullHashInfos({})); | |
| 549 ResetLocalDatabaseManager(); | |
| 550 WaitForTasksOnTaskRunner(); | |
| 551 | |
| 552 StoreAndHashPrefixes store_and_hash_prefixes; | |
| 553 ReplaceV4Database(store_and_hash_prefixes, false /* stores_available */); | |
| 554 | |
| 555 TestWhitelistClient client(false /* whitelist_expected */); | |
| 556 const GURL url_check("https://other.com/"); | |
| 557 EXPECT_EQ(AsyncMatch::MATCH, v4_local_database_manager_->CheckCsdWhitelistUrl( | |
| 558 url_check, &client)); | |
| 559 | |
| 560 WaitForTasksOnTaskRunner(); | |
| 561 EXPECT_FALSE(client.callback_called_); | |
| 562 } | |
| 563 | |
| 429 TEST_F(V4LocalDatabaseManagerTest, | 564 TEST_F(V4LocalDatabaseManagerTest, |
| 430 TestCheckBrowseUrlReturnsNoMatchWhenDisabled) { | 565 TestCheckBrowseUrlReturnsNoMatchWhenDisabled) { |
| 431 WaitForTasksOnTaskRunner(); | 566 WaitForTasksOnTaskRunner(); |
| 432 | 567 |
| 433 // The same URL returns |false| in the previous test because | 568 // The same URL returns |false| in the previous test because |
| 434 // v4_local_database_manager_ is enabled. | 569 // v4_local_database_manager_ is enabled. |
| 435 ForceDisableLocalDatabaseManager(); | 570 ForceDisableLocalDatabaseManager(); |
| 436 | 571 |
| 437 EXPECT_TRUE(v4_local_database_manager_->CheckBrowseUrl( | 572 EXPECT_TRUE(v4_local_database_manager_->CheckBrowseUrl( |
| 438 GURL("http://example.com/a/"), nullptr)); | 573 GURL("http://example.com/a/"), nullptr)); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 664 EXPECT_FALSE(FakeV4LocalDatabaseManager::PerformFullHashCheckCalled( | 799 EXPECT_FALSE(FakeV4LocalDatabaseManager::PerformFullHashCheckCalled( |
| 665 v4_local_database_manager_)); | 800 v4_local_database_manager_)); |
| 666 } | 801 } |
| 667 | 802 |
| 668 TEST_F(V4LocalDatabaseManagerTest, TestMatchDownloadWhitelistUrl) { | 803 TEST_F(V4LocalDatabaseManagerTest, TestMatchDownloadWhitelistUrl) { |
| 669 SetupFakeManager(); | 804 SetupFakeManager(); |
| 670 GURL good_url("http://safe.com"); | 805 GURL good_url("http://safe.com"); |
| 671 GURL other_url("http://iffy.com"); | 806 GURL other_url("http://iffy.com"); |
| 672 | 807 |
| 673 StoreAndHashPrefixes store_and_hash_prefixes; | 808 StoreAndHashPrefixes store_and_hash_prefixes; |
| 674 store_and_hash_prefixes.emplace_back(GetCertCsdDownloadWhitelistId(), | 809 store_and_hash_prefixes.emplace_back(GetUrlCsdDownloadWhitelistId(), |
| 675 HashForUrl(good_url)); | 810 HashForUrl(good_url)); |
| 676 | 811 |
| 677 ReplaceV4Database(store_and_hash_prefixes, false /* not available */); | 812 ReplaceV4Database(store_and_hash_prefixes, false /* not available */); |
| 678 // Verify it defaults to false when DB is not available. | 813 // Verify it defaults to false when DB is not available. |
| 679 EXPECT_FALSE(v4_local_database_manager_->MatchDownloadWhitelistUrl(good_url)); | 814 EXPECT_FALSE(v4_local_database_manager_->MatchDownloadWhitelistUrl(good_url)); |
| 680 | 815 |
| 681 ReplaceV4Database(store_and_hash_prefixes, true /* available */); | 816 ReplaceV4Database(store_and_hash_prefixes, true /* available */); |
| 682 // Not whitelisted. | 817 // Not whitelisted. |
| 683 EXPECT_FALSE( | 818 EXPECT_FALSE( |
| 684 v4_local_database_manager_->MatchDownloadWhitelistUrl(other_url)); | 819 v4_local_database_manager_->MatchDownloadWhitelistUrl(other_url)); |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 960 | 1095 |
| 961 TestClient client(SB_THREAT_TYPE_BINARY_MALWARE_URL, url_chain); | 1096 TestClient client(SB_THREAT_TYPE_BINARY_MALWARE_URL, url_chain); |
| 962 EXPECT_FALSE( | 1097 EXPECT_FALSE( |
| 963 v4_local_database_manager_->CheckDownloadUrl(url_chain, &client)); | 1098 v4_local_database_manager_->CheckDownloadUrl(url_chain, &client)); |
| 964 EXPECT_FALSE(client.on_check_download_urls_result_called_); | 1099 EXPECT_FALSE(client.on_check_download_urls_result_called_); |
| 965 WaitForTasksOnTaskRunner(); | 1100 WaitForTasksOnTaskRunner(); |
| 966 EXPECT_TRUE(client.on_check_download_urls_result_called_); | 1101 EXPECT_TRUE(client.on_check_download_urls_result_called_); |
| 967 } | 1102 } |
| 968 | 1103 |
| 969 } // namespace safe_browsing | 1104 } // namespace safe_browsing |
| OLD | NEW |