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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/util/cryptographer_unittest.cc
diff --git a/sync/util/cryptographer_unittest.cc b/sync/util/cryptographer_unittest.cc
index 94a20c8bc735ea226129a1e3740c5742751a1e93..93950c6acb507da39801232e5cdcdbf4f87c1a9f 100644
--- a/sync/util/cryptographer_unittest.cc
+++ b/sync/util/cryptographer_unittest.cc
@@ -264,4 +264,47 @@ TEST_F(CryptographerTest, CopyConstructor) {
EXPECT_EQ(encrypted_c.key_name(), encrypted_k2.key_name());
}
+TEST_F(CryptographerTest, GetKeysThenInstall) {
pavely 2015/02/18 22:31:46 Could you add comment describing test? Test verif
+ sync_pb::PasswordSpecificsData original;
+ original.set_origin("http://example.com");
+ original.set_username_value("luser");
+ original.set_password_value("p4ssw0rd");
+
+ // First, encrypt the same value using two different keys.
+ KeyParams params1 = {"localhost", "dummy", "dummy"};
+ EXPECT_TRUE(cryptographer_.AddKey(params1));
+ EXPECT_TRUE(cryptographer_.is_ready());
+
+ sync_pb::EncryptedData encrypted_k1;
+ EXPECT_TRUE(cryptographer_.Encrypt(original, &encrypted_k1));
+
+ KeyParams params2 = {"localhost", "dummy2", "dummy2"};
+ EXPECT_TRUE(cryptographer_.AddKey(params2));
+ EXPECT_TRUE(cryptographer_.is_ready());
+
+ sync_pb::EncryptedData encrypted_k2;
+ EXPECT_TRUE(cryptographer_.Encrypt(original, &encrypted_k2));
+
+ // Then construct second cryptographer and bootstrap it from the first one.
+ Cryptographer another_cryptographer(cryptographer_.encryptor());
+ std::string bootstrap_token;
+ EXPECT_TRUE(cryptographer_.GetBootstrapToken(&bootstrap_token));
+ another_cryptographer.Bootstrap(bootstrap_token);
+
+ // Before key installation, the second cryptographer should only be able
+ // to decrypt using the last key.
+ EXPECT_FALSE(another_cryptographer.CanDecrypt(encrypted_k1));
+ EXPECT_TRUE(another_cryptographer.CanDecrypt(encrypted_k2));
+
+ sync_pb::EncryptedData keys;
+ EXPECT_TRUE(cryptographer_.GetKeys(&keys));
+ ASSERT_TRUE(another_cryptographer.CanDecrypt(keys));
+ another_cryptographer.InstallKeys(keys);
+
+ // Verify that bootstrapped cryptographer decrypts succesfully using
+ // all the keys after key installation.
+ EXPECT_TRUE(another_cryptographer.CanDecrypt(encrypted_k1));
+ EXPECT_TRUE(another_cryptographer.CanDecrypt(encrypted_k2));
+}
+
} // namespace syncer
« 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