| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/password_manager/encryptor.h" | 5 #include "chrome/browser/password_manager/encryptor.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result)); | 90 ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result)); |
| 91 EXPECT_EQ(plaintext, result); | 91 EXPECT_EQ(plaintext, result); |
| 92 | 92 |
| 93 // Make sure it null terminates. | 93 // Make sure it null terminates. |
| 94 plaintext.assign("hello", 3); | 94 plaintext.assign("hello", 3); |
| 95 ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); | 95 ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); |
| 96 ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result)); | 96 ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result)); |
| 97 EXPECT_EQ(plaintext, "hel"); | 97 EXPECT_EQ(plaintext, "hel"); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Encryption currently only enabled on Mac and Windows. | |
| 101 // TODO(dhollowa): http://crbug.com/49115 Implement secure store on Linux. | |
| 102 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 103 TEST_F(EncryptorTest, CypherTextDiffers) { | 100 TEST_F(EncryptorTest, CypherTextDiffers) { |
| 104 std::string plaintext; | 101 std::string plaintext; |
| 105 std::string result; | 102 std::string result; |
| 106 std::string ciphertext; | 103 std::string ciphertext; |
| 107 | 104 |
| 108 // Test borderline cases (empty strings). | 105 // Test borderline cases (empty strings). |
| 109 ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); | 106 ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); |
| 110 ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result)); | 107 ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result)); |
| 111 // |cyphertext| is empty on the Mac, different on Windows. | 108 // |cyphertext| is empty on the Mac, different on Windows. |
| 112 EXPECT_TRUE(ciphertext.empty() || plaintext != ciphertext); | 109 EXPECT_TRUE(ciphertext.empty() || plaintext != ciphertext); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 130 TEST_F(EncryptorTest, DecryptError) { | 127 TEST_F(EncryptorTest, DecryptError) { |
| 131 std::string plaintext; | 128 std::string plaintext; |
| 132 std::string result; | 129 std::string result; |
| 133 std::string ciphertext; | 130 std::string ciphertext; |
| 134 | 131 |
| 135 // Test a simple string, messing with ciphertext prior to decrypting. | 132 // Test a simple string, messing with ciphertext prior to decrypting. |
| 136 plaintext = "hello"; | 133 plaintext = "hello"; |
| 137 ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); | 134 ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); |
| 138 EXPECT_NE(plaintext, ciphertext); | 135 EXPECT_NE(plaintext, ciphertext); |
| 139 ASSERT_LT(4UL, ciphertext.size()); | 136 ASSERT_LT(4UL, ciphertext.size()); |
| 140 ciphertext[3] = ciphertext[0] + 1; | 137 ciphertext[3] = ciphertext[3] + 1; |
| 141 EXPECT_FALSE(Encryptor::DecryptString(ciphertext, &result)); | 138 EXPECT_FALSE(Encryptor::DecryptString(ciphertext, &result)); |
| 142 EXPECT_NE(plaintext, result); | 139 EXPECT_NE(plaintext, result); |
| 143 EXPECT_TRUE(result.empty()); | 140 EXPECT_TRUE(result.empty()); |
| 144 } | 141 } |
| 145 #endif | |
| 146 | 142 |
| 147 } // namespace | 143 } // namespace |
| OLD | NEW |