Added test case for CryConfigFile
This commit is contained in:
parent
c936fca16a
commit
39c62ae185
@ -14,7 +14,13 @@ CryConfigFile CryConfigFile::create(const bf::path &path, CryConfig config) {
|
||||
if (bf::exists(path)) {
|
||||
throw std::runtime_error("Config file exists already.");
|
||||
}
|
||||
return CryConfigFile(path, std::move(config));
|
||||
auto result = CryConfigFile(path, std::move(config));
|
||||
result.save();
|
||||
return result;
|
||||
}
|
||||
|
||||
CryConfigFile::~CryConfigFile() {
|
||||
//We do not call save() here, because we do not want the config file to be re-encrypted on each filesystem run
|
||||
}
|
||||
|
||||
optional<CryConfigFile> CryConfigFile::load(const bf::path &path) {
|
||||
|
@ -9,6 +9,7 @@ namespace cryfs {
|
||||
class CryConfigFile final {
|
||||
public:
|
||||
CryConfigFile(CryConfigFile &&rhs);
|
||||
~CryConfigFile();
|
||||
|
||||
static CryConfigFile create(const boost::filesystem::path &path, CryConfig config);
|
||||
static boost::optional<CryConfigFile> load(const boost::filesystem::path &path);
|
||||
|
90
test/config/CryConfigFileTest.cpp
Normal file
90
test/config/CryConfigFileTest.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
#include <google/gtest/gtest.h>
|
||||
|
||||
#include "../../src/config/CryConfigFile.h"
|
||||
#include <messmer/cpp-utils/tempfile/TempFile.h>
|
||||
|
||||
using namespace cryfs;
|
||||
using cpputils::TempFile;
|
||||
|
||||
class CryConfigFileTest: public ::testing::Test {
|
||||
public:
|
||||
CryConfigFileTest(): file(false) {}
|
||||
|
||||
TempFile file;
|
||||
|
||||
CryConfigFile CreateAndLoadEmpty() {
|
||||
Create(CryConfig());
|
||||
return Load();
|
||||
}
|
||||
|
||||
void Create(CryConfig cfg) {
|
||||
CryConfigFile::create(file.path(), std::move(cfg));
|
||||
}
|
||||
|
||||
CryConfigFile Load() {
|
||||
return CryConfigFile::load(file.path()).value();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(CryConfigFileTest, RootBlob_Init) {
|
||||
CryConfigFile created = CreateAndLoadEmpty();
|
||||
EXPECT_EQ("", created.config()->RootBlob());
|
||||
}
|
||||
|
||||
TEST_F(CryConfigFileTest, RootBlob_CreateAndLoad) {
|
||||
CryConfig cfg;
|
||||
cfg.SetRootBlob("rootblobid");
|
||||
Create(std::move(cfg));
|
||||
CryConfigFile loaded = Load();
|
||||
EXPECT_EQ("rootblobid", loaded.config()->RootBlob());
|
||||
}
|
||||
|
||||
TEST_F(CryConfigFileTest, RootBlob_SaveAndLoad) {
|
||||
CryConfigFile created = CreateAndLoadEmpty();
|
||||
created.config()->SetRootBlob("rootblobid");
|
||||
created.save();
|
||||
CryConfigFile loaded = Load();
|
||||
EXPECT_EQ("rootblobid", loaded.config()->RootBlob());
|
||||
}
|
||||
|
||||
TEST_F(CryConfigFileTest, EncryptionKey_Init) {
|
||||
CryConfigFile created = CreateAndLoadEmpty();
|
||||
EXPECT_EQ("", created.config()->EncryptionKey());
|
||||
}
|
||||
|
||||
TEST_F(CryConfigFileTest, EncryptionKey_CreateAndLoad) {
|
||||
CryConfig cfg;
|
||||
cfg.SetEncryptionKey("encryptionkey");
|
||||
Create(std::move(cfg));
|
||||
CryConfigFile loaded = Load();
|
||||
EXPECT_EQ("encryptionkey", loaded.config()->EncryptionKey());
|
||||
}
|
||||
|
||||
TEST_F(CryConfigFileTest, EncryptionKey_SaveAndLoad) {
|
||||
CryConfigFile created = CreateAndLoadEmpty();
|
||||
created.config()->SetEncryptionKey("encryptionkey");
|
||||
created.save();
|
||||
CryConfigFile loaded = Load();
|
||||
EXPECT_EQ("encryptionkey", loaded.config()->EncryptionKey());
|
||||
}
|
||||
|
||||
TEST_F(CryConfigFileTest, Cipher_Init) {
|
||||
CryConfigFile created = CreateAndLoadEmpty();
|
||||
EXPECT_EQ("", created.config()->Cipher());
|
||||
}
|
||||
|
||||
TEST_F(CryConfigFileTest, Cipher_CreateAndLoad) {
|
||||
CryConfig cfg;
|
||||
cfg.SetCipher("cipher");
|
||||
Create(std::move(cfg));
|
||||
CryConfigFile loaded = Load();
|
||||
EXPECT_EQ("cipher", loaded.config()->Cipher());
|
||||
}
|
||||
|
||||
TEST_F(CryConfigFileTest, Cipher_SaveAndLoad) {
|
||||
CryConfigFile created = CreateAndLoadEmpty();
|
||||
created.config()->SetCipher("cipher");
|
||||
created.save();
|
||||
CryConfigFile loaded = Load();
|
||||
EXPECT_EQ("cipher", loaded.config()->Cipher());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user