#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/enterprise/connectors/device_trust/key_management/core/persistence/linux_key_persistence_delegate.h"
#include <string>
#include <string_view>
#include "base/base64.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/strings/stringprintf.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/enterprise/connectors/device_trust/key_management/core/ec_signing_key.h"
#include "chrome/browser/enterprise/connectors/device_trust/key_management/core/persistence/metrics_utils.h"
#include "chrome/browser/enterprise/connectors/device_trust/key_management/core/signing_key_pair.h"
#include "components/policy/proto/device_management_backend.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
BPKUR;
namespace {
base::FilePath::CharType kFileName[] = …);
constexpr char kErrorHistogramFormat[] = …;
constexpr char kGibberish[] = …;
constexpr char kValidKeyWrappedBase64[] = …;
constexpr char kInvalidBase64String[] = …;
constexpr char kValidHWKeyFileContent[] = …;
constexpr char kValidOSKeyFileContent[] = …;
constexpr char kInvalidTrustLevelKeyFileContent[] = …;
std::vector<uint8_t> ParseKeyWrapped(std::string_view encoded_wrapped) { … }
void ValidateSigningKey(enterprise_connectors::SigningKeyPair* key_pair,
BPKUR::KeyTrustLevel trust_level) { … }
}
namespace enterprise_connectors {
class LinuxKeyPersistenceDelegateTest : public testing::Test { … };
TEST_F(LinuxKeyPersistenceDelegateTest, StoreKeyPair_FileDoesNotExist) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, StoreKeyPair_UnspecifiedKey) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, StoreKeyPair_ValidOSKeyPair) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, StoreKeyPair_ValidHWKeyPair) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, LoadKeyPair_NoKeyFile) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, LoadKeyPair_ValidOSKeyFile) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, LoadKeyPair_ValidHWKeyFile) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, LoadKeyPair_InvalidTrustLevel) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, LoadKeyPair_MissingSigningKey) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, LoadKeyPair_MissingTrustLevel) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, LoadKeyPair_InvalidContent) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, LoadKeyPair_TrailingGibberish) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, LoadKeyPair_KeyNotBase64) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, StoreAndLoadKeyPair) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, CreateKeyPair) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, PromoteTemporaryKeyPair) { … }
TEST_F(LinuxKeyPersistenceDelegateTest, DeleteKeyPair) { … }
}