2016-02-11 16:39:42 +01:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <cpp-utils/tempfile/TempDir.h>
|
|
|
|
#include <cpp-utils/tempfile/TempFile.h>
|
|
|
|
#include <cpp-utils/pointer/cast.h>
|
|
|
|
#include <blockstore/implementations/ondisk/OnDiskBlockStore.h>
|
|
|
|
#include <cryfs/filesystem/CryDevice.h>
|
|
|
|
#include <cryfs/filesystem/CryDir.h>
|
|
|
|
#include <cryfs/filesystem/CryFile.h>
|
|
|
|
#include <cryfs/filesystem/CryOpenFile.h>
|
2015-10-22 18:48:04 +02:00
|
|
|
#include "../testutils/MockConsole.h"
|
2016-02-11 16:39:42 +01:00
|
|
|
#include <cryfs/config/CryConfigLoader.h>
|
2016-06-22 02:36:29 +02:00
|
|
|
#include <cpp-utils/system/homedir.h>
|
|
|
|
#include "../testutils/TestWithFakeHomeDirectory.h"
|
2015-04-27 16:38:09 +02:00
|
|
|
|
|
|
|
//TODO (whole project) Make constructors explicit when implicit construction not needed
|
|
|
|
|
|
|
|
using ::testing::Test;
|
2015-10-22 18:48:04 +02:00
|
|
|
using ::testing::Return;
|
|
|
|
using ::testing::_;
|
2015-04-27 16:38:09 +02:00
|
|
|
using cpputils::TempDir;
|
|
|
|
using cpputils::TempFile;
|
|
|
|
using cpputils::dynamic_pointer_move;
|
2015-07-21 18:22:03 +02:00
|
|
|
using cpputils::make_unique_ref;
|
2015-07-26 13:09:55 +02:00
|
|
|
using cpputils::unique_ref;
|
2015-09-12 20:16:13 +02:00
|
|
|
using cpputils::Console;
|
2015-10-24 19:35:37 +02:00
|
|
|
using cpputils::Random;
|
2015-11-04 05:27:00 +01:00
|
|
|
using cpputils::SCrypt;
|
2015-11-11 20:22:46 +01:00
|
|
|
using cpputils::Data;
|
2016-06-22 02:36:29 +02:00
|
|
|
using cpputils::system::FakeHomeDirectoryRAII;
|
2015-04-27 16:38:09 +02:00
|
|
|
using blockstore::ondisk::OnDiskBlockStore;
|
2015-10-30 19:53:15 +01:00
|
|
|
using boost::none;
|
2015-04-27 16:38:09 +02:00
|
|
|
|
|
|
|
namespace bf = boost::filesystem;
|
|
|
|
using namespace cryfs;
|
|
|
|
|
2016-06-22 02:36:29 +02:00
|
|
|
class CryFsTest: public Test, public TestWithMockConsole, public TestWithFakeHomeDirectory {
|
2015-04-27 16:38:09 +02:00
|
|
|
public:
|
2015-10-22 18:48:04 +02:00
|
|
|
CryFsTest(): rootdir(), config(false) {
|
|
|
|
}
|
2015-10-23 12:16:23 +02:00
|
|
|
|
|
|
|
CryConfigFile loadOrCreateConfig() {
|
2015-11-19 10:08:09 +01:00
|
|
|
auto askPassword = [] {return "mypassword";};
|
2016-03-04 23:12:41 +01:00
|
|
|
return CryConfigLoader(mockConsole(), Random::PseudoRandom(), SCrypt::TestSettings, askPassword, askPassword, none, none, true).loadOrCreate(config.path()).value();
|
2015-10-23 12:16:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unique_ref<OnDiskBlockStore> blockStore() {
|
|
|
|
return make_unique_ref<OnDiskBlockStore>(rootdir.path());
|
2015-10-22 18:48:04 +02:00
|
|
|
}
|
2015-10-23 12:16:23 +02:00
|
|
|
|
2015-04-27 16:38:09 +02:00
|
|
|
TempDir rootdir;
|
|
|
|
TempFile config;
|
|
|
|
};
|
|
|
|
|
2015-10-23 12:16:23 +02:00
|
|
|
TEST_F(CryFsTest, CreatedRootdirIsLoadableAfterClosing) {
|
2015-06-17 12:28:18 +02:00
|
|
|
{
|
2015-10-23 12:16:23 +02:00
|
|
|
CryDevice dev(loadOrCreateConfig(), blockStore());
|
2015-06-17 12:28:18 +02:00
|
|
|
}
|
2015-10-23 12:16:23 +02:00
|
|
|
CryDevice dev(loadOrCreateConfig(), blockStore());
|
2015-04-27 18:00:11 +02:00
|
|
|
auto root = dev.Load(bf::path("/"));
|
2015-06-18 19:36:05 +02:00
|
|
|
dynamic_pointer_move<CryDir>(root.get()).get()->children();
|
2015-04-27 16:38:09 +02:00
|
|
|
}
|
2015-11-11 20:22:46 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|