chromium/components/os_crypt/async/browser/os_crypt_async_unittest.cc

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/os_crypt/async/browser/os_crypt_async.h"

#include <optional>

#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/test/task_environment.h"
#include "components/os_crypt/async/browser/key_provider.h"
#include "components/os_crypt/async/browser/test_utils.h"
#include "components/os_crypt/async/common/algorithm.mojom.h"
#include "components/os_crypt/async/common/encryptor.h"
#include "components/os_crypt/sync/os_crypt.h"
#include "components/os_crypt/sync/os_crypt_mocker.h"
#include "crypto/hkdf.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(IS_LINUX)
#include "components/os_crypt/sync/key_storage_linux.h"
#endif

namespace os_crypt_async {

namespace {

// Helper function to verify that decryption using OSCrypt failed. This is
// platform dependent, as Windows will fail, but other platforms will return the
// ciphertext back.
[[nodiscard]] bool MaybeVerifyFailedDecryptOperation(
    const std::optional<std::string>& decrypted,
    base::span<const uint8_t> ciphertext) {}

}  // namespace
class OSCryptAsyncTest : public ::testing::Test {};

class TestKeyProvider : public KeyProvider {};

TEST_F(OSCryptAsyncTest, EncryptHeader) {}

TEST_F(OSCryptAsyncTest, TwoProvidersBothEnabled) {}

TEST_F(OSCryptAsyncTest, TwoProvidersOneEnabled) {}

TEST_F(OSCryptAsyncTest, EncryptorOption) {}

class SlowTestKeyProvider : public TestKeyProvider {};

// This test verifies that GetInstanceAsync can correctly handle multiple queued
// requests for an instance for a slow init.
TEST_F(OSCryptAsyncTest, MultipleCalls) {}

// This test verifies that if the subscription from CallbackList moves out of
// scope, then the callback never occurs.
TEST_F(OSCryptAsyncTest, SubscriptionCancelled) {}

TEST_F(OSCryptAsyncTest, TestOSCryptAsyncInterface) {}

TEST_F(OSCryptAsyncTest, TestEncryptorInterface) {}

class FailingKeyProvider : public TestKeyProvider {};

// Some tests require a working OSCrypt.
class OSCryptAsyncTestWithOSCrypt : public OSCryptAsyncTest {};

// This test merely verifies that OSCryptAsync can operate with no key providers
// and return a valid Encryptor with no keys, and that it can interop with
// OSCrypt. The rest of the encryption tests for this mode are located in
// encryptor_unittest.cc.
TEST_F(OSCryptAsyncTestWithOSCrypt, Empty) {}

TEST_F(OSCryptAsyncTestWithOSCrypt, FailingKeyProvider) {}

// Test also that if no key providers have OSCrypt sync compatibility then
// encryption simply falls back to OSCrypt, and that OSCrypt can decrypt it
// fine.
TEST_F(OSCryptAsyncTestWithOSCrypt, EncryptorOption) {}

OSCryptAsyncDeathTest;

TEST_F(OSCryptAsyncDeathTest, SamePrecedence) {}

TEST_F(OSCryptAsyncDeathTest, SameName) {}

TEST_F(OSCryptAsyncDeathTest, OverlappingNames) {}

TEST_F(OSCryptAsyncDeathTest, OverlappingNamesBackwards) {}

TEST_F(OSCryptAsyncTest, NoCrashWithLongNames) {}

}  // namespace os_crypt_async