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

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

Issue 10878015: [Sync] Move keystore key handling to SyncEncryptionHandlerImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + fix cryptographer Created 8 years, 3 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
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/string_util.h" 10 #include "base/string_util.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 sync_pb::EncryptedData encrypted3; 131 sync_pb::EncryptedData encrypted3;
132 EXPECT_TRUE(cryptographer_.Encrypt(original, &encrypted3)); 132 EXPECT_TRUE(cryptographer_.Encrypt(original, &encrypted3));
133 sync_pb::EncryptedData encrypted4; 133 sync_pb::EncryptedData encrypted4;
134 EXPECT_TRUE(cryptographer_.Encrypt(original, &encrypted4)); 134 EXPECT_TRUE(cryptographer_.Encrypt(original, &encrypted4));
135 135
136 EXPECT_EQ(encrypted1.key_name(), encrypted2.key_name()); 136 EXPECT_EQ(encrypted1.key_name(), encrypted2.key_name());
137 EXPECT_NE(encrypted1.key_name(), encrypted3.key_name()); 137 EXPECT_NE(encrypted1.key_name(), encrypted3.key_name());
138 EXPECT_EQ(encrypted3.key_name(), encrypted4.key_name()); 138 EXPECT_EQ(encrypted3.key_name(), encrypted4.key_name());
139 } 139 }
140 140
141 // Ensure setting the keystore key works and doesn't modify the default nigori.
142 TEST_F(SyncCryptographerTest, SetKeystore) {
143 EXPECT_FALSE(cryptographer_.is_initialized());
144 EXPECT_FALSE(cryptographer_.HasKeystoreKey());
145
146 EXPECT_FALSE(cryptographer_.SetKeystoreKey(""));
147 EXPECT_FALSE(cryptographer_.HasKeystoreKey());
148
149 EXPECT_TRUE(cryptographer_.SetKeystoreKey("keystore_key"));
150 EXPECT_TRUE(cryptographer_.HasKeystoreKey());
151 EXPECT_FALSE(cryptographer_.is_initialized());
152 }
153
154 // Crashes, Bug 55178. 141 // Crashes, Bug 55178.
155 #if defined(OS_WIN) 142 #if defined(OS_WIN)
156 #define MAYBE_EncryptExportDecrypt DISABLED_EncryptExportDecrypt 143 #define MAYBE_EncryptExportDecrypt DISABLED_EncryptExportDecrypt
157 #else 144 #else
158 #define MAYBE_EncryptExportDecrypt EncryptExportDecrypt 145 #define MAYBE_EncryptExportDecrypt EncryptExportDecrypt
159 #endif 146 #endif
160 TEST_F(SyncCryptographerTest, MAYBE_EncryptExportDecrypt) { 147 TEST_F(SyncCryptographerTest, MAYBE_EncryptExportDecrypt) {
161 sync_pb::EncryptedData nigori; 148 sync_pb::EncryptedData nigori;
162 sync_pb::EncryptedData encrypted; 149 sync_pb::EncryptedData encrypted;
163 150
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 EXPECT_NE(static_cast<Nigori*>(NULL), unpacked.get()); 204 EXPECT_NE(static_cast<Nigori*>(NULL), unpacked.get());
218 205
219 std::string user_key, encryption_key, mac_key; 206 std::string user_key, encryption_key, mac_key;
220 ASSERT_TRUE(unpacked->ExportKeys(&user_key, &encryption_key, &mac_key)); 207 ASSERT_TRUE(unpacked->ExportKeys(&user_key, &encryption_key, &mac_key));
221 208
222 EXPECT_EQ(expected_user, user_key); 209 EXPECT_EQ(expected_user, user_key);
223 EXPECT_EQ(expected_encryption, encryption_key); 210 EXPECT_EQ(expected_encryption, encryption_key);
224 EXPECT_EQ(expected_mac, mac_key); 211 EXPECT_EQ(expected_mac, mac_key);
225 } 212 }
226 213
227 // Test that bootstrapping the keystore key works and doesn't affect the default
228 // nigori.
229 TEST_F(SyncCryptographerTest, BootstrapKeystore) {
230 std::string token;
231 cryptographer_.GetKeystoreKeyBootstrapToken(&token);
232 EXPECT_TRUE(token.empty());
233
234 cryptographer_.SetKeystoreKey("keystore_key");
235 cryptographer_.GetKeystoreKeyBootstrapToken(&token);
236 EXPECT_FALSE(token.empty());
237
238 Cryptographer cryptographer2(&encryptor_);
239 EXPECT_FALSE(cryptographer2.HasKeystoreKey());
240 cryptographer2.BootstrapKeystoreKey(token);
241 EXPECT_TRUE(cryptographer2.HasKeystoreKey());
242 EXPECT_FALSE(cryptographer2.is_initialized());
243 }
244
245 } // namespace syncer 214 } // namespace syncer
OLDNEW
« sync/util/cryptographer.cc ('K') | « sync/util/cryptographer.cc ('k') | sync/util/nigori.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698