2015-09-29 14:29:10 +02:00
|
|
|
#include "testutils/ProgramOptionsTestBase.h"
|
2016-02-23 21:07:23 +01:00
|
|
|
#include <cryfs-cli/program_options/ProgramOptions.h>
|
2016-02-11 16:39:42 +01:00
|
|
|
#include <cpp-utils/pointer/unique_ref_boost_optional_gtest_workaround.h>
|
2015-09-29 14:29:10 +02:00
|
|
|
|
2019-01-19 22:02:41 +01:00
|
|
|
using namespace cryfs_cli::program_options;
|
2015-10-17 19:38:24 +02:00
|
|
|
using boost::none;
|
2015-11-18 11:01:48 +01:00
|
|
|
using boost::optional;
|
|
|
|
using std::ostream;
|
2015-10-17 19:38:24 +02:00
|
|
|
using std::string;
|
2015-11-18 11:01:48 +01:00
|
|
|
namespace bf = boost::filesystem;
|
|
|
|
|
|
|
|
// This is needed for google test to work with boost::optional<boost::filesystem::path>
|
|
|
|
namespace boost {
|
2018-09-04 00:59:17 +02:00
|
|
|
template<> inline ostream& operator<< <char, std::char_traits<char>, bf::path>(ostream &stream, const optional<bf::path> &path) {
|
2015-11-18 11:01:48 +01:00
|
|
|
if (path == none) {
|
|
|
|
return stream << "none";
|
|
|
|
}
|
|
|
|
return stream << *path;
|
|
|
|
}
|
|
|
|
}
|
2015-09-29 14:29:10 +02:00
|
|
|
|
|
|
|
class ProgramOptionsTest: public ProgramOptionsTestBase {};
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, BaseDir) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("/home/user/mydir", "", none, false, false, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
2015-09-29 14:29:10 +02:00
|
|
|
EXPECT_EQ("/home/user/mydir", testobj.baseDir());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, MountDir) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "/home/user/mydir", none, false, false, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
2015-09-29 14:29:10 +02:00
|
|
|
EXPECT_EQ("/home/user/mydir", testobj.mountDir());
|
|
|
|
}
|
|
|
|
|
2015-10-24 19:56:05 +02:00
|
|
|
TEST_F(ProgramOptionsTest, ConfigfileNone) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, true, false, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
2015-10-24 19:56:05 +02:00
|
|
|
EXPECT_EQ(none, testobj.configFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, ConfigfileSome) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", bf::path("/home/user/configfile"), true, false, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
2015-10-24 19:56:05 +02:00
|
|
|
EXPECT_EQ("/home/user/configfile", testobj.configFile().get());
|
2015-09-29 14:39:10 +02:00
|
|
|
}
|
|
|
|
|
2015-10-15 05:26:05 +02:00
|
|
|
TEST_F(ProgramOptionsTest, ForegroundFalse) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, false, false, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
2015-10-15 05:26:05 +02:00
|
|
|
EXPECT_FALSE(testobj.foreground());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, ForegroundTrue) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, true, false, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
2015-10-15 05:26:05 +02:00
|
|
|
EXPECT_TRUE(testobj.foreground());
|
|
|
|
}
|
|
|
|
|
2018-02-01 18:45:31 +01:00
|
|
|
TEST_F(ProgramOptionsTest, AllowFilesystemUpgradeFalse) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, false, false, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
2018-02-01 18:45:31 +01:00
|
|
|
EXPECT_FALSE(testobj.allowFilesystemUpgrade());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, AllowFilesystemUpgradeTrue) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, false, true, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
2018-02-01 18:45:31 +01:00
|
|
|
EXPECT_TRUE(testobj.allowFilesystemUpgrade());
|
|
|
|
}
|
|
|
|
|
2020-08-01 03:08:19 +02:00
|
|
|
TEST_F(ProgramOptionsTest, CreateMissingBasedirFalse) {
|
|
|
|
ProgramOptions testobj("", "", none, false, false, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
|
|
|
EXPECT_FALSE(testobj.createMissingBasedir());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, CreateMissingBasedirTrue) {
|
|
|
|
ProgramOptions testobj("", "", none, false, true, false, true, false, none, none, none, none, false, none, {"./myExecutable"});
|
|
|
|
EXPECT_TRUE(testobj.createMissingBasedir());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, CreateMissingMountpointFalse) {
|
|
|
|
ProgramOptions testobj("", "", none, false, false, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
|
|
|
EXPECT_FALSE(testobj.createMissingMountpoint());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, CreateMissingMountpointTrue) {
|
|
|
|
ProgramOptions testobj("", "", none, false, true, false, false, true, none, none, none, none, false, none, {"./myExecutable"});
|
|
|
|
EXPECT_TRUE(testobj.createMissingMountpoint());
|
|
|
|
}
|
|
|
|
|
2015-10-17 19:38:24 +02:00
|
|
|
TEST_F(ProgramOptionsTest, LogfileNone) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, true, false, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
2015-10-17 19:38:24 +02:00
|
|
|
EXPECT_EQ(none, testobj.logFile());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, LogfileSome) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, true, false, false, false, false, none, bf::path("logfile"), none, none, false, none, {"./myExecutable"});
|
2015-10-17 19:38:24 +02:00
|
|
|
EXPECT_EQ("logfile", testobj.logFile().get());
|
|
|
|
}
|
|
|
|
|
2015-11-12 20:43:11 +01:00
|
|
|
TEST_F(ProgramOptionsTest, UnmountAfterIdleMinutesNone) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, true, false, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
2018-02-01 20:21:26 +01:00
|
|
|
EXPECT_EQ(none, testobj.unmountAfterIdleMinutes());
|
2015-11-12 20:43:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, UnmountAfterIdleMinutesSome) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, true, false, false, false, false, 10, none, none, none, false, none, {"./myExecutable"});
|
2015-11-12 20:43:11 +01:00
|
|
|
EXPECT_EQ(10, testobj.unmountAfterIdleMinutes().get());
|
|
|
|
}
|
|
|
|
|
2015-10-30 19:53:15 +01:00
|
|
|
TEST_F(ProgramOptionsTest, CipherNone) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, true, false, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
2015-10-30 19:53:15 +01:00
|
|
|
EXPECT_EQ(none, testobj.cipher());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, CipherSome) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, true, false, false, false, false, none, none, string("aes-256-gcm"), none, false, none, {"./myExecutable"});
|
2015-10-30 19:53:15 +01:00
|
|
|
EXPECT_EQ("aes-256-gcm", testobj.cipher().get());
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:12:41 +01:00
|
|
|
TEST_F(ProgramOptionsTest, BlocksizeBytesNone) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, true, false, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
2016-03-04 23:12:41 +01:00
|
|
|
EXPECT_EQ(none, testobj.blocksizeBytes());
|
|
|
|
}
|
|
|
|
|
2016-06-27 07:07:58 +02:00
|
|
|
TEST_F(ProgramOptionsTest, BlocksizeBytesSome) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, true, false, false, false, false, none, none, none, 10*1024, false, none, {"./myExecutable"});
|
2016-03-04 23:12:41 +01:00
|
|
|
EXPECT_EQ(10*1024u, testobj.blocksizeBytes().get());
|
|
|
|
}
|
|
|
|
|
2016-06-27 07:07:58 +02:00
|
|
|
TEST_F(ProgramOptionsTest, MissingBlockIsIntegrityViolationTrue) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, true, false, false, false, false, none, none, none, none, false, true, {"./myExecutable"});
|
2016-06-27 07:07:58 +02:00
|
|
|
EXPECT_TRUE(testobj.missingBlockIsIntegrityViolation().value());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, MissingBlockIsIntegrityViolationFalse) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, true, false, false, false, false, none, none, none, none, false, false, {"./myExecutable"});
|
2016-06-27 07:07:58 +02:00
|
|
|
EXPECT_FALSE(testobj.missingBlockIsIntegrityViolation().value());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, MissingBlockIsIntegrityViolationNone) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, true, false, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
2016-06-27 07:07:58 +02:00
|
|
|
EXPECT_EQ(none, testobj.missingBlockIsIntegrityViolation());
|
|
|
|
}
|
|
|
|
|
2018-04-29 22:41:21 +02:00
|
|
|
TEST_F(ProgramOptionsTest, AllowIntegrityViolationsFalse) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, true, false, false, false, false, none, none, none, none, false, none, {"./myExecutable"});
|
2018-04-29 22:41:21 +02:00
|
|
|
EXPECT_FALSE(testobj.allowIntegrityViolations());
|
2017-09-16 17:18:04 +02:00
|
|
|
}
|
|
|
|
|
2018-04-29 22:41:21 +02:00
|
|
|
TEST_F(ProgramOptionsTest, AllowIntegrityViolationsTrue) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("", "", none, true, false, false, false, false, none, none, none, none, true, none, {"./myExecutable"});
|
2018-04-29 22:41:21 +02:00
|
|
|
EXPECT_TRUE(testobj.allowIntegrityViolations());
|
2017-09-16 17:18:04 +02:00
|
|
|
}
|
|
|
|
|
2015-09-29 14:29:10 +02:00
|
|
|
TEST_F(ProgramOptionsTest, EmptyFuseOptions) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("/rootDir", "/home/user/mydir", none, false, false, false, false, false, none, none, none, none, false, none, {});
|
2015-09-29 14:29:10 +02:00
|
|
|
//Fuse should have the mount dir as first parameter
|
2016-05-10 01:07:02 +02:00
|
|
|
EXPECT_VECTOR_EQ({}, testobj.fuseOptions());
|
2015-09-29 14:29:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(ProgramOptionsTest, SomeFuseOptions) {
|
2020-08-01 03:08:19 +02:00
|
|
|
ProgramOptions testobj("/rootDir", "/home/user/mydir", none, false, false, false, false, false, none, none, none, none, false, none, {"-f", "--longoption"});
|
2015-09-29 14:29:10 +02:00
|
|
|
//Fuse should have the mount dir as first parameter
|
2016-05-10 01:07:02 +02:00
|
|
|
EXPECT_VECTOR_EQ({"-f", "--longoption"}, testobj.fuseOptions());
|
2015-09-29 14:29:10 +02:00
|
|
|
}
|