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

Side by Side Diff: components/sync/base/nigori_unittest.cc

Issue 2813453004: [sync] Fix decryption failure caused by missing user_key (Closed)
Patch Set: Restore derivation check, add tests Created 3 years, 8 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
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 "components/sync/base/nigori.h" 5 #include "components/sync/base/nigori.h"
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace syncer { 10 namespace syncer {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 std::string decrypted; 119 std::string decrypted;
120 EXPECT_FALSE(nigori.Decrypt(encrypted, &decrypted)); 120 EXPECT_FALSE(nigori.Decrypt(encrypted, &decrypted));
121 121
122 EXPECT_NE(plaintext, decrypted); 122 EXPECT_NE(plaintext, decrypted);
123 } 123 }
124 124
125 TEST(SyncNigoriTest, ExportImport) { 125 TEST(SyncNigoriTest, ExportImport) {
126 Nigori nigori1; 126 Nigori nigori1;
127 EXPECT_TRUE(nigori1.InitByDerivation("example.com", "username", "password")); 127 EXPECT_TRUE(nigori1.InitByDerivation("example.com", "username", "password"));
128 128
129 std::string user_key;
129 std::string encryption_key; 130 std::string encryption_key;
130 std::string mac_key; 131 std::string mac_key;
131 EXPECT_TRUE(nigori1.ExportKeys(&encryption_key, &mac_key)); 132 EXPECT_TRUE(nigori1.ExportKeys(&user_key, &encryption_key, &mac_key));
132 133
133 Nigori nigori2; 134 Nigori nigori2;
134 EXPECT_TRUE(nigori2.InitByImport(encryption_key, mac_key)); 135 EXPECT_TRUE(nigori2.InitByImport(user_key, encryption_key, mac_key));
135 136
136 std::string original("test"); 137 std::string original("test");
137 std::string plaintext; 138 std::string plaintext;
138 std::string ciphertext; 139 std::string ciphertext;
139 140
140 EXPECT_TRUE(nigori1.Encrypt(original, &ciphertext)); 141 EXPECT_TRUE(nigori1.Encrypt(original, &ciphertext));
141 EXPECT_TRUE(nigori2.Decrypt(ciphertext, &plaintext)); 142 EXPECT_TRUE(nigori2.Decrypt(ciphertext, &plaintext));
142 EXPECT_EQ(original, plaintext); 143 EXPECT_EQ(original, plaintext);
143 144
144 EXPECT_TRUE(nigori2.Encrypt(original, &ciphertext)); 145 EXPECT_TRUE(nigori2.Encrypt(original, &ciphertext));
145 EXPECT_TRUE(nigori1.Decrypt(ciphertext, &plaintext)); 146 EXPECT_TRUE(nigori1.Decrypt(ciphertext, &plaintext));
146 EXPECT_EQ(original, plaintext); 147 EXPECT_EQ(original, plaintext);
147 148
148 std::string permuted1, permuted2; 149 std::string permuted1, permuted2;
149 EXPECT_TRUE(nigori1.Permute(Nigori::Password, original, &permuted1)); 150 EXPECT_TRUE(nigori1.Permute(Nigori::Password, original, &permuted1));
150 EXPECT_TRUE(nigori2.Permute(Nigori::Password, original, &permuted2)); 151 EXPECT_TRUE(nigori2.Permute(Nigori::Password, original, &permuted2));
151 EXPECT_EQ(permuted1, permuted2); 152 EXPECT_EQ(permuted1, permuted2);
152 } 153 }
153 154
155 TEST(SyncNigoriTest, InitByDerivationSetsUserKey) {
156 Nigori nigori;
157 EXPECT_TRUE(nigori.InitByDerivation("example.com", "username", "password"));
158
159 std::string user_key = "";
160 std::string encryption_key;
161 std::string mac_key;
162 EXPECT_TRUE(nigori.ExportKeys(&user_key, &encryption_key, &mac_key));
163
164 EXPECT_NE(user_key, "");
165 }
166
167 TEST(SyncNigoriTest, InitByImportToleratesEmptyUserKey) {
168 Nigori nigori1;
169 EXPECT_TRUE(nigori1.InitByDerivation("example.com", "username", "password"));
170
171 std::string user_key;
172 std::string encryption_key;
173 std::string mac_key;
174 EXPECT_TRUE(nigori1.ExportKeys(&user_key, &encryption_key, &mac_key));
175
176 Nigori nigori2;
177 EXPECT_TRUE(nigori2.InitByImport("", encryption_key, mac_key));
178 }
179
154 } // anonymous namespace 180 } // anonymous namespace
155 } // namespace syncer 181 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/base/nigori.cc ('k') | components/sync/engine_impl/model_type_worker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698