| 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 { |
| (...skipping 108 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; | |
| 130 std::string encryption_key; | 129 std::string encryption_key; |
| 131 std::string mac_key; | 130 std::string mac_key; |
| 132 EXPECT_TRUE(nigori1.ExportKeys(&user_key, &encryption_key, &mac_key)); | 131 EXPECT_TRUE(nigori1.ExportKeys(&encryption_key, &mac_key)); |
| 133 | 132 |
| 134 Nigori nigori2; | 133 Nigori nigori2; |
| 135 EXPECT_TRUE(nigori2.InitByImport(user_key, encryption_key, mac_key)); | 134 EXPECT_TRUE(nigori2.InitByImport(encryption_key, mac_key)); |
| 136 | 135 |
| 137 std::string original("test"); | 136 std::string original("test"); |
| 138 std::string plaintext; | 137 std::string plaintext; |
| 139 std::string ciphertext; | 138 std::string ciphertext; |
| 140 | 139 |
| 141 EXPECT_TRUE(nigori1.Encrypt(original, &ciphertext)); | 140 EXPECT_TRUE(nigori1.Encrypt(original, &ciphertext)); |
| 142 EXPECT_TRUE(nigori2.Decrypt(ciphertext, &plaintext)); | 141 EXPECT_TRUE(nigori2.Decrypt(ciphertext, &plaintext)); |
| 143 EXPECT_EQ(original, plaintext); | 142 EXPECT_EQ(original, plaintext); |
| 144 | 143 |
| 145 EXPECT_TRUE(nigori2.Encrypt(original, &ciphertext)); | 144 EXPECT_TRUE(nigori2.Encrypt(original, &ciphertext)); |
| 146 EXPECT_TRUE(nigori1.Decrypt(ciphertext, &plaintext)); | 145 EXPECT_TRUE(nigori1.Decrypt(ciphertext, &plaintext)); |
| 147 EXPECT_EQ(original, plaintext); | 146 EXPECT_EQ(original, plaintext); |
| 148 | 147 |
| 149 std::string permuted1, permuted2; | 148 std::string permuted1, permuted2; |
| 150 EXPECT_TRUE(nigori1.Permute(Nigori::Password, original, &permuted1)); | 149 EXPECT_TRUE(nigori1.Permute(Nigori::Password, original, &permuted1)); |
| 151 EXPECT_TRUE(nigori2.Permute(Nigori::Password, original, &permuted2)); | 150 EXPECT_TRUE(nigori2.Permute(Nigori::Password, original, &permuted2)); |
| 152 EXPECT_EQ(permuted1, permuted2); | 151 EXPECT_EQ(permuted1, permuted2); |
| 153 } | 152 } |
| 154 | 153 |
| 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 | |
| 180 } // anonymous namespace | 154 } // anonymous namespace |
| 181 } // namespace syncer | 155 } // namespace syncer |
| OLD | NEW |