| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/util/cryptographer.h" | 5 #include "chrome/browser/sync/util/cryptographer.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "chrome/browser/password_manager/encryptor.h" | 11 #include "chrome/browser/password_manager/encryptor.h" |
| 12 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 12 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 namespace browser_sync { | 15 namespace browser_sync { |
| 16 | 16 |
| 17 TEST(CryptographerTest, EmptyCantDecrypt) { | 17 TEST(CryptographerTest, EmptyCantDecrypt) { |
| 18 Cryptographer cryptographer; | 18 Cryptographer cryptographer; |
| 19 EXPECT_FALSE(cryptographer.is_ready()); | 19 EXPECT_FALSE(cryptographer.is_ready()); |
| 20 | 20 |
| 21 sync_pb::EncryptedData encrypted; | 21 sync_pb::EncryptedData encrypted; |
| 22 encrypted.set_key_name("foo"); | 22 encrypted.set_key_name("foo"); |
| 23 encrypted.set_blob("bar"); | 23 encrypted.set_blob("bar"); |
| 24 | 24 |
| 25 EXPECT_FALSE(cryptographer.CanDecrypt(encrypted)); | 25 EXPECT_FALSE(cryptographer.CanDecrypt(encrypted)); |
| 26 } | 26 } |
| 27 | 27 |
| 28 TEST(CryptographerTest, EmptyCantEncrypt) { |
| 29 Cryptographer cryptographer; |
| 30 EXPECT_FALSE(cryptographer.is_ready()); |
| 31 |
| 32 sync_pb::EncryptedData encrypted; |
| 33 sync_pb::PasswordSpecificsData original; |
| 34 EXPECT_FALSE(cryptographer.Encrypt(original, &encrypted)); |
| 35 } |
| 36 |
| 28 TEST(CryptographerTest, MissingCantDecrypt) { | 37 TEST(CryptographerTest, MissingCantDecrypt) { |
| 29 Cryptographer cryptographer; | 38 Cryptographer cryptographer; |
| 30 | 39 |
| 31 KeyParams params = {"localhost", "dummy", "dummy"}; | 40 KeyParams params = {"localhost", "dummy", "dummy"}; |
| 32 cryptographer.AddKey(params); | 41 cryptographer.AddKey(params); |
| 33 EXPECT_TRUE(cryptographer.is_ready()); | 42 EXPECT_TRUE(cryptographer.is_ready()); |
| 34 | 43 |
| 35 sync_pb::EncryptedData encrypted; | 44 sync_pb::EncryptedData encrypted; |
| 36 encrypted.set_key_name("foo"); | 45 encrypted.set_key_name("foo"); |
| 37 encrypted.set_blob("bar"); | 46 encrypted.set_blob("bar"); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 172 |
| 164 std::string user_key, encryption_key, mac_key; | 173 std::string user_key, encryption_key, mac_key; |
| 165 ASSERT_TRUE(unpacked->ExportKeys(&user_key, &encryption_key, &mac_key)); | 174 ASSERT_TRUE(unpacked->ExportKeys(&user_key, &encryption_key, &mac_key)); |
| 166 | 175 |
| 167 EXPECT_EQ(expected_user, user_key); | 176 EXPECT_EQ(expected_user, user_key); |
| 168 EXPECT_EQ(expected_encryption, encryption_key); | 177 EXPECT_EQ(expected_encryption, encryption_key); |
| 169 EXPECT_EQ(expected_mac, mac_key); | 178 EXPECT_EQ(expected_mac, mac_key); |
| 170 } | 179 } |
| 171 | 180 |
| 172 } // namespace browser_sync | 181 } // namespace browser_sync |
| OLD | NEW |