Add test cases for --allow-filesystem-upgrade

This commit is contained in:
Sebastian Messmer 2018-02-01 09:45:31 -08:00
parent 11c6f7fa98
commit 67afdd4baa
4 changed files with 49 additions and 3 deletions

View File

@ -25,7 +25,6 @@ namespace cryfs {
const boost::filesystem::path &mountDir() const;
const boost::optional<boost::filesystem::path> &configFile() const;
bool foreground() const;
// TODO add test cases for allowFilesystemUpgrade
bool allowFilesystemUpgrade() const;
const boost::optional<std::string> &cipher() const;
const boost::optional<uint32_t> &blocksizeBytes() const;

View File

@ -74,6 +74,26 @@ TEST_F(ProgramOptionsParserTest, MountDir_Relative) {
EXPECT_EQ(bf::current_path() / "mountDir", options.mountDir());
}
TEST_F(ProgramOptionsParserTest, Foreground_False) {
ProgramOptions options = parse({"./myExecutable", "/home/user/basedir", "mountdir"});
EXPECT_FALSE(options.foreground());
}
TEST_F(ProgramOptionsParserTest, Foreground_True) {
ProgramOptions options = parse({"./myExecutable", "-f", "/home/user/basedir", "mountdir"});
EXPECT_TRUE(options.foreground());
}
TEST_F(ProgramOptionsParserTest, AllowFilesystemUpgrade_False) {
ProgramOptions options = parse({"./myExecutable", "/home/user/basedir", "mountdir"});
EXPECT_FALSE(options.allowFilesystemUpgrade());
}
TEST_F(ProgramOptionsParserTest, AllowFilesystemUpgrade_True) {
ProgramOptions options = parse({"./myExecutable", "--allow-filesystem-upgrade", "/home/user/basedir", "mountdir"});
EXPECT_TRUE(options.allowFilesystemUpgrade());
}
TEST_F(ProgramOptionsParserTest, LogfileGiven) {
ProgramOptions options = parse({"./myExecutable", "/home/user/baseDir", "--logfile", "/home/user/mylogfile", "/home/user/mountDir"});
EXPECT_EQ("/home/user/mylogfile", options.logFile().value());

View File

@ -52,6 +52,16 @@ TEST_F(ProgramOptionsTest, ForegroundTrue) {
EXPECT_TRUE(testobj.foreground());
}
TEST_F(ProgramOptionsTest, AllowFilesystemUpgradeFalse) {
ProgramOptions testobj("", "", none, false, false, none, none, none, none, {"./myExecutable"});
EXPECT_FALSE(testobj.allowFilesystemUpgrade());
}
TEST_F(ProgramOptionsTest, AllowFilesystemUpgradeTrue) {
ProgramOptions testobj("", "", none, false, true, none, none, none, none, {"./myExecutable"});
EXPECT_TRUE(testobj.allowFilesystemUpgrade());
}
TEST_F(ProgramOptionsTest, LogfileNone) {
ProgramOptions testobj("", "", none, true, false, none, none, none, none, {"./myExecutable"});
EXPECT_EQ(none, testobj.logFile());
@ -103,3 +113,4 @@ TEST_F(ProgramOptionsTest, SomeFuseOptions) {
//Fuse should have the mount dir as first parameter
EXPECT_VECTOR_EQ({"-f", "--longoption"}, testobj.fuseOptions());
}

View File

@ -56,9 +56,9 @@ public:
return loader(password, noninteractive, cipher).loadOrCreate(file.path(), false).value();
}
optional<CryConfigFile> Load(const string &password = "mypassword", const optional<string> &cipher = none, bool noninteractive = false) {
optional<CryConfigFile> Load(const string &password = "mypassword", const optional<string> &cipher = none, bool noninteractive = false, bool allowFilesystemUpgrade = false) {
EXPECT_TRUE(file.exists());
return loader(password, noninteractive, cipher).loadOrCreate(file.path(), false);
return loader(password, noninteractive, cipher).loadOrCreate(file.path(), allowFilesystemUpgrade);
}
void CreateWithRootBlob(const string &rootBlob, const string &password = "mypassword") {
@ -276,3 +276,19 @@ TEST_F(CryConfigLoaderTest, DontMigrateWhenAnsweredNo) {
EXPECT_THAT(e.what(), HasSubstr("It has to be migrated."));
}
}
TEST_F(CryConfigLoaderTest, DoesNotAskForMigrationWhenUpgradesAllowedByProgramArguments_NoninteractiveMode) {
EXPECT_CALL(*console, askYesNo(HasSubstr("migrate"), _)).Times(0);
string version = olderVersion();
CreateWithVersion(version);
EXPECT_NE(boost::none, Load("mypassword", none, true, true));
}
TEST_F(CryConfigLoaderTest, DoesNotAskForMigrationWhenUpgradesAllowedByProgramArguments_InteractiveMode) {
EXPECT_CALL(*console, askYesNo(HasSubstr("migrate"), _)).Times(0);
string version = olderVersion();
CreateWithVersion(version);
EXPECT_NE(boost::none, Load("mypassword", none, false, true));
}