2015-10-29 19:34:36 +01:00
|
|
|
#include "testutils/CliTest.h"
|
2015-10-29 10:47:14 +01:00
|
|
|
|
|
|
|
//TODO Test CLI ends with error message (before daemonization), if
|
|
|
|
// - mountdir does not exist
|
|
|
|
// - mountdir exists but belongs to other user
|
|
|
|
// - mountdir exists but is missing permissions
|
|
|
|
// - TODO when else is libfuse failing? What requirements are there for the mountdir?)
|
2015-10-29 15:52:49 +01:00
|
|
|
//TODO Test what happens if basedir == mountdir
|
|
|
|
//TODO Test all stuff (basedir missing, not readable, not writeable, not accessible, ...) also with "-f" foreground flag.
|
2015-10-29 10:47:14 +01:00
|
|
|
|
2015-10-29 15:52:49 +01:00
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
namespace bf = boost::filesystem;
|
2015-10-29 15:52:49 +01:00
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
//Tests what happens if cryfs is run in the wrong environment, i.e. with a base directory that doesn't exist or similar
|
|
|
|
class CliTest_WrongEnvironment: public CliTest {
|
|
|
|
public:
|
2015-10-29 15:52:49 +01:00
|
|
|
void RemoveReadPermission(const bf::path &dir) {
|
|
|
|
//TODO Take read permission from basedir in a better way
|
2015-10-29 19:34:36 +01:00
|
|
|
system((std::string("chmod -rwx ")+dir.c_str()).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test_Run_Success() {
|
|
|
|
EXPECT_RUN_SUCCESS(
|
|
|
|
{basedir.path().c_str(), mountdir.path().c_str()}
|
|
|
|
);
|
2015-10-29 15:52:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Test_Run_Error(const char *expectedError) {
|
|
|
|
EXPECT_RUN_ERROR(
|
|
|
|
{basedir.path().c_str(), mountdir.path().c_str()},
|
|
|
|
expectedError
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test_Run_LogIsNotStderr_Error(const char *expectedError) {
|
|
|
|
//Error message should be shown on stderr, even if a logfile is specified.
|
|
|
|
EXPECT_RUN_ERROR(
|
|
|
|
{basedir.path().c_str(), mountdir.path().c_str(), "--logfile", logfile.path().c_str()},
|
|
|
|
expectedError
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test_Run_ExternalConfigfile_Error(const char *expectedError) {
|
|
|
|
//Config file writing is one of the first things happening. This test case ensures that even if
|
|
|
|
//the config file is not written to the base directory, a wrong base directory is recognized correctly.
|
|
|
|
EXPECT_RUN_ERROR(
|
|
|
|
{basedir.path().c_str(), mountdir.path().c_str(), "--config", configfile.path().c_str()},
|
|
|
|
expectedError
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Test_Run_ExternalConfigfile_LogIsNotStderr_Error(const char *expectedError) {
|
|
|
|
EXPECT_RUN_ERROR(
|
|
|
|
{basedir.path().c_str(), mountdir.path().c_str(), "--logfile", logfile.path().c_str(), "--config", configfile.path().c_str()},
|
|
|
|
expectedError
|
|
|
|
);
|
2015-10-29 19:34:36 +01:00
|
|
|
}
|
2015-10-29 10:47:14 +01:00
|
|
|
};
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, NoErrorCondition) {
|
|
|
|
//Counter-Test. Test that it doesn't fail if we call it without an error condition.
|
|
|
|
Test_Run_Success();
|
2015-10-29 15:52:49 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_DoesntExist) {
|
2015-10-29 15:52:49 +01:00
|
|
|
basedir.remove();
|
|
|
|
Test_Run_Error("Error: Base directory not found");
|
2015-10-29 10:47:14 +01:00
|
|
|
}
|
2015-10-29 15:52:49 +01:00
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_DoesntExist_LogIsNotStderr) {
|
2015-10-29 15:52:49 +01:00
|
|
|
basedir.remove();
|
|
|
|
Test_Run_LogIsNotStderr_Error("Error: Base directory not found");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_DoesntExist_ExternalConfigfile) {
|
2015-10-29 15:52:49 +01:00
|
|
|
basedir.remove();
|
|
|
|
Test_Run_ExternalConfigfile_Error("Error: Base directory not found");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_DoesntExist_ExternalConfigfile_LogIsNotStderr) {
|
2015-10-29 15:52:49 +01:00
|
|
|
basedir.remove();
|
|
|
|
Test_Run_ExternalConfigfile_LogIsNotStderr_Error("Error: Base directory not found");
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO finish the following test cases
|
|
|
|
/*
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoReadPermission) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveReadPermission(basedir);
|
|
|
|
Test_Run_Error("Error: Base directory not readable");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoReadPermission_LogIsNotStderr) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveReadPermission(basedir);
|
|
|
|
Test_Run_LogIsNotStderr_Error("Error: Base directory not readable");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoReadPermission_ExternalConfigfile) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveReadPermission(basedir);
|
|
|
|
Test_Run_ExternalConfigfile_Error("Error: Base directory not readable");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoReadPermission_ExternalConfigfile_LogIsNotStderr) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveReadPermission(basedir);
|
|
|
|
Test_Run_ExternalConfigfile_LogIsNotStderrError("Error: Base directory not readable");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoWritePermission) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveReadPermission(basedir);
|
|
|
|
Test_Run_Error("Error: Base directory not writeable");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoWritePermission_LogIsNotStderr) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveReadPermission(basedir);
|
|
|
|
Test_Run_LogIsNotStderr_Error("Error: Base directory not writeable");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoWritePermission_ExternalConfigfile) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveReadPermission(basedir);
|
|
|
|
Test_Run_ExternalConfigfile_Error("Error: Base directory not writeable");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoWritePermission_ExternalConfigfile_LogIsNotStderr) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveReadPermission(basedir);
|
|
|
|
Test_Run_ExternalConfigfile_LogIsNotStderrError("Error: Base directory not writeable");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoAccessPermission) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveAccessPermission(basedir);
|
|
|
|
Test_Run_Error("Error: Base directory not accessable");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoAccessPermission_LogIsNotStderr) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveAccessPermission(basedir);
|
|
|
|
Test_Run_LogIsNotStderr_Error("Error: Base directory not accessable");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoAccessPermission_ExternalConfigfile) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveAccessPermission(basedir);
|
|
|
|
Test_Run_ExternalConfigfile_Error("Error: Base directory not accessable");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoAccessPermission_ExternalConfigfile_LogIsNotStderr) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveAccessPermission(basedir);
|
|
|
|
Test_Run_ExternalConfigfile_LogIsNotStderrError("Error: Base directory not accessable");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoPermission) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveAllPermissions(basedir);
|
|
|
|
Test_Run_Error("Error: Base directory not accessable");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoPermission_LogIsNotStderr) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveAllPermissions(basedir);
|
|
|
|
Test_Run_LogIsNotStderr_Error("Error: Base directory not accessable");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoPermission_ExternalConfigfile) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveAllPermissions(basedir);
|
|
|
|
Test_Run_ExternalConfigfile_Error("Error: Base directory not accessable");
|
|
|
|
}
|
|
|
|
|
2015-10-29 19:34:36 +01:00
|
|
|
TEST_F(CliTest_WrongEnvironment, BaseDir_NoPermission_ExternalConfigfile_LogIsNotStderr) {
|
2015-10-29 15:52:49 +01:00
|
|
|
RemoveAllPermissions(basedir);
|
|
|
|
Test_Run_ExternalConfigfile_LogIsNotStderrError("Error: Base directory not accessable");
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|