xref: /openbmc/estoraged/src/test/include/estoraged_test.hpp (revision 1d6665fcfa2addddfd1f05f6d53d93a35c1d1b97)
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     MOCK_METHOD(int, runFsck,
43                 (const std::string& logicalVolumePath,
44                  const std::string& options),
45                 (override));
46 };
47 
48 class MockCryptsetupInterface : public estoraged::CryptsetupInterface
49 {
50   public:
51     MOCK_METHOD(int, cryptFormat,
52                 (struct crypt_device * cd, const char* type, const char* cipher,
53                  const char* cipherMode, const char* uuid,
54                  const char* volumeKey, size_t volumeKeySize, void* params),
55                 (override));
56 
57     MOCK_METHOD(int, cryptKeyslotAddByVolumeKey,
58                 (struct crypt_device * cd, int keyslot, const char* volumeKey,
59                  size_t volumeKeySize, const char* passphrase,
60                  size_t passphraseSize),
61                 (override));
62 
63     MOCK_METHOD(int, cryptLoad,
64                 (struct crypt_device * cd, const char* requestedType,
65                  void* params),
66                 (override));
67 
68     MOCK_METHOD(int, cryptKeyslotChangeByPassphrase,
69                 (struct crypt_device * cd, int keyslotOld, int keyslotNew,
70                  const char* passphrase, size_t passphraseSize,
71                  const char* newPassphrase, size_t newPassphraseSize),
72                 (override));
73 
74     MOCK_METHOD(int, cryptActivateByPassphrase,
75                 (struct crypt_device * cd, const char* name, int keyslot,
76                  const char* passphrase, size_t passphraseSize, uint32_t flags),
77                 (override));
78 
79     MOCK_METHOD(int, cryptDeactivate,
80                 (struct crypt_device * cd, const char* name), (override));
81 
82     MOCK_METHOD(int, cryptKeyslotDestroy,
83                 (struct crypt_device * cd, const int slot), (override));
84 
85     MOCK_METHOD(int, cryptKeySlotMax, (const char* type), (override));
86 
87     MOCK_METHOD(crypt_keyslot_info, cryptKeySlotStatus,
88                 (struct crypt_device * cd, int keyslot), (override));
89 
90     MOCK_METHOD(std::string, cryptGetDir, (), (override));
91 };
92 
93 } // namespace estoraged_test
94