Add a sanity check that mountdir can't be equal to rootdir
This commit is contained in:
parent
c572e7f353
commit
b7af7ca2f2
@ -143,6 +143,12 @@ namespace cryfs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Cli::_sanityChecks(const ProgramOptions &options) {
|
||||||
|
if (bf::path(options.baseDir()) == bf::path(options.mountDir())) {
|
||||||
|
throw std::runtime_error("Can't mount into base directory");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int Cli::main(int argc, char *argv[]) {
|
int Cli::main(int argc, char *argv[]) {
|
||||||
cpputils::showBacktraceOnSigSegv();
|
cpputils::showBacktraceOnSigSegv();
|
||||||
_showVersion();
|
_showVersion();
|
||||||
@ -150,6 +156,7 @@ namespace cryfs {
|
|||||||
ProgramOptions options = program_options::Parser(argc, argv).parse();
|
ProgramOptions options = program_options::Parser(argc, argv).parse();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
_sanityChecks(options);
|
||||||
_runFilesystem(options);
|
_runFilesystem(options);
|
||||||
} catch (const std::runtime_error &e) {
|
} catch (const std::runtime_error &e) {
|
||||||
std::cerr << "Error: " << e.what() << std::endl;
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
@ -20,6 +20,7 @@ namespace cryfs {
|
|||||||
static bool _checkPassword(const std::string &password);
|
static bool _checkPassword(const std::string &password);
|
||||||
static void _showVersion();
|
static void _showVersion();
|
||||||
static void _initLogfile(const program_options::ProgramOptions &options);
|
static void _initLogfile(const program_options::ProgramOptions &options);
|
||||||
|
static void _sanityChecks(const program_options::ProgramOptions &options);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,17 +6,17 @@ using cpputils::TempFile;
|
|||||||
using CliTest_Setup = CliTest;
|
using CliTest_Setup = CliTest;
|
||||||
|
|
||||||
TEST_F(CliTest_Setup, NoSpecialOptions) {
|
TEST_F(CliTest_Setup, NoSpecialOptions) {
|
||||||
EXPECT_RUN_SUCCESS({basedir.path().c_str(), mountdir.path().c_str()});
|
EXPECT_RUN_SUCCESS({basedir->path().c_str(), mountdir->path().c_str()});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CliTest_Setup, NotexistingLogfileGiven) {
|
TEST_F(CliTest_Setup, NotexistingLogfileGiven) {
|
||||||
TempFile notexisting_logfile(false);
|
TempFile notexisting_logfile(false);
|
||||||
EXPECT_RUN_SUCCESS({basedir.path().c_str(), mountdir.path().c_str(), "--logfile", notexisting_logfile.path().c_str()});
|
EXPECT_RUN_SUCCESS({basedir->path().c_str(), mountdir->path().c_str(), "--logfile", notexisting_logfile.path().c_str()});
|
||||||
//TODO Expect logfile is used (check logfile content)
|
//TODO Expect logfile is used (check logfile content)
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CliTest_Setup, ExistingLogfileGiven) {
|
TEST_F(CliTest_Setup, ExistingLogfileGiven) {
|
||||||
EXPECT_RUN_SUCCESS({basedir.path().c_str(), mountdir.path().c_str(), "--logfile", logfile.path().c_str()});
|
EXPECT_RUN_SUCCESS({basedir->path().c_str(), mountdir->path().c_str(), "--logfile", logfile.path().c_str()});
|
||||||
//TODO Expect logfile is used (check logfile content)
|
//TODO Expect logfile is used (check logfile content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ TEST_F(CliTest_ShowingHelp, HelpLongOption) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CliTest_ShowingHelp, HelpLongOptionTogetherWithOtherOptions) {
|
TEST_F(CliTest_ShowingHelp, HelpLongOptionTogetherWithOtherOptions) {
|
||||||
EXPECT_EXIT_WITH_HELP_MESSAGE({"/", "/mountdir", "--help"});
|
EXPECT_EXIT_WITH_HELP_MESSAGE({basedir->path().c_str(), mountdir->path().c_str(), "--help"});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CliTest_ShowingHelp, HelpShortOption) {
|
TEST_F(CliTest_ShowingHelp, HelpShortOption) {
|
||||||
@ -15,7 +15,7 @@ TEST_F(CliTest_ShowingHelp, HelpShortOption) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CliTest_ShowingHelp, HelpShortOptionTogetherWithOtherOptions) {
|
TEST_F(CliTest_ShowingHelp, HelpShortOptionTogetherWithOtherOptions) {
|
||||||
EXPECT_EXIT_WITH_HELP_MESSAGE({"/", "/mountdir", "-h"});
|
EXPECT_EXIT_WITH_HELP_MESSAGE({basedir->path().c_str(), mountdir->path().c_str(), "-h"});
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CliTest_ShowingHelp, MissingAllOptions) {
|
TEST_F(CliTest_ShowingHelp, MissingAllOptions) {
|
||||||
@ -23,5 +23,5 @@ TEST_F(CliTest_ShowingHelp, MissingAllOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(CliTest_ShowingHelp, MissingDir) {
|
TEST_F(CliTest_ShowingHelp, MissingDir) {
|
||||||
EXPECT_EXIT_WITH_HELP_MESSAGE({"/"});
|
EXPECT_EXIT_WITH_HELP_MESSAGE({basedir->path().c_str()});
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
// - mountdir exists but belongs to other user
|
// - mountdir exists but belongs to other user
|
||||||
// - mountdir exists but is missing permissions
|
// - mountdir exists but is missing permissions
|
||||||
// - TODO when else is libfuse failing? What requirements are there for the mountdir?)
|
// - TODO when else is libfuse failing? What requirements are there for the mountdir?)
|
||||||
//TODO Test what happens if basedir == mountdir
|
|
||||||
|
|
||||||
|
|
||||||
namespace bf = boost::filesystem;
|
namespace bf = boost::filesystem;
|
||||||
@ -39,7 +38,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
vector<const char*> args() {
|
vector<const char*> args() {
|
||||||
vector<const char*> result = {basedir.path().c_str(), mountdir.path().c_str()};
|
vector<const char*> result = {basedir->path().c_str(), mountdir->path().c_str()};
|
||||||
if (GetParam().externalConfigfile) {
|
if (GetParam().externalConfigfile) {
|
||||||
result.push_back("--config");
|
result.push_back("--config");
|
||||||
result.push_back(configfile.path().c_str());
|
result.push_back(configfile.path().c_str());
|
||||||
@ -69,8 +68,13 @@ TEST_P(CliTest_WrongEnvironment, NoErrorCondition) {
|
|||||||
Test_Run_Success();
|
Test_Run_Success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_P(CliTest_WrongEnvironment, MountDirIsBaseDir) {
|
||||||
|
mountdir = basedir;
|
||||||
|
Test_Run_Error("Error: Can't mount into base directory");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_P(CliTest_WrongEnvironment, BaseDir_DoesntExist) {
|
TEST_P(CliTest_WrongEnvironment, BaseDir_DoesntExist) {
|
||||||
basedir.remove();
|
basedir->remove();
|
||||||
Test_Run_Error("Error: Base directory not found");
|
Test_Run_Error("Error: Base directory not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,10 +9,10 @@
|
|||||||
|
|
||||||
class CliTest : public ::testing::Test {
|
class CliTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
CliTest(): basedir(), mountdir(), logfile(), configfile(false) {}
|
CliTest(): basedir(std::make_shared<cpputils::TempDir>()), mountdir(std::make_shared<cpputils::TempDir>()), logfile(), configfile(false) {}
|
||||||
|
|
||||||
cpputils::TempDir basedir;
|
std::shared_ptr<cpputils::TempDir> basedir;
|
||||||
cpputils::TempDir mountdir;
|
std::shared_ptr<cpputils::TempDir> mountdir;
|
||||||
cpputils::TempFile logfile;
|
cpputils::TempFile logfile;
|
||||||
cpputils::TempFile configfile;
|
cpputils::TempFile configfile;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user