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

Unified Diff: chrome/browser/sync/util/cryptographer_unittest.cc

Issue 8759019: [Sync] Add intelligent re-encryption support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase again Created 9 years 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 | « chrome/browser/sync/util/cryptographer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/util/cryptographer_unittest.cc
diff --git a/chrome/browser/sync/util/cryptographer_unittest.cc b/chrome/browser/sync/util/cryptographer_unittest.cc
index e9110d0c2faf01030c513ffc48c21a30069f46b9..2f66fb96055d7e25e013d936d8d654e26f619304 100644
--- a/chrome/browser/sync/util/cryptographer_unittest.cc
+++ b/chrome/browser/sync/util/cryptographer_unittest.cc
@@ -87,6 +87,39 @@ TEST(CryptographerTest, CanEncryptAndDecrypt) {
EXPECT_EQ(original.SerializeAsString(), decrypted.SerializeAsString());
}
+TEST(CryptographerTest, EncryptOnlyIfDifferent) {
+ Cryptographer cryptographer;
+
+ KeyParams params = {"localhost", "dummy", "dummy"};
+ EXPECT_TRUE(cryptographer.AddKey(params));
+ EXPECT_TRUE(cryptographer.is_ready());
+
+ sync_pb::PasswordSpecificsData original;
+ original.set_origin("http://example.com");
+ original.set_username_value("azure");
+ original.set_password_value("hunter2");
+
+ sync_pb::EncryptedData encrypted;
+ EXPECT_TRUE(cryptographer.Encrypt(original, &encrypted));
+
+ sync_pb::EncryptedData encrypted2, encrypted3;
+ encrypted2.CopyFrom(encrypted);
+ encrypted3.CopyFrom(encrypted);
+ EXPECT_TRUE(cryptographer.Encrypt(original, &encrypted2));
+
+ // Now encrypt with a new default key. Should overwrite the old data.
+ KeyParams params_new = {"localhost", "dummy", "dummy2"};
+ cryptographer.AddKey(params_new);
+ EXPECT_TRUE(cryptographer.Encrypt(original, &encrypted3));
+
+ sync_pb::PasswordSpecificsData decrypted;
+ EXPECT_TRUE(cryptographer.Decrypt(encrypted2, &decrypted));
+ // encrypted2 should match encrypted, encrypted3 should not (due to salting).
+ EXPECT_EQ(encrypted.SerializeAsString(), encrypted2.SerializeAsString());
+ EXPECT_NE(encrypted.SerializeAsString(), encrypted3.SerializeAsString());
+ EXPECT_EQ(original.SerializeAsString(), decrypted.SerializeAsString());
+}
+
TEST(CryptographerTest, AddKeySetsDefault) {
Cryptographer cryptographer;
« no previous file with comments | « chrome/browser/sync/util/cryptographer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698