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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "blimp/common/blob_cache/id_util.h"
6 #include "crypto/sha2.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace blimp {
10 namespace {
11 const char kInput[] = "\xde\xad\xbe\xef\x4b\x1d\xc0\xd3\xff\xfe";
Wez 2016/04/23 00:08:52 kBlobData? nit: Blank line between namespace and
nyquist 2016/04/25 08:11:17 Done.
12
13 // Caution: If these expected outputs ever change, it means that all client-side
14 // caches will effectively be invalidated.
15 const char kExpected[] =
Wez 2016/04/23 00:08:52 kBlobId and kBlobIdString, say?
nyquist 2016/04/25 08:11:17 Done.
16 "\x31\xda\x00\xaf\x5e\xd6\x64\xd6\x5f\xb1\xe6\x34\x99\xd3\xf5\x12\x21\xc8"
17 "\xf8\x51\x19\xfd\x1d\x17\xaa\x0b\x5e\x85\x10\x4f\x17\x15";
18 const char kExpectedFormatted[] =
19 "31da00af5ed664d65fb1e63499d3f51221c8f85119fd1d17aa0b5e85104f1715";
20
21 class IdUtilTest : public testing::Test {
Wez 2016/04/23 00:08:52 Why are we overriding testing::Test if we're not a
nyquist 2016/04/25 08:11:17 Done.
22 public:
23 IdUtilTest() {}
24 ~IdUtilTest() override {}
25 };
26
27 TEST_F(IdUtilTest, VerifyHashCalculationCreatesExpectedHash) {
Wez 2016/04/23 00:08:52 Suggest calling this just BlobIdIsCorrect or Corre
nyquist 2016/04/25 08:11:17 Done.
28 BlobId id = CalculateBlobId(kInput, 10);
29 EXPECT_EQ(crypto::kSHA256Length, id.length());
30 for (size_t i = 0; i < crypto::kSHA256Length; i++)
31 EXPECT_EQ(kExpected[i], static_cast<int>(id[i]));
32 EXPECT_EQ(kExpectedFormatted, FormatBlobId(id));
33 }
34
35 TEST_F(IdUtilTest, VerifyLengthChecker) {
Wez 2016/04/23 00:08:52 This looks like two different tests; one is verify
nyquist 2016/04/25 08:11:17 Done.
36 BlobId id1 = CalculateBlobId(kInput, 10);
37 EXPECT_EQ(crypto::kSHA256Length, id1.length());
38 EXPECT_TRUE(BlobIdHasCorrectLength(id1));
39
40 BlobId id2 = CalculateBlobId(kInput, 8);
41 EXPECT_EQ(crypto::kSHA256Length, id2.length());
42 EXPECT_TRUE(BlobIdHasCorrectLength(id2));
43
44 EXPECT_FALSE(BlobIdHasCorrectLength(BlobId("")));
45 EXPECT_FALSE(BlobIdHasCorrectLength(BlobId("123")));
46 EXPECT_TRUE(
47 BlobIdHasCorrectLength(BlobId("12345678901234567890123456789012")));
48 EXPECT_FALSE(
49 BlobIdHasCorrectLength(BlobId("12345678901234567890123456789012fff")));
50 }
51
52 } // namespace
53 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698