Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: components/os_crypt/os_crypt_unittest.cc

Issue 1973483002: OSCrypt for POSIX uses libsecret to store a randomised encryption key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed asan Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/os_crypt/os_crypt.h" 5 #include "components/os_crypt/os_crypt.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 #if defined(USE_LIBSECRET)
17 #include "components/os_crypt/os_crypt_mocker_linux.h"
18 #endif
19
16 namespace { 20 namespace {
17 21
18 class OSCryptTest : public testing::Test { 22 class OSCryptTest : public testing::Test {
19 public: 23 public:
20 OSCryptTest() {} 24 OSCryptTest() {}
21 25
22 void SetUp() override { 26 void SetUp() override {
23 #if defined(OS_MACOSX) 27 #if defined(OS_MACOSX)
24 OSCrypt::UseMockKeychain(true); 28 OSCrypt::UseMockKeychain(true);
25 #endif 29 #endif
30 #if defined(USE_LIBSECRET)
31 OSCryptMockerLinux::SetUpWithSingleton();
32 #endif
33 }
34
35 void TearDown() override {
36 #if defined(USE_LIBSECRET)
37 OSCryptMockerLinux::TearDown();
38 #endif
26 } 39 }
27 40
28 private: 41 private:
29 DISALLOW_COPY_AND_ASSIGN(OSCryptTest); 42 DISALLOW_COPY_AND_ASSIGN(OSCryptTest);
30 }; 43 };
31 44
32 TEST_F(OSCryptTest, String16EncryptionDecryption) { 45 TEST_F(OSCryptTest, String16EncryptionDecryption) {
33 base::string16 plaintext; 46 base::string16 plaintext;
34 base::string16 result; 47 base::string16 result;
35 std::string utf8_plaintext; 48 std::string utf8_plaintext;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 ASSERT_TRUE(OSCrypt::EncryptString(plaintext, &ciphertext)); 150 ASSERT_TRUE(OSCrypt::EncryptString(plaintext, &ciphertext));
138 EXPECT_NE(plaintext, ciphertext); 151 EXPECT_NE(plaintext, ciphertext);
139 ASSERT_LT(4UL, ciphertext.size()); 152 ASSERT_LT(4UL, ciphertext.size());
140 ciphertext[3] = ciphertext[3] + 1; 153 ciphertext[3] = ciphertext[3] + 1;
141 EXPECT_FALSE(OSCrypt::DecryptString(ciphertext, &result)); 154 EXPECT_FALSE(OSCrypt::DecryptString(ciphertext, &result));
142 EXPECT_NE(plaintext, result); 155 EXPECT_NE(plaintext, result);
143 EXPECT_TRUE(result.empty()); 156 EXPECT_TRUE(result.empty());
144 } 157 }
145 158
146 } // namespace 159 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698