2015-04-27 16:38:09 +02:00
|
|
|
#include <google/gtest/gtest.h>
|
|
|
|
#include <messmer/cpp-utils/tempfile/TempDir.h>
|
|
|
|
#include <messmer/cpp-utils/tempfile/TempFile.h>
|
2015-06-21 17:44:45 +02:00
|
|
|
#include <messmer/cpp-utils/pointer/cast.h>
|
2015-04-27 16:38:09 +02:00
|
|
|
#include <messmer/blockstore/implementations/ondisk/OnDiskBlockStore.h>
|
2015-09-12 20:16:13 +02:00
|
|
|
#include "../../src/filesystem/CryDevice.h"
|
|
|
|
#include "../../src/filesystem/CryDir.h"
|
|
|
|
#include "../../src/filesystem/CryFile.h"
|
|
|
|
#include "../../src/filesystem/CryOpenFile.h"
|
2015-04-27 16:38:09 +02:00
|
|
|
|
|
|
|
//TODO (whole project) Make constructors explicit when implicit construction not needed
|
|
|
|
|
|
|
|
using ::testing::Test;
|
|
|
|
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-04-27 16:38:09 +02:00
|
|
|
using blockstore::ondisk::OnDiskBlockStore;
|
|
|
|
|
|
|
|
namespace bf = boost::filesystem;
|
|
|
|
using namespace cryfs;
|
|
|
|
|
2015-07-26 13:09:55 +02:00
|
|
|
class MockConsole: public Console {
|
|
|
|
void print(const std::string &) override {}
|
|
|
|
unsigned int ask(const std::string &, const std::vector<std::string> &) override {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-09-04 16:00:41 +02:00
|
|
|
bool askYesNo(const std::string &) override {
|
|
|
|
return true;
|
|
|
|
}
|
2015-07-26 13:09:55 +02:00
|
|
|
};
|
|
|
|
|
2015-04-27 16:38:09 +02:00
|
|
|
class CryFsTest: public Test {
|
|
|
|
public:
|
|
|
|
CryFsTest(): rootdir(), config(false) {}
|
|
|
|
TempDir rootdir;
|
|
|
|
TempFile config;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(CryFsTest, CreatedRootdirIsLoadableAfterClosing) {
|
|
|
|
{
|
2015-07-26 13:09:55 +02:00
|
|
|
CryDevice dev(CryConfigLoader().createNewWithWeakKey(config.path()), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
|
2015-04-27 16:38:09 +02:00
|
|
|
}
|
2015-07-26 13:09:55 +02:00
|
|
|
CryDevice dev(CryConfigLoader().loadExisting(config.path()).value(), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
|
2015-06-17 12:28:18 +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-06-17 12:28:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CryFsTest, UsingStrongKey1_CreatedRootdirIsLoadableAfterClosing) {
|
|
|
|
{
|
2015-07-26 13:09:55 +02:00
|
|
|
CryDevice dev(CryConfigLoader(make_unique_ref<MockConsole>()).createNew(config.path()), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
|
2015-06-17 12:28:18 +02:00
|
|
|
}
|
2015-07-26 13:09:55 +02:00
|
|
|
CryDevice dev(CryConfigLoader().loadExisting(config.path()).value(), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
|
2015-06-17 12:28:18 +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-06-17 12:28:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CryFsTest, UsingStrongKey2_CreatedRootdirIsLoadableAfterClosing) {
|
|
|
|
{
|
2015-07-26 13:09:55 +02:00
|
|
|
CryDevice dev(CryConfigLoader(make_unique_ref<MockConsole>()).loadOrCreate(config.path()), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
|
2015-06-17 12:28:18 +02:00
|
|
|
}
|
2015-07-26 13:09:55 +02:00
|
|
|
CryDevice dev(CryConfigLoader().loadOrCreate(config.path()), make_unique_ref<OnDiskBlockStore>(rootdir.path()));
|
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
|
|
|
}
|