Added test cases
This commit is contained in:
parent
09f6b48710
commit
30ae2fc45c
@ -41,7 +41,6 @@ optional<CryConfigFile> CryConfigFile::load(const bf::path &path, const string &
|
|||||||
}
|
}
|
||||||
CryConfig config = CryConfig::load(decrypted->data);
|
CryConfig config = CryConfig::load(decrypted->data);
|
||||||
if (config.Cipher() != decrypted->cipherName) {
|
if (config.Cipher() != decrypted->cipherName) {
|
||||||
//TODO Test that this fails
|
|
||||||
LOG(ERROR) << "Inner cipher algorithm used to encrypt config file doesn't match config value";
|
LOG(ERROR) << "Inner cipher algorithm used to encrypt config file doesn't match config value";
|
||||||
return none;
|
return none;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ optional<CryConfigFile> CryConfigLoader::_loadConfig(const bf::path &filename) {
|
|||||||
return none;
|
return none;
|
||||||
}
|
}
|
||||||
if (_cipher != none && config->config()->Cipher() != *_cipher) {
|
if (_cipher != none && config->config()->Cipher() != *_cipher) {
|
||||||
//TODO Test this fails
|
|
||||||
throw std::runtime_error("Filesystem uses "+config->config()->Cipher()+" cipher and not "+*_cipher+" as specified.");
|
throw std::runtime_error("Filesystem uses "+config->config()->Cipher()+" cipher and not "+*_cipher+" as specified.");
|
||||||
}
|
}
|
||||||
return std::move(*config);
|
return std::move(*config);
|
||||||
|
@ -10,6 +10,7 @@ using std::string;
|
|||||||
using boost::optional;
|
using boost::optional;
|
||||||
using boost::none;
|
using boost::none;
|
||||||
using cpputils::SCrypt;
|
using cpputils::SCrypt;
|
||||||
|
using cpputils::Data;
|
||||||
namespace bf = boost::filesystem;
|
namespace bf = boost::filesystem;
|
||||||
|
|
||||||
//gtest/boost::optional workaround for working with optional<CryConfigFile>
|
//gtest/boost::optional workaround for working with optional<CryConfigFile>
|
||||||
@ -146,3 +147,13 @@ TEST_F(CryConfigFileTest, CanSaveAndLoadModififedCipher) {
|
|||||||
CryConfigFile loaded = Load().value();
|
CryConfigFile loaded = Load().value();
|
||||||
EXPECT_EQ("twofish-128-cfb", loaded.config()->Cipher());
|
EXPECT_EQ("twofish-128-cfb", loaded.config()->Cipher());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(CryConfigFileTest, FailsIfConfigFileIsEncryptedWithACipherDifferentToTheOneSpecifiedByTheUser) {
|
||||||
|
auto encryptor = CryConfigEncryptorFactory::deriveKey("mypassword", SCrypt::TestSettings);
|
||||||
|
auto config = Config();
|
||||||
|
config.SetCipher("aes-256-gcm");
|
||||||
|
Data encrypted = encryptor->encrypt(config.save(), "aes-256-cfb");
|
||||||
|
encrypted.StoreToFile(file.path());
|
||||||
|
auto loaded = Load("mypassword");
|
||||||
|
EXPECT_EQ(none, loaded);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user