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

Side by Side 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: Address comments 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/sync/util/cryptographer.h" 5 #include "chrome/browser/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/string_util.h" 10 #include "base/string_util.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 sync_pb::EncryptedData encrypted; 79 sync_pb::EncryptedData encrypted;
80 EXPECT_TRUE(cryptographer.Encrypt(original, &encrypted)); 80 EXPECT_TRUE(cryptographer.Encrypt(original, &encrypted));
81 81
82 sync_pb::PasswordSpecificsData decrypted; 82 sync_pb::PasswordSpecificsData decrypted;
83 EXPECT_TRUE(cryptographer.Decrypt(encrypted, &decrypted)); 83 EXPECT_TRUE(cryptographer.Decrypt(encrypted, &decrypted));
84 84
85 EXPECT_EQ(original.SerializeAsString(), decrypted.SerializeAsString()); 85 EXPECT_EQ(original.SerializeAsString(), decrypted.SerializeAsString());
86 } 86 }
87 87
88 TEST(CryptographerTest, EncryptOnlyIfDifferent) {
89 Cryptographer cryptographer;
90
91 KeyParams params = {"localhost", "dummy", "dummy"};
92 EXPECT_TRUE(cryptographer.AddKey(params));
93 EXPECT_TRUE(cryptographer.is_ready());
94
95 sync_pb::PasswordSpecificsData original;
96 original.set_origin("http://example.com");
97 original.set_username_value("azure");
98 original.set_password_value("hunter2");
99
100 sync_pb::EncryptedData encrypted;
101 EXPECT_TRUE(cryptographer.Encrypt(original, &encrypted));
102
103 sync_pb::EncryptedData encrypted2, encrypted3;
104 encrypted2.CopyFrom(encrypted);
105 encrypted3.CopyFrom(encrypted);
106 EXPECT_TRUE(cryptographer.Encrypt(original, &encrypted2));
107
108 // Now encrypt with a new default key. Should overwrite the old data.
109 KeyParams params_new = {"localhost", "dummy", "dummy2"};
110 cryptographer.AddKey(params_new);
111 EXPECT_TRUE(cryptographer.Encrypt(original, &encrypted3));
112
113 sync_pb::PasswordSpecificsData decrypted;
114 EXPECT_TRUE(cryptographer.Decrypt(encrypted2, &decrypted));
115 // encrypted2 should match encrypted, encrypted3 should not (due to salting).
116 EXPECT_EQ(encrypted.SerializeAsString(), encrypted2.SerializeAsString());
117 EXPECT_NE(encrypted.SerializeAsString(), encrypted3.SerializeAsString());
118 EXPECT_EQ(original.SerializeAsString(), decrypted.SerializeAsString());
119 }
120
88 TEST(CryptographerTest, AddKeySetsDefault) { 121 TEST(CryptographerTest, AddKeySetsDefault) {
89 Cryptographer cryptographer; 122 Cryptographer cryptographer;
90 123
91 KeyParams params1 = {"localhost", "dummy", "dummy1"}; 124 KeyParams params1 = {"localhost", "dummy", "dummy1"};
92 EXPECT_TRUE(cryptographer.AddKey(params1)); 125 EXPECT_TRUE(cryptographer.AddKey(params1));
93 EXPECT_TRUE(cryptographer.is_ready()); 126 EXPECT_TRUE(cryptographer.is_ready());
94 127
95 sync_pb::PasswordSpecificsData original; 128 sync_pb::PasswordSpecificsData original;
96 original.set_origin("http://example.com"); 129 original.set_origin("http://example.com");
97 original.set_username_value("azure"); 130 original.set_username_value("azure");
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 *iter == syncable::BOOKMARKS) 395 *iter == syncable::BOOKMARKS)
363 EXPECT_EQ(1U, encrypted_types.count(*iter)); 396 EXPECT_EQ(1U, encrypted_types.count(*iter));
364 else 397 else
365 EXPECT_EQ(0U, encrypted_types.count(*iter)); 398 EXPECT_EQ(0U, encrypted_types.count(*iter));
366 } 399 }
367 400
368 cryptographer.RemoveObserver(&observer); 401 cryptographer.RemoveObserver(&observer);
369 } 402 }
370 403
371 } // namespace browser_sync 404 } // namespace browser_sync
OLDNEW
« chrome/browser/sync/util/cryptographer.cc ('K') | « chrome/browser/sync/util/cryptographer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698