Added test cases

This commit is contained in:
Sebastian Messmer 2015-11-12 10:59:38 -08:00
parent 09f6b48710
commit 30ae2fc45c
3 changed files with 11 additions and 2 deletions

View File

@ -41,7 +41,6 @@ optional<CryConfigFile> CryConfigFile::load(const bf::path &path, const string &
}
CryConfig config = CryConfig::load(decrypted->data);
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";
return none;
}

View File

@ -34,7 +34,6 @@ optional<CryConfigFile> CryConfigLoader::_loadConfig(const bf::path &filename) {
return none;
}
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.");
}
return std::move(*config);

View File

@ -10,6 +10,7 @@ using std::string;
using boost::optional;
using boost::none;
using cpputils::SCrypt;
using cpputils::Data;
namespace bf = boost::filesystem;
//gtest/boost::optional workaround for working with optional<CryConfigFile>
@ -146,3 +147,13 @@ TEST_F(CryConfigFileTest, CanSaveAndLoadModififedCipher) {
CryConfigFile loaded = Load().value();
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);
}