#include #include #include #include #include #include #include #include #include #include "../testutils/MockConsole.h" #include #include //TODO (whole project) Make constructors explicit when implicit construction not needed using ::testing::Test; using ::testing::Return; using ::testing::_; using std::make_shared; using cpputils::TempDir; using cpputils::TempFile; using cpputils::dynamic_pointer_move; using cpputils::make_unique_ref; using cpputils::unique_ref; using cpputils::Console; using cpputils::Random; using cpputils::SCrypt; using cpputils::Data; using cpputils::NoninteractiveConsole; using blockstore::ondisk::OnDiskBlockStore; using boost::none; namespace bf = boost::filesystem; using namespace cryfs; class CryFsTest: public Test, public TestWithMockConsole { public: CryFsTest(): rootdir(), config(false) { } CryConfigFile loadOrCreateConfig() { auto askPassword = [] {return "mypassword";}; return CryConfigLoader(make_shared(mockConsole()), Random::PseudoRandom(), SCrypt::TestSettings, askPassword, askPassword, none, none).loadOrCreate(config.path()).value(); } unique_ref blockStore() { return make_unique_ref(rootdir.path()); } TempDir rootdir; TempFile config; }; TEST_F(CryFsTest, CreatedRootdirIsLoadableAfterClosing) { { CryDevice dev(loadOrCreateConfig(), blockStore()); } CryDevice dev(loadOrCreateConfig(), blockStore()); auto root = dev.Load(bf::path("/")); dynamic_pointer_move(root.get()).get()->children(); } TEST_F(CryFsTest, LoadingFilesystemDoesntModifyConfigFile) { { CryDevice dev(loadOrCreateConfig(), blockStore()); } Data configAfterCreating = Data::LoadFromFile(config.path()).value(); { CryDevice dev(loadOrCreateConfig(), blockStore()); } Data configAfterLoading = Data::LoadFromFile(config.path()).value(); EXPECT_EQ(configAfterCreating, configAfterLoading); }