Fix test cases

This commit is contained in:
Sebastian Messmer 2018-02-07 23:08:01 -08:00
parent 8221e76f3a
commit 621864b50c
6 changed files with 79 additions and 79 deletions

View File

@ -22,118 +22,118 @@ namespace boost {
class ProgramOptionsTest: public ProgramOptionsTestBase {};
TEST_F(ProgramOptionsTest, BaseDir) {
ProgramOptions testobj("/home/user/mydir", "", none, false, false, none, none, none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("/home/user/mydir", "", none, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
EXPECT_EQ("/home/user/mydir", testobj.baseDir());
}
TEST_F(ProgramOptionsTest, MountDir) {
ProgramOptions testobj("", "/home/user/mydir", none, false, false, none, none, none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "/home/user/mydir", none, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
EXPECT_EQ("/home/user/mydir", testobj.mountDir());
}
TEST_F(ProgramOptionsTest, ConfigfileNone) {
ProgramOptions testobj("", "", none, true, false, none, none, none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, true, false, false, none, none, none, none, false, none, {"./myExecutable"});
EXPECT_EQ(none, testobj.configFile());
}
TEST_F(ProgramOptionsTest, ConfigfileSome) {
ProgramOptions testobj("", "", bf::path("/home/user/configfile"), true, false, none, none, none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", bf::path("/home/user/configfile"), true, false, false, none, none, none, none, false, none, {"./myExecutable"});
EXPECT_EQ("/home/user/configfile", testobj.configFile().get());
}
TEST_F(ProgramOptionsTest, ForegroundFalse) {
ProgramOptions testobj("", "", none, false, false, none, none, none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
EXPECT_FALSE(testobj.foreground());
}
TEST_F(ProgramOptionsTest, ForegroundTrue) {
ProgramOptions testobj("", "", none, true, false, none, none, none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, true, false, false, none, none, none, none, false, none, {"./myExecutable"});
EXPECT_TRUE(testobj.foreground());
}
TEST_F(ProgramOptionsTest, AllowFilesystemUpgradeFalse) {
ProgramOptions testobj("", "", none, false, false, none, none, none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
EXPECT_FALSE(testobj.allowFilesystemUpgrade());
}
TEST_F(ProgramOptionsTest, AllowFilesystemUpgradeTrue) {
ProgramOptions testobj("", "", none, false, true, none, none, none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, false, true, false, none, none, none, none, false, none, {"./myExecutable"});
EXPECT_TRUE(testobj.allowFilesystemUpgrade());
}
TEST_F(ProgramOptionsTest, LogfileNone) {
ProgramOptions testobj("", "", none, true, false, none, none, none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, true, false, false, none, none, none, none, false, none, {"./myExecutable"});
EXPECT_EQ(none, testobj.logFile());
}
TEST_F(ProgramOptionsTest, LogfileSome) {
ProgramOptions testobj("", "", none, true, false, none, bf::path("logfile"), none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, true, false, false, none, bf::path("logfile"), none, none, false, none, {"./myExecutable"});
EXPECT_EQ("logfile", testobj.logFile().get());
}
TEST_F(ProgramOptionsTest, UnmountAfterIdleMinutesNone) {
ProgramOptions testobj("", "", none, true, false, none, none, none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, true, false, false, none, none, none, none, false, none, {"./myExecutable"});
EXPECT_EQ(none, testobj.unmountAfterIdleMinutes());
}
TEST_F(ProgramOptionsTest, UnmountAfterIdleMinutesSome) {
ProgramOptions testobj("", "", none, true, false, 10, none, none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, true, false, false, 10, none, none, none, false, none, {"./myExecutable"});
EXPECT_EQ(10, testobj.unmountAfterIdleMinutes().get());
}
TEST_F(ProgramOptionsTest, CipherNone) {
ProgramOptions testobj("", "", none, true, false, none, none, none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, true, false, false, none, none, none, none, false, none, {"./myExecutable"});
EXPECT_EQ(none, testobj.cipher());
}
TEST_F(ProgramOptionsTest, CipherSome) {
ProgramOptions testobj("", "", none, true, false, none, none, string("aes-256-gcm"), none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, true, false, false, none, none, string("aes-256-gcm"), none, false, none, {"./myExecutable"});
EXPECT_EQ("aes-256-gcm", testobj.cipher().get());
}
TEST_F(ProgramOptionsTest, BlocksizeBytesNone) {
ProgramOptions testobj("", "", none, true, false, none, none, none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, true, false, false, none, none, none, none, false, none, {"./myExecutable"});
EXPECT_EQ(none, testobj.blocksizeBytes());
}
TEST_F(ProgramOptionsTest, BlocksizeBytesSome) {
ProgramOptions testobj("", "", none, true, false, none, none, none, 10*1024, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, true, false, false, none, none, none, 10*1024, false, none, {"./myExecutable"});
EXPECT_EQ(10*1024u, testobj.blocksizeBytes().get());
}
TEST_F(ProgramOptionsTest, MissingBlockIsIntegrityViolationTrue) {
ProgramOptions testobj("", "", none, true, false, none, none, none, none, false, true, {"./myExecutable"});
ProgramOptions testobj("", "", none, true, false, false, none, none, none, none, false, true, {"./myExecutable"});
EXPECT_TRUE(testobj.missingBlockIsIntegrityViolation().value());
}
TEST_F(ProgramOptionsTest, MissingBlockIsIntegrityViolationFalse) {
ProgramOptions testobj("", "", none, true, false, none, none, none, none, false, false, {"./myExecutable"});
ProgramOptions testobj("", "", none, true, false, false, none, none, none, none, false, false, {"./myExecutable"});
EXPECT_FALSE(testobj.missingBlockIsIntegrityViolation().value());
}
TEST_F(ProgramOptionsTest, MissingBlockIsIntegrityViolationNone) {
ProgramOptions testobj("", "", none, true, false, none, none, none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, true, false, false, none, none, none, none, false, none, {"./myExecutable"});
EXPECT_EQ(none, testobj.missingBlockIsIntegrityViolation());
}
TEST_F(ProgramOptionsTest, NoIntegrityChecksFalse) {
ProgramOptions testobj("", "", none, true, false, none, none, none, none, false, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, true, false, false, none, none, none, none, false, none, {"./myExecutable"});
EXPECT_FALSE(testobj.noIntegrityChecks());
}
TEST_F(ProgramOptionsTest, NoIntegrityChecksTrue) {
ProgramOptions testobj("", "", none, true, false, none, none, none, none, true, none, {"./myExecutable"});
ProgramOptions testobj("", "", none, true, false, false, none, none, none, none, true, none, {"./myExecutable"});
EXPECT_TRUE(testobj.noIntegrityChecks());
}
TEST_F(ProgramOptionsTest, EmptyFuseOptions) {
ProgramOptions testobj("/rootDir", "/home/user/mydir", none, false, false, none, none, none, none, false, none, {});
ProgramOptions testobj("/rootDir", "/home/user/mydir", none, false, false, false, none, none, none, none, false, none, {});
//Fuse should have the mount dir as first parameter
EXPECT_VECTOR_EQ({}, testobj.fuseOptions());
}
TEST_F(ProgramOptionsTest, SomeFuseOptions) {
ProgramOptions testobj("/rootDir", "/home/user/mydir", none, false, false, none, none, none, none, false, none, {"-f", "--longoption"});
ProgramOptions testobj("/rootDir", "/home/user/mydir", none, false, false, false, none, none, none, none, false, none, {"-f", "--longoption"});
//Fuse should have the mount dir as first parameter
EXPECT_VECTOR_EQ({"-f", "--longoption"}, testobj.fuseOptions());
}

View File

@ -65,88 +65,88 @@ TEST_F(CryConfigCreatorTest, DoesAskForCipherIfNotSpecified) {
AnswerNoToDefaultSettings();
IGNORE_ASK_FOR_MISSINGBLOCKISINTEGRITYVIOLATION();
EXPECT_ASK_FOR_CIPHER().WillOnce(ChooseAnyCipher());
CryConfig config = creator.create(none, none, none).config;
CryConfig config = creator.create(none, none, none, false).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskForCipherIfSpecified) {
AnswerNoToDefaultSettings();
IGNORE_ASK_FOR_MISSINGBLOCKISINTEGRITYVIOLATION();
EXPECT_DOES_NOT_ASK_FOR_CIPHER();
CryConfig config = creator.create(string("aes-256-gcm"), none, none).config;
CryConfig config = creator.create(string("aes-256-gcm"), none, none, false).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskForCipherIfUsingDefaultSettings) {
AnswerYesToDefaultSettings();
EXPECT_DOES_NOT_ASK_FOR_CIPHER();
CryConfig config = creator.create(none, none, none).config;
CryConfig config = creator.create(none, none, none, false).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskForCipherIfNoninteractive) {
EXPECT_DOES_NOT_ASK_TO_USE_DEFAULT_SETTINGS();
EXPECT_DOES_NOT_ASK_FOR_CIPHER();
CryConfig config = noninteractiveCreator.create(none, none, none).config;
CryConfig config = noninteractiveCreator.create(none, none, none, false).config;
}
TEST_F(CryConfigCreatorTest, DoesAskForBlocksizeIfNotSpecified) {
AnswerNoToDefaultSettings();
IGNORE_ASK_FOR_MISSINGBLOCKISINTEGRITYVIOLATION();
EXPECT_ASK_FOR_BLOCKSIZE().WillOnce(Return(1));
CryConfig config = creator.create(none, none, none).config;
CryConfig config = creator.create(none, none, none, false).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskForBlocksizeIfSpecified) {
AnswerNoToDefaultSettings();
IGNORE_ASK_FOR_MISSINGBLOCKISINTEGRITYVIOLATION();
EXPECT_DOES_NOT_ASK_FOR_BLOCKSIZE();
CryConfig config = creator.create(none, 10*1024u, none).config;
CryConfig config = creator.create(none, 10*1024u, none, false).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskForBlocksizeIfNoninteractive) {
EXPECT_DOES_NOT_ASK_TO_USE_DEFAULT_SETTINGS();
EXPECT_DOES_NOT_ASK_FOR_BLOCKSIZE();
CryConfig config = noninteractiveCreator.create(none, none, none).config;
CryConfig config = noninteractiveCreator.create(none, none, none, false).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskForBlocksizeIfUsingDefaultSettings) {
AnswerYesToDefaultSettings();
EXPECT_DOES_NOT_ASK_FOR_BLOCKSIZE();
CryConfig config = creator.create(none, none, none).config;
CryConfig config = creator.create(none, none, none, false).config;
}
TEST_F(CryConfigCreatorTest, DoesAskWhetherMissingBlocksAreIntegrityViolationsIfNotSpecified) {
AnswerNoToDefaultSettings();
EXPECT_ASK_FOR_MISSINGBLOCKISINTEGRITYVIOLATION().WillOnce(Return(true));
CryConfig config = creator.create(none, none, none).config;
CryConfig config = creator.create(none, none, none, false).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskWhetherMissingBlocksAreIntegrityViolationsIfSpecified_True) {
AnswerNoToDefaultSettings();
EXPECT_DOES_NOT_ASK_FOR_MISSINGBLOCKISINTEGRITYVIOLATION();
CryConfig config = creator.create(none, none, true).config;
CryConfig config = creator.create(none, none, true, false).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskWhetherMissingBlocksAreIntegrityViolationsIfSpecified_False) {
AnswerNoToDefaultSettings();
EXPECT_DOES_NOT_ASK_FOR_MISSINGBLOCKISINTEGRITYVIOLATION();
CryConfig config = creator.create(none, none, false).config;
CryConfig config = creator.create(none, none, false, false).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskWhetherMissingBlocksAreIntegrityViolationsIfNoninteractive) {
EXPECT_DOES_NOT_ASK_TO_USE_DEFAULT_SETTINGS();
EXPECT_DOES_NOT_ASK_FOR_MISSINGBLOCKISINTEGRITYVIOLATION();
CryConfig config = noninteractiveCreator.create(none, none, none).config;
CryConfig config = noninteractiveCreator.create(none, none, none, false).config;
}
TEST_F(CryConfigCreatorTest, DoesNotAskWhetherMissingBlocksAreIntegrityViolationsIfUsingDefaultSettings) {
AnswerYesToDefaultSettings();
EXPECT_DOES_NOT_ASK_FOR_MISSINGBLOCKISINTEGRITYVIOLATION();
CryConfig config = creator.create(none, none, none).config;
CryConfig config = creator.create(none, none, none, false).config;
}
TEST_F(CryConfigCreatorTest, ChoosesEmptyRootBlobId) {
AnswerNoToDefaultSettings();
IGNORE_ASK_FOR_MISSINGBLOCKISINTEGRITYVIOLATION();
CryConfig config = creator.create(none, none, none).config;
CryConfig config = creator.create(none, none, none, false).config;
EXPECT_EQ("", config.RootBlob()); // This tells CryFS to create a new root blob
}
@ -155,7 +155,7 @@ TEST_F(CryConfigCreatorTest, ChoosesValidEncryptionKey_448) {
AnswerNoToDefaultSettings();
IGNORE_ASK_FOR_MISSINGBLOCKISINTEGRITYVIOLATION();
EXPECT_ASK_FOR_CIPHER().WillOnce(ChooseCipher("mars-448-gcm"));
CryConfig config = creator.create(none, none, none).config;
CryConfig config = creator.create(none, none, none, false).config;
cpputils::Mars448_GCM::EncryptionKey::FromString(config.EncryptionKey()); // This crashes if invalid
}
#endif
@ -164,7 +164,7 @@ TEST_F(CryConfigCreatorTest, ChoosesValidEncryptionKey_256) {
AnswerNoToDefaultSettings();
IGNORE_ASK_FOR_MISSINGBLOCKISINTEGRITYVIOLATION();
EXPECT_ASK_FOR_CIPHER().WillOnce(ChooseCipher("aes-256-gcm"));
CryConfig config = creator.create(none, none, none).config;
CryConfig config = creator.create(none, none, none, false).config;
cpputils::AES256_GCM::EncryptionKey::FromString(config.EncryptionKey()); // This crashes if invalid
}
@ -172,28 +172,28 @@ TEST_F(CryConfigCreatorTest, ChoosesValidEncryptionKey_128) {
AnswerNoToDefaultSettings();
IGNORE_ASK_FOR_MISSINGBLOCKISINTEGRITYVIOLATION();
EXPECT_ASK_FOR_CIPHER().WillOnce(ChooseCipher("aes-128-gcm"));
CryConfig config = creator.create(none, none, none).config;
CryConfig config = creator.create(none, none, none, false).config;
cpputils::AES128_GCM::EncryptionKey::FromString(config.EncryptionKey()); // This crashes if invalid
}
TEST_F(CryConfigCreatorTest, DoesNotAskForAnythingIfEverythingIsSpecified) {
EXPECT_DOES_NOT_ASK_TO_USE_DEFAULT_SETTINGS();
EXPECT_DOES_NOT_ASK_FOR_CIPHER();
CryConfig config = noninteractiveCreator.create(string("aes-256-gcm"), 10*1024u, none).config;
CryConfig config = noninteractiveCreator.create(string("aes-256-gcm"), 10*1024u, none, false).config;
}
TEST_F(CryConfigCreatorTest, SetsCorrectCreatedWithVersion) {
CryConfig config = noninteractiveCreator.create(none, none, none).config;
CryConfig config = noninteractiveCreator.create(none, none, none, false).config;
EXPECT_EQ(gitversion::VersionString(), config.CreatedWithVersion());
}
TEST_F(CryConfigCreatorTest, SetsCorrectLastOpenedWithVersion) {
CryConfig config = noninteractiveCreator.create(none, none);
CryConfig config = noninteractiveCreator.create(none, none, none, false).config;
EXPECT_EQ(gitversion::VersionString(), config.CreatedWithVersion());
}
TEST_F(CryConfigCreatorTest, SetsCorrectVersion) {
CryConfig config = noninteractiveCreator.create(none, none, none).config;
CryConfig config = noninteractiveCreator.create(none, none, none, false).config;
EXPECT_EQ(CryConfig::FilesystemFormatVersion, config.Version());
}

View File

@ -73,12 +73,12 @@ public:
CryConfigFile Create(const string &password = "mypassword", const optional<string> &cipher = none, bool noninteractive = false) {
EXPECT_FALSE(file.exists());
return loader(password, noninteractive, cipher).loadOrCreate(file.path(), false).value().configFile;
return loader(password, noninteractive, cipher).loadOrCreate(file.path(), false, false).value().configFile;
}
optional<CryConfigFile> Load(const string &password = "mypassword", const optional<string> &cipher = none, bool noninteractive = false, bool allowFilesystemUpgrade = false) {
EXPECT_TRUE(file.exists());
auto loadResult = loader(password, noninteractive, cipher).loadOrCreate(file.path(), allowFilesystemUpgrade);
auto loadResult = loader(password, noninteractive, cipher).loadOrCreate(file.path(), allowFilesystemUpgrade, false);
if (loadResult == none) {
return none;
}
@ -86,13 +86,13 @@ public:
}
void CreateWithRootBlob(const string &rootBlob, const string &password = "mypassword") {
auto cfg = loader(password, false).loadOrCreate(file.path(), false).value().configFile;
auto cfg = loader(password, false).loadOrCreate(file.path(), false, false).value().configFile;
cfg.config()->SetRootBlob(rootBlob);
cfg.save();
}
void CreateWithCipher(const string &cipher, const string &password = "mypassword") {
auto cfg = loader(password, false).loadOrCreate(file.path(), false).value().configFile;
auto cfg = loader(password, false).loadOrCreate(file.path(), false, false).value().configFile;
cfg.config()->SetCipher(cipher);
cfg.save();
}
@ -102,7 +102,7 @@ public:
FakeRandomGenerator generator(Data::FromString(encKey));
auto loader = CryConfigLoader(console, generator, SCrypt::TestSettings, askPassword,
askPassword, none, none, none);
ASSERT_NE(boost::none, loader.loadOrCreate(file.path(), false));
ASSERT_NE(boost::none, loader.loadOrCreate(file.path(), false, false));
}
void ChangeEncryptionKey(const string &encKey, const string& password = "mypassword") {
@ -111,16 +111,16 @@ public:
cfg.save();
}
void CreateWithVersion(const string &version, const string &password = "mypassword") {
auto cfg = loader(password, false).loadOrCreate(file.path(), false).value().configFile;
cfg.config()->SetVersion(version);
void CreateWithVersion(const string &version, const string& formatVersion, const string &password = "mypassword") {
auto cfg = loader(password, false).loadOrCreate(file.path(), false, false).value().configFile;
cfg.config()->SetVersion(formatVersion);
cfg.config()->SetLastOpenedWithVersion(version);
cfg.config()->SetCreatedWithVersion(version);
cfg.save();
}
void CreateWithFilesystemID(const CryConfig::FilesystemID &filesystemId, const string &password = "mypassword") {
auto cfg = loader(password, false).loadOrCreate(file.path(), false).value().configFile;
auto cfg = loader(password, false).loadOrCreate(file.path(), false, false).value().configFile;
cfg.config()->SetFilesystemId(filesystemId);
cfg.save();
}
@ -245,7 +245,7 @@ TEST_F(CryConfigLoaderTest, Cipher_Create) {
}
TEST_F(CryConfigLoaderTest, Version_Load) {
CreateWithVersion("0.9.2");
CreateWithVersion("0.9.2", "0.9.2");
auto loaded = Load().value();
EXPECT_EQ(CryConfig::FilesystemFormatVersion, loaded.config()->Version());
EXPECT_EQ(gitversion::VersionString(), loaded.config()->LastOpenedWithVersion());
@ -253,7 +253,7 @@ TEST_F(CryConfigLoaderTest, Version_Load) {
}
TEST_F(CryConfigLoaderTest, Version_Load_IsStoredAndNotOnlyOverwrittenInMemoryOnLoad) {
CreateWithVersion("0.9.2", "mypassword");
CreateWithVersion("0.9.2", "0.9.2", "mypassword");
Load().value();
auto configFile = CryConfigFile::load(file.path(), "mypassword").value();
EXPECT_EQ(CryConfig::FilesystemFormatVersion, configFile.config()->Version());
@ -284,7 +284,7 @@ TEST_F(CryConfigLoaderTest, AsksWhenLoadingNewerFilesystem_AnswerYes) {
EXPECT_CALL(*console, askYesNo(HasSubstr("should not be opened with older versions"), false)).Times(1).WillOnce(Return(true));
string version = newerVersion();
CreateWithVersion(version);
CreateWithVersion(version, version);
EXPECT_NE(boost::none, Load());
}
@ -292,7 +292,7 @@ TEST_F(CryConfigLoaderTest, AsksWhenLoadingNewerFilesystem_AnswerNo) {
EXPECT_CALL(*console, askYesNo(HasSubstr("should not be opened with older versions"), false)).Times(1).WillOnce(Return(false));
string version = newerVersion();
CreateWithVersion(version);
CreateWithVersion(version, version);
try {
Load();
EXPECT_TRUE(false); // expect throw
@ -305,14 +305,14 @@ TEST_F(CryConfigLoaderTest, AsksWhenMigratingOlderFilesystem) {
EXPECT_CALL(*console, askYesNo(HasSubstr("Do you want to migrate it?"), false)).Times(1).WillOnce(Return(true));
string version = olderVersion();
CreateWithVersion(version);
CreateWithVersion(version, version);
EXPECT_NE(boost::none, Load());
}
TEST_F(CryConfigLoaderTest, DoesNotAskForMigrationWhenCorrectVersion) {
EXPECT_CALL(*console, askYesNo(HasSubstr("Do you want to migrate it?"), false)).Times(0);
EXPECT_CALL(*console, askYesNo(HasSubstr("Do you want to migrate it?"), _)).Times(0);
CreateWithVersion(gitversion::VersionString());
CreateWithVersion(gitversion::VersionString(), CryConfig::FilesystemFormatVersion);
EXPECT_NE(boost::none, Load());
}
@ -320,7 +320,7 @@ TEST_F(CryConfigLoaderTest, DontMigrateWhenAnsweredNo) {
EXPECT_CALL(*console, askYesNo(HasSubstr("Do you want to migrate it?"), false)).Times(1).WillOnce(Return(false));
string version = olderVersion();
CreateWithVersion(version);
CreateWithVersion(version, version);
try {
Load();
EXPECT_TRUE(false); // expect throw
@ -332,21 +332,21 @@ TEST_F(CryConfigLoaderTest, DontMigrateWhenAnsweredNo) {
TEST_F(CryConfigLoaderTest, MyClientIdIsIndeterministic) {
TempFile file1(false);
TempFile file2(false);
uint32_t myClientId = loader("mypassword", true).loadOrCreate(file1.path(), false).value().myClientId;
EXPECT_NE(myClientId, loader("mypassword", true).loadOrCreate(file2.path(), false).value().myClientId);
uint32_t myClientId = loader("mypassword", true).loadOrCreate(file1.path(), false, false).value().myClientId;
EXPECT_NE(myClientId, loader("mypassword", true).loadOrCreate(file2.path(), false, false).value().myClientId);
}
TEST_F(CryConfigLoaderTest, MyClientIdIsLoadedCorrectly) {
TempFile file(false);
uint32_t myClientId = loader("mypassword", true).loadOrCreate(file.path(), false).value().myClientId;
EXPECT_EQ(myClientId, loader("mypassword", true).loadOrCreate(file.path(), false).value().myClientId);
uint32_t myClientId = loader("mypassword", true).loadOrCreate(file.path(), false, false).value().myClientId;
EXPECT_EQ(myClientId, loader("mypassword", true).loadOrCreate(file.path(), false, false).value().myClientId);
}
TEST_F(CryConfigLoaderTest, DoesNotAskForMigrationWhenUpgradesAllowedByProgramArguments_NoninteractiveMode) {
EXPECT_CALL(*console, askYesNo(HasSubstr("migrate"), _)).Times(0);
string version = olderVersion();
CreateWithVersion(version);
CreateWithVersion(version, version);
EXPECT_NE(boost::none, Load("mypassword", none, true, true));
}
@ -354,6 +354,6 @@ TEST_F(CryConfigLoaderTest, DoesNotAskForMigrationWhenUpgradesAllowedByProgramAr
EXPECT_CALL(*console, askYesNo(HasSubstr("migrate"), _)).Times(0);
string version = olderVersion();
CreateWithVersion(version);
CreateWithVersion(version, version);
EXPECT_NE(boost::none, Load("mypassword", none, false, true));
}

View File

@ -38,7 +38,7 @@ public:
CryConfigFile loadOrCreateConfig() {
auto askPassword = [] {return "mypassword";};
return CryConfigLoader(make_shared<NoninteractiveConsole>(mockConsole()), Random::PseudoRandom(), SCrypt::TestSettings, askPassword, askPassword, none, none, none).loadOrCreate(config.path(), false).value().configFile;
return CryConfigLoader(make_shared<NoninteractiveConsole>(mockConsole()), Random::PseudoRandom(), SCrypt::TestSettings, askPassword, askPassword, none, none, none).loadOrCreate(config.path(), false, false).value().configFile;
}
unique_ref<OnDiskBlockStore2> blockStore() {

View File

@ -29,7 +29,7 @@ public:
auto blockStore = cpputils::make_unique_ref<InMemoryBlockStore2>();
auto askPassword = [] {return "mypassword";};
auto config = CryConfigLoader(make_shared<NoninteractiveConsole>(mockConsole()), Random::PseudoRandom(), SCrypt::TestSettings, askPassword, askPassword, none, none, none)
.loadOrCreate(configFile.path(), false).value();
.loadOrCreate(configFile.path(), false, false).value();
return make_unique_ref<CryDevice>(std::move(config.configFile), std::move(blockStore), config.myClientId, false, false);
}

View File

@ -18,14 +18,14 @@ public:
};
TEST_F(LocalStateMetadataTest, myClientId_ValueIsConsistent) {
LocalStateMetadata metadata1 = LocalStateMetadata::loadOrGenerate(stateDir.path(), Data(0));
LocalStateMetadata metadata2 = LocalStateMetadata::loadOrGenerate(stateDir.path(), Data(0));
LocalStateMetadata metadata1 = LocalStateMetadata::loadOrGenerate(stateDir.path(), Data(0), false);
LocalStateMetadata metadata2 = LocalStateMetadata::loadOrGenerate(stateDir.path(), Data(0), false);
EXPECT_EQ(metadata1.myClientId(), metadata2.myClientId());
}
TEST_F(LocalStateMetadataTest, myClientId_ValueIsRandomForNewClient) {
LocalStateMetadata metadata1 = LocalStateMetadata::loadOrGenerate(stateDir.path(), Data(0));
LocalStateMetadata metadata2 = LocalStateMetadata::loadOrGenerate(stateDir2.path(), Data(0));
LocalStateMetadata metadata1 = LocalStateMetadata::loadOrGenerate(stateDir.path(), Data(0), false);
LocalStateMetadata metadata2 = LocalStateMetadata::loadOrGenerate(stateDir2.path(), Data(0), false);
EXPECT_NE(metadata1.myClientId(), metadata2.myClientId());
}
@ -35,20 +35,20 @@ TEST_F(LocalStateMetadataTest, myClientId_TakesLegacyValueIfSpecified) {
file << 12345u;
file.close();
LocalStateMetadata metadata = LocalStateMetadata::loadOrGenerate(stateDir.path(), Data(0));
LocalStateMetadata metadata = LocalStateMetadata::loadOrGenerate(stateDir.path(), Data(0), false);
EXPECT_EQ(12345u, metadata.myClientId());
}
#endif
TEST_F(LocalStateMetadataTest, encryptionKeyHash_whenLoadingWithSameKey_thenDoesntCrash) {
LocalStateMetadata::loadOrGenerate(stateDir.path(), DataFixture::generate(1024));
LocalStateMetadata::loadOrGenerate(stateDir.path(), DataFixture::generate(1024));
LocalStateMetadata::loadOrGenerate(stateDir.path(), DataFixture::generate(1024), false);
LocalStateMetadata::loadOrGenerate(stateDir.path(), DataFixture::generate(1024), false);
}
TEST_F(LocalStateMetadataTest, encryptionKeyHash_whenLoadingWithDifferentKey_thenCrashes) {
LocalStateMetadata::loadOrGenerate(stateDir.path(), DataFixture::generate(1024, 1));
LocalStateMetadata::loadOrGenerate(stateDir.path(), DataFixture::generate(1024, 1), false);
EXPECT_THROW(
LocalStateMetadata::loadOrGenerate(stateDir.path(), DataFixture::generate(1024, 2)),
LocalStateMetadata::loadOrGenerate(stateDir.path(), DataFixture::generate(1024, 2), false),
std::runtime_error
);
}