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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/files/file_util.h" | 6 #include "base/files/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 } | 701 } |
702 | 702 |
703 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 703 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
704 // This test hits a NOTREACHED so it is a release mode only test. | 704 // This test hits a NOTREACHED so it is a release mode only test. |
705 TEST_F(V4StoreTest, TestAdditionsWithRiceEncodingFailsWithInvalidInput) { | 705 TEST_F(V4StoreTest, TestAdditionsWithRiceEncodingFailsWithInvalidInput) { |
706 RepeatedPtrField<ThreatEntrySet> additions; | 706 RepeatedPtrField<ThreatEntrySet> additions; |
707 ThreatEntrySet* addition = additions.Add(); | 707 ThreatEntrySet* addition = additions.Add(); |
708 addition->set_compression_type(RICE); | 708 addition->set_compression_type(RICE); |
709 addition->mutable_rice_hashes()->set_num_entries(-1); | 709 addition->mutable_rice_hashes()->set_num_entries(-1); |
710 HashPrefixMap additions_map; | 710 HashPrefixMap additions_map; |
711 EXPECT_EQ(RICE_DECODING_FAILURE, V4Store::UpdateHashPrefixMapFromAdditions( | 711 EXPECT_EQ(RICE_DECODING_FAILURE, |
712 additions, &additions_map)); | 712 V4Store(task_runner_, store_path_) |
| 713 .UpdateHashPrefixMapFromAdditions(additions, &additions_map)); |
713 } | 714 } |
714 #endif | 715 #endif |
715 | 716 |
716 TEST_F(V4StoreTest, TestAdditionsWithRiceEncodingSucceeds) { | 717 TEST_F(V4StoreTest, TestAdditionsWithRiceEncodingSucceeds) { |
717 RepeatedPtrField<ThreatEntrySet> additions; | 718 RepeatedPtrField<ThreatEntrySet> additions; |
718 ThreatEntrySet* addition = additions.Add(); | 719 ThreatEntrySet* addition = additions.Add(); |
719 addition->set_compression_type(RICE); | 720 addition->set_compression_type(RICE); |
720 RiceDeltaEncoding* rice_hashes = addition->mutable_rice_hashes(); | 721 RiceDeltaEncoding* rice_hashes = addition->mutable_rice_hashes(); |
721 rice_hashes->set_first_value(5); | 722 rice_hashes->set_first_value(5); |
722 rice_hashes->set_num_entries(3); | 723 rice_hashes->set_num_entries(3); |
723 rice_hashes->set_rice_parameter(28); | 724 rice_hashes->set_rice_parameter(28); |
724 // The following value is hand-crafted by getting inspiration from: | 725 // The following value is hand-crafted by getting inspiration from: |
725 // https://goto.google.com/testlargenumbersriceencoded | 726 // https://goto.google.com/testlargenumbersriceencoded |
726 // The value listed at that place fails the "integer overflow" check so I | 727 // The value listed at that place fails the "integer overflow" check so I |
727 // modified it until the decoder parsed it successfully. | 728 // modified it until the decoder parsed it successfully. |
728 rice_hashes->set_encoded_data( | 729 rice_hashes->set_encoded_data( |
729 "\xbf\xa8\x3f\xfb\xf\xf\x5e\x27\xe6\xc3\x1d\xc6\x38"); | 730 "\xbf\xa8\x3f\xfb\xf\xf\x5e\x27\xe6\xc3\x1d\xc6\x38"); |
730 HashPrefixMap additions_map; | 731 HashPrefixMap additions_map; |
731 EXPECT_EQ(APPLY_UPDATE_SUCCESS, V4Store::UpdateHashPrefixMapFromAdditions( | 732 EXPECT_EQ(APPLY_UPDATE_SUCCESS, |
732 additions, &additions_map)); | 733 V4Store(task_runner_, store_path_) |
| 734 .UpdateHashPrefixMapFromAdditions(additions, &additions_map)); |
733 EXPECT_EQ(1u, additions_map.size()); | 735 EXPECT_EQ(1u, additions_map.size()); |
734 EXPECT_EQ(std::string("\x5\0\0\0\fL\x93\xADV\x7F\xF6o\xCEo1\x81", 16), | 736 EXPECT_EQ(std::string("\x5\0\0\0\fL\x93\xADV\x7F\xF6o\xCEo1\x81", 16), |
735 additions_map[4]); | 737 additions_map[4]); |
736 } | 738 } |
737 | 739 |
738 TEST_F(V4StoreTest, TestRemovalsWithRiceEncodingSucceeds) { | 740 TEST_F(V4StoreTest, TestRemovalsWithRiceEncodingSucceeds) { |
739 HashPrefixMap prefix_map_old; | 741 HashPrefixMap prefix_map_old; |
740 EXPECT_EQ(APPLY_UPDATE_SUCCESS, | 742 EXPECT_EQ(APPLY_UPDATE_SUCCESS, |
741 V4Store::AddUnlumpedHashes(4, "1111abcdefgh", &prefix_map_old)); | 743 V4Store::AddUnlumpedHashes(4, "1111abcdefgh", &prefix_map_old)); |
742 HashPrefixMap prefix_map_additions; | 744 HashPrefixMap prefix_map_additions; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 | 794 |
793 HashPrefixMap prefix_map_old; | 795 HashPrefixMap prefix_map_old; |
794 EXPECT_EQ(APPLY_UPDATE_SUCCESS, | 796 EXPECT_EQ(APPLY_UPDATE_SUCCESS, |
795 V4Store::AddUnlumpedHashes(4, "2222", &prefix_map_old)); | 797 V4Store::AddUnlumpedHashes(4, "2222", &prefix_map_old)); |
796 EXPECT_EQ(CHECKSUM_MISMATCH_FAILURE, | 798 EXPECT_EQ(CHECKSUM_MISMATCH_FAILURE, |
797 V4Store(task_runner_, store_path_) | 799 V4Store(task_runner_, store_path_) |
798 .MergeUpdate(prefix_map_old, HashPrefixMap(), nullptr, "aawc")); | 800 .MergeUpdate(prefix_map_old, HashPrefixMap(), nullptr, "aawc")); |
799 } | 801 } |
800 | 802 |
801 } // namespace safe_browsing | 803 } // namespace safe_browsing |
OLD | NEW |