Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: components/safe_browsing_db/v4_store_unittest.cc

Issue 2614763002: DCHECK that full hash must be 21 bytes or 32 bytes long. (Closed)
Patch Set: Change DCHECK to accept 32 or 21 size. Add unit test. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/safe_browsing_db/v4_store.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/base64.h" 5 #include "base/base64.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 } 666 }
667 667
668 TEST_F(V4StoreTest, TestHashPrefixDoesNotExistInMapWithDifferentSizes) { 668 TEST_F(V4StoreTest, TestHashPrefixDoesNotExistInMapWithDifferentSizes) {
669 V4Store store(task_runner_, store_path_); 669 V4Store store(task_runner_, store_path_);
670 store.hash_prefix_map_[4] = "3333aaaa"; 670 store.hash_prefix_map_[4] = "3333aaaa";
671 store.hash_prefix_map_[5] = "11111hhhhh"; 671 store.hash_prefix_map_[5] = "11111hhhhh";
672 FullHash full_hash = "22222222222222222222222222222222"; 672 FullHash full_hash = "22222222222222222222222222222222";
673 EXPECT_TRUE(store.GetMatchingHashPrefix(full_hash).empty()); 673 EXPECT_TRUE(store.GetMatchingHashPrefix(full_hash).empty());
674 } 674 }
675 675
676 TEST_F(V4StoreTest, GetMatchingHashPrefixSize32Or21) {
677 HashPrefix prefix = "0123";
678 V4Store store(task_runner_, store_path_);
679 store.hash_prefix_map_[4] = prefix;
680
681 FullHash full_hash_21 = "0123456789ABCDEF01234";
682 EXPECT_EQ(prefix, store.GetMatchingHashPrefix(full_hash_21));
683 FullHash full_hash_32 = "0123456789ABCDEF0123456789ABCDEF";
684 EXPECT_EQ(prefix, store.GetMatchingHashPrefix(full_hash_32));
685 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
686 // This hits a DCHECK so it is release mode only.
687 FullHash full_hash_22 = "0123456789ABCDEF012345";
688 EXPECT_EQ(prefix, store.GetMatchingHashPrefix(full_hash_22));
689 #endif
690 }
691
676 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 692 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
677 // This test hits a NOTREACHED so it is a release mode only test. 693 // This test hits a NOTREACHED so it is a release mode only test.
678 TEST_F(V4StoreTest, TestAdditionsWithRiceEncodingFailsWithInvalidInput) { 694 TEST_F(V4StoreTest, TestAdditionsWithRiceEncodingFailsWithInvalidInput) {
679 RepeatedPtrField<ThreatEntrySet> additions; 695 RepeatedPtrField<ThreatEntrySet> additions;
680 ThreatEntrySet* addition = additions.Add(); 696 ThreatEntrySet* addition = additions.Add();
681 addition->set_compression_type(RICE); 697 addition->set_compression_type(RICE);
682 addition->mutable_rice_hashes()->set_num_entries(-1); 698 addition->mutable_rice_hashes()->set_num_entries(-1);
683 HashPrefixMap additions_map; 699 HashPrefixMap additions_map;
684 EXPECT_EQ(RICE_DECODING_FAILURE, 700 EXPECT_EQ(RICE_DECODING_FAILURE,
685 V4Store(task_runner_, store_path_) 701 V4Store(task_runner_, store_path_)
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 base::RunLoop().RunUntilIdle(); 882 base::RunLoop().RunUntilIdle();
867 883
868 // This ensures that the callback was called. 884 // This ensures that the callback was called.
869 EXPECT_TRUE(called_back); 885 EXPECT_TRUE(called_back);
870 // Ensure that the file is still not created. 886 // Ensure that the file is still not created.
871 EXPECT_FALSE(base::PathExists(store.store_path_)); 887 EXPECT_FALSE(base::PathExists(store.store_path_));
872 EXPECT_FALSE(updated_store_); 888 EXPECT_FALSE(updated_store_);
873 } 889 }
874 890
875 } // namespace safe_browsing 891 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing_db/v4_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698