xref: /openbmc/estoraged/src/test/include/estoraged_test.hpp (revision c0f85486f0f8733ae0239e006ed14222640a13c7)
1 
2 #include "cryptErase.hpp"
3 #include "cryptsetupInterface.hpp"
4 #include "estoraged.hpp"
5 #include "filesystemInterface.hpp"
6 
7 #include <unistd.h>
8 
9 #include <exception>
10 #include <filesystem>
11 #include <string>
12 
13 #include <gmock/gmock.h>
14 #include <gtest/gtest.h>
15 
16 namespace estoraged_test
17 {
18 
19 class MockFilesystemInterface : public estoraged::FilesystemInterface
20 {
21   public:
22     MOCK_METHOD(int, runMkfs, (const std::string& logicalVolumePath),
23                 (override));
24 
25     MOCK_METHOD(int, doMount,
26                 (const char* source, const char* target,
27                  const char* filesystemtype, unsigned long mountflags,
28                  const void* data),
29                 (override));
30 
31     MOCK_METHOD(int, doUnmount, (const char* target), (override));
32 
33     MOCK_METHOD(bool, createDirectory, (const std::filesystem::path& p),
34                 (override));
35 
36     MOCK_METHOD(bool, removeDirectory, (const std::filesystem::path& p),
37                 (override));
38 
39     MOCK_METHOD(bool, directoryExists, (const std::filesystem::path& p),
40                 (override));
41 };
42 
43 class MockCryptsetupInterface : public estoraged::CryptsetupInterface
44 {
45   public:
46     MOCK_METHOD(int, cryptFormat,
47                 (struct crypt_device * cd, const char* type, const char* cipher,
48                  const char* cipherMode, const char* uuid,
49                  const char* volumeKey, size_t volumeKeySize, void* params),
50                 (override));
51 
52     MOCK_METHOD(int, cryptKeyslotAddByVolumeKey,
53                 (struct crypt_device * cd, int keyslot, const char* volumeKey,
54                  size_t volumeKeySize, const char* passphrase,
55                  size_t passphraseSize),
56                 (override));
57 
58     MOCK_METHOD(int, cryptLoad,
59                 (struct crypt_device * cd, const char* requestedType,
60                  void* params),
61                 (override));
62 
63     MOCK_METHOD(int, cryptKeyslotChangeByPassphrase,
64                 (struct crypt_device * cd, int keyslotOld, int keyslotNew,
65                  const char* passphrase, size_t passphraseSize,
66                  const char* newPassphrase, size_t newPassphraseSize),
67                 (override));
68 
69     MOCK_METHOD(int, cryptActivateByPassphrase,
70                 (struct crypt_device * cd, const char* name, int keyslot,
71                  const char* passphrase, size_t passphraseSize, uint32_t flags),
72                 (override));
73 
74     MOCK_METHOD(int, cryptDeactivate,
75                 (struct crypt_device * cd, const char* name), (override));
76 
77     MOCK_METHOD(int, cryptKeyslotDestroy,
78                 (struct crypt_device * cd, const int slot), (override));
79 
80     MOCK_METHOD(int, cryptKeySlotMax, (const char* type), (override));
81 
82     MOCK_METHOD(crypt_keyslot_info, cryptKeySlotStatus,
83                 (struct crypt_device * cd, int keyslot), (override));
84 
85     MOCK_METHOD(std::string, cryptGetDir, (), (override));
86 };
87 
88 } // namespace estoraged_test
89