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

Side by Side Diff: delta_performer_unittest.cc

Issue 6265001: AU: Add support for signing of update payloads after they're generated. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git@master
Patch Set: rename function Created 9 years, 11 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 | « delta_performer.cc ('k') | payload_signer.h » ('j') | 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 <sys/mount.h> 5 #include <sys/mount.h>
6 #include <inttypes.h> 6 #include <inttypes.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 bool WriteSparseFile(const string& path, off_t size) { 85 bool WriteSparseFile(const string& path, off_t size) {
86 int fd = open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0644); 86 int fd = open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0644);
87 TEST_AND_RETURN_FALSE_ERRNO(fd >= 0); 87 TEST_AND_RETURN_FALSE_ERRNO(fd >= 0);
88 ScopedFdCloser fd_closer(&fd); 88 ScopedFdCloser fd_closer(&fd);
89 off_t rc = lseek(fd, size + 1, SEEK_SET); 89 off_t rc = lseek(fd, size + 1, SEEK_SET);
90 TEST_AND_RETURN_FALSE_ERRNO(rc != static_cast<off_t>(-1)); 90 TEST_AND_RETURN_FALSE_ERRNO(rc != static_cast<off_t>(-1));
91 int return_code = ftruncate(fd, size); 91 int return_code = ftruncate(fd, size);
92 TEST_AND_RETURN_FALSE_ERRNO(return_code == 0); 92 TEST_AND_RETURN_FALSE_ERRNO(return_code == 0);
93 return true; 93 return true;
94 } 94 }
95 } // namespace {}
95 96
96 void DoSmallImageTest(bool full_kernel, bool full_rootfs, bool noop) { 97 namespace {
98 void DoSmallImageTest(bool full_kernel, bool full_rootfs, bool noop,
99 bool post_sign) {
97 string a_img, b_img; 100 string a_img, b_img;
98 EXPECT_TRUE(utils::MakeTempFile("/tmp/a_img.XXXXXX", &a_img, NULL)); 101 EXPECT_TRUE(utils::MakeTempFile("/tmp/a_img.XXXXXX", &a_img, NULL));
99 ScopedPathUnlinker a_img_unlinker(a_img); 102 ScopedPathUnlinker a_img_unlinker(a_img);
100 EXPECT_TRUE(utils::MakeTempFile("/tmp/b_img.XXXXXX", &b_img, NULL)); 103 EXPECT_TRUE(utils::MakeTempFile("/tmp/b_img.XXXXXX", &b_img, NULL));
101 ScopedPathUnlinker b_img_unlinker(b_img); 104 ScopedPathUnlinker b_img_unlinker(b_img);
102 105
103 CreateExtImageAtPath(a_img, NULL); 106 CreateExtImageAtPath(a_img, NULL);
104 107
105 int image_size = static_cast<int>(utils::FileSize(a_img)); 108 int image_size = static_cast<int>(utils::FileSize(a_img));
106 109
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 204
202 EXPECT_TRUE( 205 EXPECT_TRUE(
203 DeltaDiffGenerator::GenerateDeltaUpdateFile( 206 DeltaDiffGenerator::GenerateDeltaUpdateFile(
204 full_rootfs ? "" : a_mnt, 207 full_rootfs ? "" : a_mnt,
205 full_rootfs ? "" : a_img, 208 full_rootfs ? "" : a_img,
206 b_mnt, 209 b_mnt,
207 b_img, 210 b_img,
208 full_kernel ? "" : old_kernel, 211 full_kernel ? "" : old_kernel,
209 new_kernel, 212 new_kernel,
210 delta_path, 213 delta_path,
211 kUnittestPrivateKeyPath)); 214 post_sign ? "" : kUnittestPrivateKeyPath));
215 }
216
217 if (post_sign) {
218 int signature_size;
219 {
220 const vector<char> data(1, 'x');
221 vector<char> hash;
222 ASSERT_TRUE(OmahaHashCalculator::RawHashOfData(data, &hash));
223 vector<char> signature;
224 ASSERT_TRUE(PayloadSigner::SignHash(hash,
225 kUnittestPrivateKeyPath,
226 &signature));
227 signature_size = signature.size();
228 }
229
230 vector<char> hash;
231 ASSERT_TRUE(PayloadSigner::HashPayloadForSigning(delta_path,
232 signature_size,
233 &hash));
234 vector<char> signature;
235 ASSERT_TRUE(PayloadSigner::SignHash(hash,
236 kUnittestPrivateKeyPath,
237 &signature));
238 ASSERT_TRUE(PayloadSigner::AddSignatureToPayload(delta_path,
239 signature,
240 delta_path));
212 } 241 }
213 242
214 // Read delta into memory. 243 // Read delta into memory.
215 vector<char> delta; 244 vector<char> delta;
216 EXPECT_TRUE(utils::ReadFile(delta_path, &delta)); 245 EXPECT_TRUE(utils::ReadFile(delta_path, &delta));
217 246
218 uint64_t manifest_metadata_size; 247 uint64_t manifest_metadata_size;
219 248
220 // Check the metadata. 249 // Check the metadata.
221 { 250 {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 vector<char> expected_new_rootfs_hash; 373 vector<char> expected_new_rootfs_hash;
345 EXPECT_EQ(image_size, 374 EXPECT_EQ(image_size,
346 OmahaHashCalculator::RawHashOfFile(b_img, 375 OmahaHashCalculator::RawHashOfFile(b_img,
347 image_size, 376 image_size,
348 &expected_new_rootfs_hash)); 377 &expected_new_rootfs_hash));
349 EXPECT_TRUE(expected_new_rootfs_hash == new_rootfs_hash); 378 EXPECT_TRUE(expected_new_rootfs_hash == new_rootfs_hash);
350 } 379 }
351 } 380 }
352 381
353 TEST(DeltaPerformerTest, RunAsRootSmallImageTest) { 382 TEST(DeltaPerformerTest, RunAsRootSmallImageTest) {
354 DoSmallImageTest(false, false, false); 383 DoSmallImageTest(false, false, false, false);
355 } 384 }
356 385
357 TEST(DeltaPerformerTest, RunAsRootFullKernelSmallImageTest) { 386 TEST(DeltaPerformerTest, RunAsRootFullKernelSmallImageTest) {
358 DoSmallImageTest(true, false, false); 387 DoSmallImageTest(true, false, false, false);
359 } 388 }
360 389
361 TEST(DeltaPerformerTest, RunAsRootFullSmallImageTest) { 390 TEST(DeltaPerformerTest, RunAsRootFullSmallImageTest) {
362 DoSmallImageTest(true, true, false); 391 DoSmallImageTest(true, true, false, false);
363 } 392 }
364 393
365 TEST(DeltaPerformerTest, RunAsRootNoopSmallImageTest) { 394 TEST(DeltaPerformerTest, RunAsRootNoopSmallImageTest) {
366 DoSmallImageTest(false, false, true); 395 DoSmallImageTest(false, false, true, false);
396 }
397
398 TEST(DeltaPerformerTest, RunAsRootSmallImagePostSignTest) {
399 DoSmallImageTest(false, false, false, true);
367 } 400 }
368 401
369 TEST(DeltaPerformerTest, BadDeltaMagicTest) { 402 TEST(DeltaPerformerTest, BadDeltaMagicTest) {
370 PrefsMock prefs; 403 PrefsMock prefs;
371 DeltaPerformer performer(&prefs); 404 DeltaPerformer performer(&prefs);
372 EXPECT_EQ(0, performer.Open("/dev/null", 0, 0)); 405 EXPECT_EQ(0, performer.Open("/dev/null", 0, 0));
373 EXPECT_TRUE(performer.OpenKernel("/dev/null")); 406 EXPECT_TRUE(performer.OpenKernel("/dev/null"));
374 EXPECT_EQ(4, performer.Write("junk", 4)); 407 EXPECT_EQ(4, performer.Write("junk", 4));
375 EXPECT_EQ(8, performer.Write("morejunk", 8)); 408 EXPECT_EQ(8, performer.Write("morejunk", 8));
376 EXPECT_LT(performer.Write("morejunk", 8), 0); 409 EXPECT_LT(performer.Write("morejunk", 8), 0);
(...skipping 10 matching lines...) Expand all
387 op.clear_src_extents(); 420 op.clear_src_extents();
388 *(op.add_src_extents()) = ExtentForRange(5, 3); 421 *(op.add_src_extents()) = ExtentForRange(5, 3);
389 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op)); 422 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op));
390 *(op.add_dst_extents()) = ExtentForRange(20, 6); 423 *(op.add_dst_extents()) = ExtentForRange(20, 6);
391 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op)); 424 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op));
392 *(op.add_src_extents()) = ExtentForRange(19, 2); 425 *(op.add_src_extents()) = ExtentForRange(19, 2);
393 EXPECT_FALSE(DeltaPerformer::IsIdempotentOperation(op)); 426 EXPECT_FALSE(DeltaPerformer::IsIdempotentOperation(op));
394 } 427 }
395 428
396 } // namespace chromeos_update_engine 429 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « delta_performer.cc ('k') | payload_signer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698