Fix test cases
This commit is contained in:
parent
aed30a0ec1
commit
09f89327da
@ -27,6 +27,11 @@ void CryConfigLoader::_initializeConfig(CryConfig *config) {
|
||||
_generateRootBlobKey(config);
|
||||
}
|
||||
|
||||
void CryConfigLoader::_initializeConfigWithWeakKey(CryConfig *config) {
|
||||
_generateWeakEncKey(config);
|
||||
_generateRootBlobKey(config);
|
||||
}
|
||||
|
||||
void CryConfigLoader::_generateEncKey(CryConfig *config) {
|
||||
printf("Generating secure encryption key...");
|
||||
fflush(stdout);
|
||||
@ -36,6 +41,11 @@ void CryConfigLoader::_generateEncKey(CryConfig *config) {
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void CryConfigLoader::_generateWeakEncKey(CryConfig *config) {
|
||||
auto new_key = Cipher::EncryptionKey::CreatePseudoRandom();
|
||||
config->SetEncryptionKey(new_key.ToString());
|
||||
}
|
||||
|
||||
void CryConfigLoader::_generateRootBlobKey(CryConfig *config) {
|
||||
//An empty root blob entry will tell CryDevice to create a new root blob
|
||||
config->SetRootBlob("");
|
||||
@ -48,4 +58,19 @@ unique_ptr<CryConfig> CryConfigLoader::loadExisting(const bf::path &filename) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
unique_ptr<CryConfig> CryConfigLoader::loadOrCreateWithWeakKey(const bf::path &filename) {
|
||||
auto config = loadExisting(filename);
|
||||
if (config.get() != nullptr) {
|
||||
return config;
|
||||
}
|
||||
return createNewWithWeakKey(filename);
|
||||
}
|
||||
|
||||
unique_ptr<CryConfig> CryConfigLoader::createNewWithWeakKey(const bf::path &filename) {
|
||||
auto config = make_unique<CryConfig>(filename);
|
||||
_initializeConfigWithWeakKey(config.get());
|
||||
config->save();
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,10 +18,17 @@ public:
|
||||
static std::unique_ptr<CryConfig> createNew(const boost::filesystem::path &filename);
|
||||
static std::unique_ptr<CryConfig> loadExisting(const boost::filesystem::path &filename);
|
||||
|
||||
//This method is only for testing purposes, because creating weak keys is much faster than creating strong keys.
|
||||
static std::unique_ptr<CryConfig> loadOrCreateWithWeakKey(const boost::filesystem::path &filename);
|
||||
static std::unique_ptr<CryConfig> createNewWithWeakKey(const boost::filesystem::path &filename);
|
||||
|
||||
private:
|
||||
static void _initializeConfig(CryConfig *config);
|
||||
static void _generateEncKey(CryConfig *config);
|
||||
static void _generateRootBlobKey(CryConfig *config);
|
||||
|
||||
static void _initializeConfigWithWeakKey(CryConfig *config);
|
||||
static void _generateWeakEncKey(CryConfig *config);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -29,9 +29,27 @@ public:
|
||||
|
||||
TEST_F(CryFsTest, CreatedRootdirIsLoadableAfterClosing) {
|
||||
{
|
||||
CryDevice dev(make_unique<CryConfig>(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
|
||||
CryDevice dev(CryConfigLoader::createNewWithWeakKey(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
|
||||
}
|
||||
CryDevice dev(make_unique<CryConfig>(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
|
||||
CryDevice dev(CryConfigLoader::loadExisting(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
|
||||
auto root = dev.Load(bf::path("/"));
|
||||
dynamic_pointer_move<CryDir>(root)->children();
|
||||
}
|
||||
|
||||
TEST_F(CryFsTest, UsingStrongKey1_CreatedRootdirIsLoadableAfterClosing) {
|
||||
{
|
||||
CryDevice dev(CryConfigLoader::createNew(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
|
||||
}
|
||||
CryDevice dev(CryConfigLoader::loadExisting(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
|
||||
auto root = dev.Load(bf::path("/"));
|
||||
dynamic_pointer_move<CryDir>(root)->children();
|
||||
}
|
||||
|
||||
TEST_F(CryFsTest, UsingStrongKey2_CreatedRootdirIsLoadableAfterClosing) {
|
||||
{
|
||||
CryDevice dev(CryConfigLoader::loadOrCreate(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
|
||||
}
|
||||
CryDevice dev(CryConfigLoader::loadOrCreate(config.path()), make_unique<OnDiskBlockStore>(rootdir.path()));
|
||||
auto root = dev.Load(bf::path("/"));
|
||||
dynamic_pointer_move<CryDir>(root)->children();
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
|
||||
unique_ptr<Device> createDevice() override {
|
||||
auto blockStore = make_unique<FakeBlockStore>();
|
||||
auto config = make_unique<CryConfig>(configFile.path());
|
||||
auto config = CryConfigLoader::loadOrCreateWithWeakKey(configFile.path());
|
||||
return make_unique<CryDevice>(std::move(config), std::move(blockStore));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user