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 "base/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/test/test_simple_task_runner.h" | 9 #include "base/test/test_simple_task_runner.h" |
10 #include "components/safe_browsing_db/v4_database.h" | 10 #include "components/safe_browsing_db/v4_database.h" |
11 #include "components/safe_browsing_db/v4_local_database_manager.h" | 11 #include "components/safe_browsing_db/v4_local_database_manager.h" |
12 #include "components/safe_browsing_db/v4_test_util.h" | 12 #include "components/safe_browsing_db/v4_test_util.h" |
13 #include "content/public/test/test_browser_thread_bundle.h" | 13 #include "content/public/test/test_browser_thread_bundle.h" |
| 14 #include "crypto/sha2.h" |
14 #include "net/url_request/test_url_fetcher_factory.h" | 15 #include "net/url_request/test_url_fetcher_factory.h" |
15 #include "testing/platform_test.h" | 16 #include "testing/platform_test.h" |
16 | 17 |
17 namespace safe_browsing { | 18 namespace safe_browsing { |
18 | 19 |
19 class FakeV4Database : public V4Database { | 20 class FakeV4Database : public V4Database { |
20 public: | 21 public: |
21 static void Create( | 22 static void Create( |
22 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 23 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
23 std::unique_ptr<StoreMap> store_map, | 24 std::unique_ptr<StoreMap> store_map, |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 EXPECT_FALSE(v4_local_database_manager_->MatchMalwareIP("192.168.1.1")); | 401 EXPECT_FALSE(v4_local_database_manager_->MatchMalwareIP("192.168.1.1")); |
401 EXPECT_FALSE(FakeV4LocalDatabaseManager::PerformFullHashCheckCalled( | 402 EXPECT_FALSE(FakeV4LocalDatabaseManager::PerformFullHashCheckCalled( |
402 v4_local_database_manager_)); | 403 v4_local_database_manager_)); |
403 | 404 |
404 // The fake database returns a matched hash prefix. | 405 // The fake database returns a matched hash prefix. |
405 EXPECT_TRUE(v4_local_database_manager_->MatchMalwareIP("192.168.1.2")); | 406 EXPECT_TRUE(v4_local_database_manager_->MatchMalwareIP("192.168.1.2")); |
406 EXPECT_FALSE(FakeV4LocalDatabaseManager::PerformFullHashCheckCalled( | 407 EXPECT_FALSE(FakeV4LocalDatabaseManager::PerformFullHashCheckCalled( |
407 v4_local_database_manager_)); | 408 v4_local_database_manager_)); |
408 } | 409 } |
409 | 410 |
| 411 TEST_F(V4LocalDatabaseManagerTest, TestMatchModuleWhitelist) { |
| 412 StopLocalDatabaseManager(); |
| 413 v4_local_database_manager_ = |
| 414 make_scoped_refptr(new FakeV4LocalDatabaseManager(base_dir_.GetPath())); |
| 415 SetTaskRunnerForTest(); |
| 416 StartLocalDatabaseManager(); |
| 417 WaitForTasksOnTaskRunner(); |
| 418 |
| 419 StoreAndHashPrefixes store_and_hash_prefixes; |
| 420 store_and_hash_prefixes.emplace_back(GetChromeFilenameClientIncidentId(), |
| 421 crypto::SHA256HashString("chrome.dll")); |
| 422 |
| 423 ReplaceV4Database(store_and_hash_prefixes); |
| 424 |
| 425 // No match -- i.e. not whitelisted |
| 426 EXPECT_FALSE( |
| 427 v4_local_database_manager_->MatchModuleWhitelistString("badstuff.dll")); |
| 428 |
| 429 // Whitelisted. |
| 430 EXPECT_TRUE( |
| 431 v4_local_database_manager_->MatchModuleWhitelistString("chrome.dll")); |
| 432 } |
| 433 |
410 } // namespace safe_browsing | 434 } // namespace safe_browsing |
OLD | NEW |