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 "sync/util/nigori.h" | 5 #include "components/sync/base/nigori.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace syncer { | 12 namespace syncer { |
13 namespace { | 13 namespace { |
14 | 14 |
15 TEST(SyncNigoriTest, Permute) { | 15 TEST(SyncNigoriTest, Permute) { |
16 Nigori nigori; | 16 Nigori nigori; |
17 EXPECT_TRUE(nigori.InitByDerivation("example.com", "username", "password")); | 17 EXPECT_TRUE(nigori.InitByDerivation("example.com", "username", "password")); |
18 | 18 |
19 std::string permuted; | 19 std::string permuted; |
20 EXPECT_TRUE(nigori.Permute(Nigori::Password, "test name", | 20 EXPECT_TRUE(nigori.Permute(Nigori::Password, "test name", &permuted)); |
21 &permuted)); | |
22 | 21 |
23 std::string expected = | 22 std::string expected = |
24 "prewwdJj2PrGDczvmsHJEE5ndcCyVze8sY9kD5hjY/Tm" | 23 "prewwdJj2PrGDczvmsHJEE5ndcCyVze8sY9kD5hjY/Tm" |
25 "c5kOjXFK7zB3Ss4LlHjEDirMu+vh85JwHOnGrMVe+g=="; | 24 "c5kOjXFK7zB3Ss4LlHjEDirMu+vh85JwHOnGrMVe+g=="; |
26 EXPECT_EQ(expected, permuted); | 25 EXPECT_EQ(expected, permuted); |
27 } | 26 } |
28 | 27 |
29 TEST(SyncNigoriTest, PermuteIsConstant) { | 28 TEST(SyncNigoriTest, PermuteIsConstant) { |
30 Nigori nigori1; | 29 Nigori nigori1; |
31 EXPECT_TRUE(nigori1.InitByDerivation("example.com", "username", "password")); | 30 EXPECT_TRUE(nigori1.InitByDerivation("example.com", "username", "password")); |
32 | 31 |
33 std::string permuted1; | 32 std::string permuted1; |
34 EXPECT_TRUE(nigori1.Permute(Nigori::Password, | 33 EXPECT_TRUE(nigori1.Permute(Nigori::Password, "name", &permuted1)); |
35 "name", | |
36 &permuted1)); | |
37 | 34 |
38 Nigori nigori2; | 35 Nigori nigori2; |
39 EXPECT_TRUE(nigori2.InitByDerivation("example.com", "username", "password")); | 36 EXPECT_TRUE(nigori2.InitByDerivation("example.com", "username", "password")); |
40 | 37 |
41 std::string permuted2; | 38 std::string permuted2; |
42 EXPECT_TRUE(nigori2.Permute(Nigori::Password, | 39 EXPECT_TRUE(nigori2.Permute(Nigori::Password, "name", &permuted2)); |
43 "name", | |
44 &permuted2)); | |
45 | 40 |
46 EXPECT_LT(0U, permuted1.size()); | 41 EXPECT_LT(0U, permuted1.size()); |
47 EXPECT_EQ(permuted1, permuted2); | 42 EXPECT_EQ(permuted1, permuted2); |
48 } | 43 } |
49 | 44 |
50 TEST(SyncNigoriTest, EncryptDifferentIv) { | 45 TEST(SyncNigoriTest, EncryptDifferentIv) { |
51 Nigori nigori; | 46 Nigori nigori; |
52 EXPECT_TRUE(nigori.InitByDerivation("example.com", "username", "password")); | 47 EXPECT_TRUE(nigori.InitByDerivation("example.com", "username", "password")); |
53 | 48 |
54 std::string plaintext("value"); | 49 std::string plaintext("value"); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 EXPECT_EQ(original, plaintext); | 149 EXPECT_EQ(original, plaintext); |
155 | 150 |
156 std::string permuted1, permuted2; | 151 std::string permuted1, permuted2; |
157 EXPECT_TRUE(nigori1.Permute(Nigori::Password, original, &permuted1)); | 152 EXPECT_TRUE(nigori1.Permute(Nigori::Password, original, &permuted1)); |
158 EXPECT_TRUE(nigori2.Permute(Nigori::Password, original, &permuted2)); | 153 EXPECT_TRUE(nigori2.Permute(Nigori::Password, original, &permuted2)); |
159 EXPECT_EQ(permuted1, permuted2); | 154 EXPECT_EQ(permuted1, permuted2); |
160 } | 155 } |
161 | 156 |
162 } // anonymous namespace | 157 } // anonymous namespace |
163 } // namespace syncer | 158 } // namespace syncer |
OLD | NEW |