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

Unified Diff: components/safe_browsing_db/v4_store_unittest.cc

Issue 2384893002: PVer4: Test checksum on startup outside the hotpath of DB load (Closed)
Patch Set: Verify that the checksum check happens async Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/safe_browsing_db/v4_store.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/safe_browsing_db/v4_store_unittest.cc
diff --git a/components/safe_browsing_db/v4_store_unittest.cc b/components/safe_browsing_db/v4_store_unittest.cc
index 90c6525fa88ca316d0051a6fabf0e73147e51e6f..28191dad4c78179bb345c843134ec17d18fa9e55 100644
--- a/components/safe_browsing_db/v4_store_unittest.cc
+++ b/components/safe_browsing_db/v4_store_unittest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/base64.h"
#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
@@ -800,4 +801,50 @@ TEST_F(V4StoreTest, TestMergeUpdatesFailsChecksum) {
.MergeUpdate(prefix_map_old, HashPrefixMap(), nullptr, "aawc"));
}
+TEST_F(V4StoreTest, TestChecksumErrorOnStartup) {
+ // First the case of checksum not matching after reading from disk.
+ ListUpdateResponse list_update_response;
+ list_update_response.set_new_client_state("test_client_state");
+ list_update_response.set_platform_type(LINUX_PLATFORM);
+ list_update_response.set_response_type(ListUpdateResponse::FULL_UPDATE);
+ list_update_response.mutable_checksum()->set_sha256(
+ std::string(crypto::kSHA256Length, 0));
+ WriteFileFormatProtoToFile(0x600D71FE, 9, &list_update_response);
+ V4Store store(task_runner_, store_path_);
+ EXPECT_TRUE(store.expected_checksum_.empty());
+
+ EXPECT_EQ(READ_SUCCESS, store.ReadFromDisk());
+ EXPECT_TRUE(!store.expected_checksum_.empty());
+ EXPECT_EQ("test_client_state", store.state());
+
+ EXPECT_FALSE(store.VerifyChecksum());
+
+ // Now the case of checksum matching after reading from disk.
+ // Proof of checksum mismatch using python:
+ // >>> import hashlib
+ // >>> m = hashlib.sha256()
+ // >>> m.update("abcde")
+ // >>> import base64
+ // >>> encoded = base64.b64encode(m.digest())
+ // >>> encoded
+ // 'NrvlDtloQdEEQ7y2cNZVTwo0t2G+Z+ycSorSwMRMpCw='
+ std::string expected_checksum;
+ base::Base64Decode("NrvlDtloQdEEQ7y2cNZVTwo0t2G+Z+ycSorSwMRMpCw=",
+ &expected_checksum);
+ ThreatEntrySet* additions = list_update_response.add_additions();
+ additions->set_compression_type(RAW);
+ additions->mutable_raw_hashes()->set_prefix_size(5);
+ additions->mutable_raw_hashes()->set_raw_hashes("abcde");
+ list_update_response.mutable_checksum()->set_sha256(expected_checksum);
+ WriteFileFormatProtoToFile(0x600D71FE, 9, &list_update_response);
+ V4Store another_store(task_runner_, store_path_);
+ EXPECT_TRUE(another_store.expected_checksum_.empty());
+
+ EXPECT_EQ(READ_SUCCESS, another_store.ReadFromDisk());
+ EXPECT_TRUE(!another_store.expected_checksum_.empty());
+ EXPECT_EQ("test_client_state", another_store.state());
+
+ EXPECT_TRUE(another_store.VerifyChecksum());
+}
+
} // namespace safe_browsing
« 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