OLD | NEW |
---|---|
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 { |
11 namespace { | 11 namespace { |
12 | 12 |
13 TEST(SyncNigoriTest, Permute) { | 13 TEST(SyncNigoriTest, Permute) { |
pavely
2017/04/10 21:27:29
Could you add tests that InitByDerivation populate
Patrick Noland
2017/04/10 23:43:06
Done.
| |
14 Nigori nigori; | 14 Nigori nigori; |
15 EXPECT_TRUE(nigori.InitByDerivation("example.com", "username", "password")); | 15 EXPECT_TRUE(nigori.InitByDerivation("example.com", "username", "password")); |
16 | 16 |
17 std::string permuted; | 17 std::string permuted; |
18 EXPECT_TRUE(nigori.Permute(Nigori::Password, "test name", &permuted)); | 18 EXPECT_TRUE(nigori.Permute(Nigori::Password, "test name", &permuted)); |
19 | 19 |
20 std::string expected = | 20 std::string expected = |
21 "prewwdJj2PrGDczvmsHJEE5ndcCyVze8sY9kD5hjY/Tm" | 21 "prewwdJj2PrGDczvmsHJEE5ndcCyVze8sY9kD5hjY/Tm" |
22 "c5kOjXFK7zB3Ss4LlHjEDirMu+vh85JwHOnGrMVe+g=="; | 22 "c5kOjXFK7zB3Ss4LlHjEDirMu+vh85JwHOnGrMVe+g=="; |
23 EXPECT_EQ(expected, permuted); | 23 EXPECT_EQ(expected, permuted); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
154 } // anonymous namespace | 155 } // anonymous namespace |
155 } // namespace syncer | 156 } // namespace syncer |
OLD | NEW |