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

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

Issue 2934893003: Deleted redundant SymmetricKey::GetRawKey(). (Closed)
Patch Set: Rebased to fix conflict with ToT. Created 3 years, 6 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
« no previous file with comments | « components/sync/base/nigori.cc ('k') | crypto/hmac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 user_key;
130 std::string encryption_key; 130 std::string encryption_key;
131 std::string mac_key; 131 std::string mac_key;
132 EXPECT_TRUE(nigori1.ExportKeys(&user_key, &encryption_key, &mac_key)); 132 nigori1.ExportKeys(&user_key, &encryption_key, &mac_key);
133 133
134 Nigori nigori2; 134 Nigori nigori2;
135 EXPECT_TRUE(nigori2.InitByImport(user_key, encryption_key, mac_key)); 135 EXPECT_TRUE(nigori2.InitByImport(user_key, encryption_key, mac_key));
136 136
137 std::string original("test"); 137 std::string original("test");
138 std::string plaintext; 138 std::string plaintext;
139 std::string ciphertext; 139 std::string ciphertext;
140 140
141 EXPECT_TRUE(nigori1.Encrypt(original, &ciphertext)); 141 EXPECT_TRUE(nigori1.Encrypt(original, &ciphertext));
142 EXPECT_TRUE(nigori2.Decrypt(ciphertext, &plaintext)); 142 EXPECT_TRUE(nigori2.Decrypt(ciphertext, &plaintext));
143 EXPECT_EQ(original, plaintext); 143 EXPECT_EQ(original, plaintext);
144 144
145 EXPECT_TRUE(nigori2.Encrypt(original, &ciphertext)); 145 EXPECT_TRUE(nigori2.Encrypt(original, &ciphertext));
146 EXPECT_TRUE(nigori1.Decrypt(ciphertext, &plaintext)); 146 EXPECT_TRUE(nigori1.Decrypt(ciphertext, &plaintext));
147 EXPECT_EQ(original, plaintext); 147 EXPECT_EQ(original, plaintext);
148 148
149 std::string permuted1, permuted2; 149 std::string permuted1, permuted2;
150 EXPECT_TRUE(nigori1.Permute(Nigori::Password, original, &permuted1)); 150 EXPECT_TRUE(nigori1.Permute(Nigori::Password, original, &permuted1));
151 EXPECT_TRUE(nigori2.Permute(Nigori::Password, original, &permuted2)); 151 EXPECT_TRUE(nigori2.Permute(Nigori::Password, original, &permuted2));
152 EXPECT_EQ(permuted1, permuted2); 152 EXPECT_EQ(permuted1, permuted2);
153 } 153 }
154 154
155 TEST(SyncNigoriTest, InitByDerivationSetsUserKey) { 155 TEST(SyncNigoriTest, InitByDerivationSetsUserKey) {
156 Nigori nigori; 156 Nigori nigori;
157 EXPECT_TRUE(nigori.InitByDerivation("example.com", "username", "password")); 157 EXPECT_TRUE(nigori.InitByDerivation("example.com", "username", "password"));
158 158
159 std::string user_key = ""; 159 std::string user_key = "";
160 std::string encryption_key; 160 std::string encryption_key;
161 std::string mac_key; 161 std::string mac_key;
162 EXPECT_TRUE(nigori.ExportKeys(&user_key, &encryption_key, &mac_key)); 162 nigori.ExportKeys(&user_key, &encryption_key, &mac_key);
163 163
164 EXPECT_NE(user_key, ""); 164 EXPECT_NE(user_key, "");
165 } 165 }
166 166
167 TEST(SyncNigoriTest, ToleratesEmptyUserKey) { 167 TEST(SyncNigoriTest, ToleratesEmptyUserKey) {
168 Nigori nigori1; 168 Nigori nigori1;
169 EXPECT_TRUE(nigori1.InitByDerivation("example.com", "username", "password")); 169 EXPECT_TRUE(nigori1.InitByDerivation("example.com", "username", "password"));
170 170
171 std::string user_key; 171 std::string user_key;
172 std::string encryption_key; 172 std::string encryption_key;
173 std::string mac_key; 173 std::string mac_key;
174 EXPECT_TRUE(nigori1.ExportKeys(&user_key, &encryption_key, &mac_key)); 174 nigori1.ExportKeys(&user_key, &encryption_key, &mac_key);
175 EXPECT_FALSE(user_key.empty()); 175 EXPECT_FALSE(user_key.empty());
176 EXPECT_FALSE(encryption_key.empty()); 176 EXPECT_FALSE(encryption_key.empty());
177 EXPECT_FALSE(mac_key.empty()); 177 EXPECT_FALSE(mac_key.empty());
178 178
179 Nigori nigori2; 179 Nigori nigori2;
180 EXPECT_TRUE(nigori2.InitByImport("", encryption_key, mac_key)); 180 EXPECT_TRUE(nigori2.InitByImport("", encryption_key, mac_key));
181 181
182 user_key = "non-empty-value"; 182 user_key = "non-empty-value";
183 EXPECT_TRUE(nigori2.ExportKeys(&user_key, &encryption_key, &mac_key)); 183 nigori2.ExportKeys(&user_key, &encryption_key, &mac_key);
184 EXPECT_TRUE(user_key.empty()); 184 EXPECT_TRUE(user_key.empty());
185 EXPECT_FALSE(encryption_key.empty()); 185 EXPECT_FALSE(encryption_key.empty());
186 EXPECT_FALSE(mac_key.empty()); 186 EXPECT_FALSE(mac_key.empty());
187 } 187 }
188 188
189 } // anonymous namespace 189 } // anonymous namespace
190 } // namespace syncer 190 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/base/nigori.cc ('k') | crypto/hmac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698