2017-07-18 23:49:51 +02:00
|
|
|
#include <blockstore/implementations/inmemory/InMemoryBlockStore2.h>
|
2016-02-11 16:39:42 +01:00
|
|
|
#include <fspp/fstest/FsTest.h>
|
|
|
|
#include <cpp-utils/tempfile/TempFile.h>
|
2016-09-25 02:50:28 +02:00
|
|
|
#include <cpp-utils/io/NoninteractiveConsole.h>
|
2019-01-26 08:38:34 +01:00
|
|
|
#include <cryfs/impl/filesystem/CryDevice.h>
|
|
|
|
#include <cryfs/impl/config/CryConfigLoader.h>
|
|
|
|
#include <cryfs/impl/config/CryPresetPasswordBasedKeyProvider.h>
|
2015-10-22 18:48:04 +02:00
|
|
|
#include "../testutils/MockConsole.h"
|
2016-06-22 02:36:29 +02:00
|
|
|
#include "../testutils/TestWithFakeHomeDirectory.h"
|
2015-03-16 02:15:51 +01:00
|
|
|
|
2015-06-18 19:36:05 +02:00
|
|
|
using cpputils::unique_ref;
|
|
|
|
using cpputils::make_unique_ref;
|
2015-10-24 19:35:37 +02:00
|
|
|
using cpputils::Random;
|
2015-11-04 05:27:00 +01:00
|
|
|
using cpputils::SCrypt;
|
2016-09-25 02:50:28 +02:00
|
|
|
using cpputils::NoninteractiveConsole;
|
2015-03-16 02:15:51 +01:00
|
|
|
using fspp::Device;
|
2015-10-30 19:53:15 +01:00
|
|
|
using boost::none;
|
2016-09-25 02:50:28 +02:00
|
|
|
using std::make_shared;
|
2017-07-18 23:49:51 +02:00
|
|
|
using blockstore::inmemory::InMemoryBlockStore2;
|
2018-10-28 02:18:32 +01:00
|
|
|
using cryfs::CryPresetPasswordBasedKeyProvider;
|
2015-03-16 02:15:51 +01:00
|
|
|
|
|
|
|
using namespace cryfs;
|
|
|
|
|
2018-12-11 06:20:18 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
auto failOnIntegrityViolation() {
|
|
|
|
return [] {
|
|
|
|
EXPECT_TRUE(false);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-06-22 02:36:29 +02:00
|
|
|
class CryFsTestFixture: public FileSystemTestFixture, public TestWithMockConsole, public TestWithFakeHomeDirectory {
|
2015-03-16 02:15:51 +01:00
|
|
|
public:
|
|
|
|
CryFsTestFixture()
|
|
|
|
// Don't create config tempfile yet
|
2018-04-22 07:04:21 +02:00
|
|
|
: tempLocalStateDir(), localStateDir(tempLocalStateDir.path()), configFile(false) {}
|
2015-03-16 02:15:51 +01:00
|
|
|
|
2015-06-18 19:36:05 +02:00
|
|
|
unique_ref<Device> createDevice() override {
|
2017-07-18 23:49:51 +02:00
|
|
|
auto blockStore = cpputils::make_unique_ref<InMemoryBlockStore2>();
|
2018-10-22 04:31:08 +02:00
|
|
|
auto _console = make_shared<NoninteractiveConsole>(mockConsole());
|
2018-10-28 02:18:32 +01:00
|
|
|
auto keyProvider = make_unique_ref<CryPresetPasswordBasedKeyProvider>("mypassword", make_unique_ref<SCrypt>(SCrypt::TestSettings));
|
2018-10-22 04:31:08 +02:00
|
|
|
auto config = CryConfigLoader(_console, Random::PseudoRandom(), std::move(keyProvider), localStateDir, none, none, none)
|
2018-02-08 08:08:01 +01:00
|
|
|
.loadOrCreate(configFile.path(), false, false).value();
|
2018-12-11 06:20:18 +01:00
|
|
|
return make_unique_ref<CryDevice>(std::move(config.configFile), std::move(blockStore), localStateDir, config.myClientId, false, false, failOnIntegrityViolation());
|
2015-03-16 02:15:51 +01:00
|
|
|
}
|
|
|
|
|
2018-04-22 07:04:21 +02:00
|
|
|
cpputils::TempDir tempLocalStateDir;
|
|
|
|
LocalStateDir localStateDir;
|
2015-04-25 03:37:25 +02:00
|
|
|
cpputils::TempFile configFile;
|
2015-03-16 02:15:51 +01:00
|
|
|
};
|
|
|
|
|
2015-03-16 02:57:01 +01:00
|
|
|
FSPP_ADD_FILESYTEM_TESTS(CryFS, CryFsTestFixture);
|
2018-12-11 06:20:18 +01:00
|
|
|
}
|