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

Unified 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, 7 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/os_crypt/os_crypt_linux_unittest.cc
diff --git a/components/os_crypt/os_crypt_linux_unittest.cc b/components/os_crypt/os_crypt_linux_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5f22c316aed39ccd99d04972e7d77ba42cfe57ad
--- /dev/null
+++ b/components/os_crypt/os_crypt_linux_unittest.cc
@@ -0,0 +1,70 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "base/macros.h"
+#include "components/os_crypt/key_storage_linux.h"
+#include "components/os_crypt/os_crypt.h"
+#include "components/os_crypt/os_crypt_mocker_linux.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class OSCryptLinuxTest : public testing::Test {
+ public:
+ OSCryptLinuxTest() = default;
+ ~OSCryptLinuxTest() override = default;
+
+ void SetUp() override {
+ OSCryptMockerLinux::SetUpWithSingleton();
+ key_storage_ = OSCryptMockerLinux::GetInstance();
+ }
+
+ void TearDown() override { OSCryptMockerLinux::TearDown(); }
+
+ protected:
+ OSCryptMockerLinux* key_storage_ = nullptr;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(OSCryptLinuxTest);
+};
+
+TEST_F(OSCryptLinuxTest, VerifyV0) {
+ const std::string originaltext = "hello";
+ std::string ciphertext;
+ std::string decipheredtext;
+
+ key_storage_->ResetTo("");
+ ciphertext = originaltext; // No encryption
+ ASSERT_TRUE(OSCrypt::DecryptString(ciphertext, &decipheredtext));
+ ASSERT_EQ(originaltext, decipheredtext);
+}
+
+TEST_F(OSCryptLinuxTest, VerifyV10) {
+ const std::string originaltext = "hello";
+ std::string ciphertext;
+ std::string decipheredtext;
+
+ key_storage_->ResetTo("peanuts");
+ ASSERT_TRUE(OSCrypt::EncryptString(originaltext, &ciphertext));
+ key_storage_->ResetTo("not_peanuts");
+ ciphertext = ciphertext.substr(3).insert(0, "v10");
+ ASSERT_TRUE(OSCrypt::DecryptString(ciphertext, &decipheredtext));
+ ASSERT_EQ(originaltext, decipheredtext);
+}
+
+TEST_F(OSCryptLinuxTest, VerifyV11) {
+ const std::string originaltext = "hello";
+ std::string ciphertext;
+ std::string decipheredtext;
+
+ key_storage_->ResetTo("");
+ ASSERT_TRUE(OSCrypt::EncryptString(originaltext, &ciphertext));
+ ASSERT_EQ(ciphertext.substr(0, 3), "v11");
+ ASSERT_TRUE(OSCrypt::DecryptString(ciphertext, &decipheredtext));
+ ASSERT_EQ(originaltext, decipheredtext);
+}
+
+} // namespace
« 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