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

Side by Side Diff: omaha_hash_calculator_unittest.cc

Issue 3712003: AU: Verify source rootfs/kernel hashes before applying delta. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: verify source partitions only for new updates Created 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « omaha_hash_calculator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium OS 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 <math.h> 5 #include <math.h>
6 #include <unistd.h> 6 #include <unistd.h>
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 108 }
109 109
110 OmahaHashCalculator calc; 110 OmahaHashCalculator calc;
111 EXPECT_EQ(0, calc.UpdateFile(data_path, 0)); 111 EXPECT_EQ(0, calc.UpdateFile(data_path, 0));
112 EXPECT_EQ(1, calc.UpdateFile(data_path, 1)); 112 EXPECT_EQ(1, calc.UpdateFile(data_path, 1));
113 EXPECT_TRUE(calc.Finalize()); 113 EXPECT_TRUE(calc.Finalize());
114 // echo -n h | openssl dgst -sha256 -binary | openssl base64 114 // echo -n h | openssl dgst -sha256 -binary | openssl base64
115 EXPECT_EQ("qqlAJmTxpB9A67xSyZk+tmrrNmYClY/fqig7ceZNsSM=", calc.hash()); 115 EXPECT_EQ("qqlAJmTxpB9A67xSyZk+tmrrNmYClY/fqig7ceZNsSM=", calc.hash());
116 } 116 }
117 117
118 TEST(OmahaHashCalculatorTest, RawHashOfFileSimpleTest) {
119 string data_path;
120 ASSERT_TRUE(
121 utils::MakeTempFile("/tmp/data.XXXXXX", &data_path, NULL));
122 ScopedPathUnlinker data_path_unlinker(data_path);
123 ASSERT_TRUE(utils::WriteFile(data_path.c_str(), "hi", 2));
124
125 static const int kLengths[] = { -1, 2, 10 };
126 for (size_t i = 0; i < arraysize(kLengths); i++) {
127 vector<char> exp_raw_hash(kExpectedRawHash,
128 kExpectedRawHash + arraysize(kExpectedRawHash));
129 vector<char> raw_hash;
130 EXPECT_EQ(2, OmahaHashCalculator::RawHashOfFile(data_path,
131 kLengths[i],
132 &raw_hash));
133 EXPECT_TRUE(exp_raw_hash == raw_hash);
134 }
135 }
136
118 TEST(OmahaHashCalculatorTest, UpdateFileNonexistentTest) { 137 TEST(OmahaHashCalculatorTest, UpdateFileNonexistentTest) {
119 OmahaHashCalculator calc; 138 OmahaHashCalculator calc;
120 EXPECT_EQ(-1, calc.UpdateFile("/some/non-existent/file", -1)); 139 EXPECT_EQ(-1, calc.UpdateFile("/some/non-existent/file", -1));
121 } 140 }
122 141
123 TEST(OmahaHashCalculatorTest, AbortTest) { 142 TEST(OmahaHashCalculatorTest, AbortTest) {
124 // Just make sure we don't crash and valgrind doesn't detect memory leaks 143 // Just make sure we don't crash and valgrind doesn't detect memory leaks
125 { 144 {
126 OmahaHashCalculator calc; 145 OmahaHashCalculator calc;
127 } 146 }
128 { 147 {
129 OmahaHashCalculator calc; 148 OmahaHashCalculator calc;
130 calc.Update("h", 1); 149 calc.Update("h", 1);
131 } 150 }
132 } 151 }
133 152
134 } // namespace chromeos_update_engine 153 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « omaha_hash_calculator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698