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

Unified Diff: blimp/common/blob_cache/id_util_unittest.cc

Issue 1912153004: [blimp] Change to use SHA-256 instead of SHA-1 for unique ids (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from Wez Created 4 years, 8 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 | « blimp/common/blob_cache/id_util.cc ('k') | blimp/common/blob_cache/in_memory_blob_cache.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/common/blob_cache/id_util_unittest.cc
diff --git a/blimp/common/blob_cache/id_util_unittest.cc b/blimp/common/blob_cache/id_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d8fa8fea27362f27a76faa3442645bebfcd56eca
--- /dev/null
+++ b/blimp/common/blob_cache/id_util_unittest.cc
@@ -0,0 +1,48 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "blimp/common/blob_cache/id_util.h"
+#include "crypto/sha2.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blimp {
+namespace {
+
+const char kBlobdata[] = "\xde\xad\xbe\xef\x4b\x1d\xc0\xd3\xff\xfe";
+
+// Caution: If these expected outputs ever change, it means that all client-side
+// caches will effectively be invalidated.
+const char kBlobId[] =
+ "\x31\xda\x00\xaf\x5e\xd6\x64\xd6\x5f\xb1\xe6\x34\x99\xd3\xf5\x12\x21\xc8"
+ "\xf8\x51\x19\xfd\x1d\x17\xaa\x0b\x5e\x85\x10\x4f\x17\x15";
+const char kBlobIdString[] =
+ "31da00af5ed664d65fb1e63499d3f51221c8f85119fd1d17aa0b5e85104f1715";
+
+TEST(IdUtilTest, BlobIdIsCorrect) {
+ BlobId id = CalculateBlobId(kBlobdata, 10);
+ EXPECT_EQ(crypto::kSHA256Length, id.length());
+ for (size_t i = 0; i < crypto::kSHA256Length; i++)
+ EXPECT_EQ(kBlobId[i], static_cast<int>(id[i]));
+ EXPECT_EQ(kBlobIdString, BlobIdToString(id));
+}
+
+TEST(IdUtilTest, BlobIdsAreCorrectLength) {
+ BlobId id1 = CalculateBlobId(kBlobdata, 10);
+ EXPECT_EQ(crypto::kSHA256Length, id1.length());
+ EXPECT_TRUE(IsValidBlobId(id1));
+
+ BlobId id2 = CalculateBlobId(kBlobdata, 8);
+ EXPECT_EQ(crypto::kSHA256Length, id2.length());
+ EXPECT_TRUE(IsValidBlobId(id2));
+}
+
+TEST(IdUtilTest, BlobIdLengthCheck) {
+ EXPECT_FALSE(IsValidBlobId(BlobId("")));
+ EXPECT_FALSE(IsValidBlobId(BlobId("123")));
+ EXPECT_TRUE(IsValidBlobId(BlobId("12345678901234567890123456789012")));
+ EXPECT_FALSE(IsValidBlobId(BlobId("12345678901234567890123456789012fff")));
+}
+
+} // namespace
+} // namespace blimp
« no previous file with comments | « blimp/common/blob_cache/id_util.cc ('k') | blimp/common/blob_cache/in_memory_blob_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698