diff --git a/src/cryfs-cli/program_options/ProgramOptions.h b/src/cryfs-cli/program_options/ProgramOptions.h index 887fffa6..d7410a6c 100644 --- a/src/cryfs-cli/program_options/ProgramOptions.h +++ b/src/cryfs-cli/program_options/ProgramOptions.h @@ -25,7 +25,6 @@ namespace cryfs { const boost::filesystem::path &mountDir() const; const boost::optional &configFile() const; bool foreground() const; - // TODO add test cases for allowFilesystemUpgrade bool allowFilesystemUpgrade() const; const boost::optional &cipher() const; const boost::optional &blocksizeBytes() const; diff --git a/test/cryfs-cli/program_options/ParserTest.cpp b/test/cryfs-cli/program_options/ParserTest.cpp index d566459d..fbd9ca3b 100644 --- a/test/cryfs-cli/program_options/ParserTest.cpp +++ b/test/cryfs-cli/program_options/ParserTest.cpp @@ -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()); diff --git a/test/cryfs-cli/program_options/ProgramOptionsTest.cpp b/test/cryfs-cli/program_options/ProgramOptionsTest.cpp index 802581c9..40e7a43e 100644 --- a/test/cryfs-cli/program_options/ProgramOptionsTest.cpp +++ b/test/cryfs-cli/program_options/ProgramOptionsTest.cpp @@ -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()); } + diff --git a/test/cryfs/config/CryConfigLoaderTest.cpp b/test/cryfs/config/CryConfigLoaderTest.cpp index 72f12d2e..24125930 100644 --- a/test/cryfs/config/CryConfigLoaderTest.cpp +++ b/test/cryfs/config/CryConfigLoaderTest.cpp @@ -56,9 +56,9 @@ public: return loader(password, noninteractive, cipher).loadOrCreate(file.path(), false).value(); } - optional Load(const string &password = "mypassword", const optional &cipher = none, bool noninteractive = false) { + optional Load(const string &password = "mypassword", const optional &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)); +}