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

Side by Side Diff: sync/util/cryptographer_unittest.cc

Issue 896313002: Add one test for Cryptographer::InstallKeys (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « no previous file | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium 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 "sync/util/cryptographer.h" 5 #include "sync/util/cryptographer.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 EXPECT_TRUE(cryptographer_clone.Encrypt(original, &encrypted_c)); 257 EXPECT_TRUE(cryptographer_clone.Encrypt(original, &encrypted_c));
258 258
259 sync_pb::PasswordSpecificsData decrypted_c; 259 sync_pb::PasswordSpecificsData decrypted_c;
260 EXPECT_TRUE(cryptographer_.Decrypt(encrypted_c, &decrypted_c)); 260 EXPECT_TRUE(cryptographer_.Decrypt(encrypted_c, &decrypted_c));
261 EXPECT_EQ(original.SerializeAsString(), decrypted_c.SerializeAsString()); 261 EXPECT_EQ(original.SerializeAsString(), decrypted_c.SerializeAsString());
262 262
263 // The cloned cryptographer should be using the latest key. 263 // The cloned cryptographer should be using the latest key.
264 EXPECT_EQ(encrypted_c.key_name(), encrypted_k2.key_name()); 264 EXPECT_EQ(encrypted_c.key_name(), encrypted_k2.key_name());
265 } 265 }
266 266
267 TEST_F(CryptographerTest, GetKeysThenInstall) {
pavely 2015/02/18 22:31:46 Could you add comment describing test? Test verif
268 sync_pb::PasswordSpecificsData original;
269 original.set_origin("http://example.com");
270 original.set_username_value("luser");
271 original.set_password_value("p4ssw0rd");
272
273 // First, encrypt the same value using two different keys.
274 KeyParams params1 = {"localhost", "dummy", "dummy"};
275 EXPECT_TRUE(cryptographer_.AddKey(params1));
276 EXPECT_TRUE(cryptographer_.is_ready());
277
278 sync_pb::EncryptedData encrypted_k1;
279 EXPECT_TRUE(cryptographer_.Encrypt(original, &encrypted_k1));
280
281 KeyParams params2 = {"localhost", "dummy2", "dummy2"};
282 EXPECT_TRUE(cryptographer_.AddKey(params2));
283 EXPECT_TRUE(cryptographer_.is_ready());
284
285 sync_pb::EncryptedData encrypted_k2;
286 EXPECT_TRUE(cryptographer_.Encrypt(original, &encrypted_k2));
287
288 // Then construct second cryptographer and bootstrap it from the first one.
289 Cryptographer another_cryptographer(cryptographer_.encryptor());
290 std::string bootstrap_token;
291 EXPECT_TRUE(cryptographer_.GetBootstrapToken(&bootstrap_token));
292 another_cryptographer.Bootstrap(bootstrap_token);
293
294 // Before key installation, the second cryptographer should only be able
295 // to decrypt using the last key.
296 EXPECT_FALSE(another_cryptographer.CanDecrypt(encrypted_k1));
297 EXPECT_TRUE(another_cryptographer.CanDecrypt(encrypted_k2));
298
299 sync_pb::EncryptedData keys;
300 EXPECT_TRUE(cryptographer_.GetKeys(&keys));
301 ASSERT_TRUE(another_cryptographer.CanDecrypt(keys));
302 another_cryptographer.InstallKeys(keys);
303
304 // Verify that bootstrapped cryptographer decrypts succesfully using
305 // all the keys after key installation.
306 EXPECT_TRUE(another_cryptographer.CanDecrypt(encrypted_k1));
307 EXPECT_TRUE(another_cryptographer.CanDecrypt(encrypted_k2));
308 }
309
267 } // namespace syncer 310 } // namespace syncer
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698