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

Side by Side Diff: components/os_crypt/os_crypt_linux_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: Recommendations 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
« no previous file with comments | « components/os_crypt/os_crypt_linux.cc ('k') | components/os_crypt/os_crypt_mocker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <string>
6
7 #include "base/macros.h"
8 #include "components/os_crypt/key_storage_linux.h"
9 #include "components/os_crypt/os_crypt.h"
10 #include "components/os_crypt/os_crypt_mocker_linux.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace {
14
15 class OSCryptLinuxTest : public testing::Test {
16 public:
17 OSCryptLinuxTest() = default;
18 ~OSCryptLinuxTest() override = default;
19
20 void SetUp() override {
21 OSCryptMockerLinux::SetUpWithSingleton();
22 key_storage_ = OSCryptMockerLinux::GetInstance();
23 }
24
25 void TearDown() override { OSCryptMockerLinux::TearDown(); }
26
27 protected:
28 OSCryptMockerLinux* key_storage_ = nullptr;
29
30 private:
31 DISALLOW_COPY_AND_ASSIGN(OSCryptLinuxTest);
32 };
33
34 TEST_F(OSCryptLinuxTest, VerifyV0) {
35 const std::string originaltext = "hello";
36 std::string ciphertext;
37 std::string decipheredtext;
38
39 key_storage_->ResetTo("");
40 ciphertext = originaltext; // No encryption
41 ASSERT_TRUE(OSCrypt::DecryptString(ciphertext, &decipheredtext));
42 ASSERT_EQ(originaltext, decipheredtext);
43 }
44
45 TEST_F(OSCryptLinuxTest, VerifyV10) {
46 const std::string originaltext = "hello";
47 std::string ciphertext;
48 std::string decipheredtext;
49
50 key_storage_->ResetTo("peanuts");
51 ASSERT_TRUE(OSCrypt::EncryptString(originaltext, &ciphertext));
52 key_storage_->ResetTo("not_peanuts");
53 ciphertext = ciphertext.substr(3).insert(0, "v10");
54 ASSERT_TRUE(OSCrypt::DecryptString(ciphertext, &decipheredtext));
55 ASSERT_EQ(originaltext, decipheredtext);
56 }
57
58 TEST_F(OSCryptLinuxTest, VerifyV11) {
59 const std::string originaltext = "hello";
60 std::string ciphertext;
61 std::string decipheredtext;
62
63 key_storage_->ResetTo("");
64 ASSERT_TRUE(OSCrypt::EncryptString(originaltext, &ciphertext));
65 ASSERT_EQ(ciphertext.substr(0, 3), "v11");
66 ASSERT_TRUE(OSCrypt::DecryptString(ciphertext, &decipheredtext));
67 ASSERT_EQ(originaltext, decipheredtext);
68 }
69
70 } // namespace
OLDNEW
« no previous file with comments | « components/os_crypt/os_crypt_linux.cc ('k') | components/os_crypt/os_crypt_mocker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698