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/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 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) | 704 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
705 // This test hits a NOTREACHED so it is a release mode only test. | 705 // This test hits a NOTREACHED so it is a release mode only test. |
706 TEST_F(V4StoreTest, TestAdditionsWithRiceEncodingFailsWithInvalidInput) { | 706 TEST_F(V4StoreTest, TestAdditionsWithRiceEncodingFailsWithInvalidInput) { |
707 RepeatedPtrField<ThreatEntrySet> additions; | 707 RepeatedPtrField<ThreatEntrySet> additions; |
708 ThreatEntrySet* addition = additions.Add(); | 708 ThreatEntrySet* addition = additions.Add(); |
709 addition->set_compression_type(RICE); | 709 addition->set_compression_type(RICE); |
710 addition->mutable_rice_hashes()->set_num_entries(-1); | 710 addition->mutable_rice_hashes()->set_num_entries(-1); |
711 HashPrefixMap additions_map; | 711 HashPrefixMap additions_map; |
712 EXPECT_EQ(RICE_DECODING_FAILURE, | 712 EXPECT_EQ(RICE_DECODING_FAILURE, |
713 V4Store(task_runner_, store_path_) | 713 V4Store(task_runner_, store_path_) |
714 .UpdateHashPrefixMapFromAdditions(additions, &additions_map)); | 714 .UpdateHashPrefixMapFromAdditions("V4Metric", additions, |
| 715 &additions_map)); |
715 } | 716 } |
716 #endif | 717 #endif |
717 | 718 |
718 TEST_F(V4StoreTest, TestAdditionsWithRiceEncodingSucceeds) { | 719 TEST_F(V4StoreTest, TestAdditionsWithRiceEncodingSucceeds) { |
719 RepeatedPtrField<ThreatEntrySet> additions; | 720 RepeatedPtrField<ThreatEntrySet> additions; |
720 ThreatEntrySet* addition = additions.Add(); | 721 ThreatEntrySet* addition = additions.Add(); |
721 addition->set_compression_type(RICE); | 722 addition->set_compression_type(RICE); |
722 RiceDeltaEncoding* rice_hashes = addition->mutable_rice_hashes(); | 723 RiceDeltaEncoding* rice_hashes = addition->mutable_rice_hashes(); |
723 rice_hashes->set_first_value(5); | 724 rice_hashes->set_first_value(5); |
724 rice_hashes->set_num_entries(3); | 725 rice_hashes->set_num_entries(3); |
725 rice_hashes->set_rice_parameter(28); | 726 rice_hashes->set_rice_parameter(28); |
726 // The following value is hand-crafted by getting inspiration from: | 727 // The following value is hand-crafted by getting inspiration from: |
727 // https://goto.google.com/testlargenumbersriceencoded | 728 // https://goto.google.com/testlargenumbersriceencoded |
728 // The value listed at that place fails the "integer overflow" check so I | 729 // The value listed at that place fails the "integer overflow" check so I |
729 // modified it until the decoder parsed it successfully. | 730 // modified it until the decoder parsed it successfully. |
730 rice_hashes->set_encoded_data( | 731 rice_hashes->set_encoded_data( |
731 "\xbf\xa8\x3f\xfb\xf\xf\x5e\x27\xe6\xc3\x1d\xc6\x38"); | 732 "\xbf\xa8\x3f\xfb\xf\xf\x5e\x27\xe6\xc3\x1d\xc6\x38"); |
732 HashPrefixMap additions_map; | 733 HashPrefixMap additions_map; |
733 EXPECT_EQ(APPLY_UPDATE_SUCCESS, | 734 EXPECT_EQ(APPLY_UPDATE_SUCCESS, |
734 V4Store(task_runner_, store_path_) | 735 V4Store(task_runner_, store_path_) |
735 .UpdateHashPrefixMapFromAdditions(additions, &additions_map)); | 736 .UpdateHashPrefixMapFromAdditions("V4Metric", additions, |
| 737 &additions_map)); |
736 EXPECT_EQ(1u, additions_map.size()); | 738 EXPECT_EQ(1u, additions_map.size()); |
737 EXPECT_EQ(std::string("\x5\0\0\0\fL\x93\xADV\x7F\xF6o\xCEo1\x81", 16), | 739 EXPECT_EQ(std::string("\x5\0\0\0\fL\x93\xADV\x7F\xF6o\xCEo1\x81", 16), |
738 additions_map[4]); | 740 additions_map[4]); |
739 } | 741 } |
740 | 742 |
741 TEST_F(V4StoreTest, TestRemovalsWithRiceEncodingSucceeds) { | 743 TEST_F(V4StoreTest, TestRemovalsWithRiceEncodingSucceeds) { |
742 HashPrefixMap prefix_map_old; | 744 HashPrefixMap prefix_map_old; |
743 EXPECT_EQ(APPLY_UPDATE_SUCCESS, | 745 EXPECT_EQ(APPLY_UPDATE_SUCCESS, |
744 V4Store::AddUnlumpedHashes(4, "1111abcdefgh", &prefix_map_old)); | 746 V4Store::AddUnlumpedHashes(4, "1111abcdefgh", &prefix_map_old)); |
745 HashPrefixMap prefix_map_additions; | 747 HashPrefixMap prefix_map_additions; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
841 EXPECT_TRUE(another_store.expected_checksum_.empty()); | 843 EXPECT_TRUE(another_store.expected_checksum_.empty()); |
842 | 844 |
843 EXPECT_EQ(READ_SUCCESS, another_store.ReadFromDisk()); | 845 EXPECT_EQ(READ_SUCCESS, another_store.ReadFromDisk()); |
844 EXPECT_TRUE(!another_store.expected_checksum_.empty()); | 846 EXPECT_TRUE(!another_store.expected_checksum_.empty()); |
845 EXPECT_EQ("test_client_state", another_store.state()); | 847 EXPECT_EQ("test_client_state", another_store.state()); |
846 | 848 |
847 EXPECT_TRUE(another_store.VerifyChecksum()); | 849 EXPECT_TRUE(another_store.VerifyChecksum()); |
848 } | 850 } |
849 | 851 |
850 } // namespace safe_browsing | 852 } // namespace safe_browsing |
OLD | NEW |