|
@@ -6,34 +6,84 @@
|
|
|
|
|
|
namespace {
|
|
|
/* Version tests */
|
|
|
+TEST(testVersion, PositiveAllEqual) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+ Json::Value message;
|
|
|
+ message["major"] = 0;
|
|
|
+ message["minor"] = 1;
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.testVersion(message);
|
|
|
+
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_TRUE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
|
|
|
+ EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
|
|
|
+}
|
|
|
+
|
|
|
TEST(testVersion, Positive) {
|
|
|
FileManagerMock fileManager;
|
|
|
|
|
|
JsonCommander jsonCommander(fileManager);
|
|
|
+ Json::Value message;
|
|
|
+ message["major"] = jsonCommander.protocolMajorVersion;
|
|
|
+ message["minor"] = jsonCommander.protocolMinorVersion - 1;
|
|
|
|
|
|
- const std::string versionString = "0.2";
|
|
|
- Json::Value version;
|
|
|
- version["version"] = versionString;
|
|
|
+ JsonCommander::Response response = jsonCommander.testVersion(message);
|
|
|
|
|
|
- JsonCommander::Response response = jsonCommander.testVersion(version);
|
|
|
EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
EXPECT_TRUE(response.json["accept"].asBool());
|
|
|
- EXPECT_EQ(response.json["version"].asString(), versionString);
|
|
|
+ EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
|
|
|
+ EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
|
|
|
}
|
|
|
|
|
|
-TEST(testVersion, Negative) {
|
|
|
+TEST(testVersion, InvalidRequest) {
|
|
|
FileManagerMock fileManager;
|
|
|
|
|
|
JsonCommander jsonCommander(fileManager);
|
|
|
+ Json::Value message;
|
|
|
+ message["major"] = "def";
|
|
|
+ message["minor"] = "abc";
|
|
|
|
|
|
- const std::string versionString = "0.1";
|
|
|
- Json::Value version;
|
|
|
- version["version"] = versionString;
|
|
|
+ JsonCommander::Response response = jsonCommander.testVersion(message);
|
|
|
|
|
|
- JsonCommander::Response response = jsonCommander.testVersion(version);
|
|
|
EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
|
|
|
EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
- EXPECT_FALSE(response.json["version"].asString().compare(versionString) == 0);
|
|
|
+ EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
|
|
|
+ EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(testVersion, NotEqualMajorNumber) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+ Json::Value message;
|
|
|
+ message["major"] = jsonCommander.protocolMajorVersion + 1;
|
|
|
+ message["minor"] = jsonCommander.protocolMinorVersion;
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.testVersion(message);
|
|
|
+
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
|
|
|
+ EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(testVersion, BiggerMinorNumber) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+ Json::Value message;
|
|
|
+ message["major"] = jsonCommander.protocolMajorVersion;
|
|
|
+ message["minor"] = jsonCommander.protocolMinorVersion + 1;
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.testVersion(message);
|
|
|
+
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["major"].asInt(), jsonCommander.protocolMajorVersion);
|
|
|
+ EXPECT_EQ(response.json["minor"].asInt(), jsonCommander.protocolMinorVersion);
|
|
|
}
|
|
|
|
|
|
/* Status tests */
|
|
@@ -871,4 +921,279 @@ TEST(Listdata, InvalidRequest) {
|
|
|
EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
|
|
|
}
|
|
|
|
|
|
+TEST(Head, Positive) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "head";
|
|
|
+ const std::string file = "asdf.txt";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+ message["file"] = file;
|
|
|
+
|
|
|
+ std::vector<char> bytes = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
|
|
|
+ const std::string bytesAsString = "YWJjZGVmZ2g=";
|
|
|
+ EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).WillOnce(testing::Return(std::make_pair(bytes, FileManager::Error::no_error)));
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_TRUE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["file"].asString(), file);
|
|
|
+ EXPECT_EQ(response.json["data"].asString(), bytesAsString);
|
|
|
+ EXPECT_EQ(response.json["error"].asString(), "");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(Head, InvalidRequest) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "head";
|
|
|
+ const int file = 3641;
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+ message["file"] = file;
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["file"].asString(), "");
|
|
|
+ EXPECT_EQ(response.json["data"].asString(), "");
|
|
|
+ EXPECT_NE(response.json["error"].asString(), "");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(Head, NoSuchFile) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "head";
|
|
|
+ const std::string file = "asdf.txt";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+ message["file"] = file;
|
|
|
+
|
|
|
+ std::vector<char> bytes;
|
|
|
+ EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).WillOnce(testing::Return(std::make_pair(bytes, FileManager::Error::no_such_file)));
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["file"].asString(), file);
|
|
|
+ EXPECT_EQ(response.json["data"].asString(), "");
|
|
|
+ EXPECT_NE(response.json["error"].asString(), "");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(Head, FileTooSmall) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "head";
|
|
|
+ const std::string file = "asdf.txt";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+ message["file"] = file;
|
|
|
+
|
|
|
+ std::vector<char> bytes;
|
|
|
+ EXPECT_CALL(fileManager, getBytesFromFile(testing::_, testing::_)).WillOnce(testing::Return(std::make_pair(bytes, FileManager::Error::file_too_small)));
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["file"].asString(), file);
|
|
|
+ EXPECT_EQ(response.json["data"].asString(), "");
|
|
|
+ EXPECT_NE(response.json["error"].asString(), "");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(Deleteme, Positive) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ // need to set currentUser in jsonCommander via calling checkLogin
|
|
|
+ Json::Value login;
|
|
|
+ login["login"] = true;
|
|
|
+ login["user"] = "positive";
|
|
|
+ login["pass"] = "positive";
|
|
|
+ login["cancel"] = false;
|
|
|
+
|
|
|
+ JsonCommander::Response loginRes = jsonCommander.checkLogin(login);
|
|
|
+ EXPECT_TRUE(loginRes.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(loginRes.json["error"].asString(), "");
|
|
|
+
|
|
|
+ // now the actual test
|
|
|
+ const std::string command = "deleteme";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+ message["pass"] = "positive";
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+ EXPECT_EQ(response.action, JsonCommander::Action::closeAndSend);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_TRUE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["error"].asString(), "");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(Deleteme, Negative) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ // need to set currentUser in jsonCommander via calling checkLogin
|
|
|
+ Json::Value login;
|
|
|
+ login["login"] = true;
|
|
|
+ login["user"] = "positive";
|
|
|
+ login["pass"] = "positive";
|
|
|
+ login["cancel"] = false;
|
|
|
+
|
|
|
+ JsonCommander::Response loginRes = jsonCommander.checkLogin(login);
|
|
|
+ EXPECT_TRUE(loginRes.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(loginRes.json["error"].asString(), "");
|
|
|
+
|
|
|
+ // now the actual test
|
|
|
+ const std::string command = "deleteme";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+ message["pass"] = "negative";
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+
|
|
|
+ EXPECT_EQ(response.action, JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_NE(response.json["error"].asString(), "");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(Deleteme, InvalidRequest) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ // need to set currentUser in jsonCommander via calling checkLogin
|
|
|
+ Json::Value login;
|
|
|
+ login["login"] = true;
|
|
|
+ login["user"] = "positive";
|
|
|
+ login["pass"] = "positive";
|
|
|
+ login["cancel"] = false;
|
|
|
+
|
|
|
+ JsonCommander::Response loginRes = jsonCommander.checkLogin(login);
|
|
|
+ EXPECT_TRUE(loginRes.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(loginRes.json["error"].asString(), "");
|
|
|
+
|
|
|
+ // now the actual test
|
|
|
+ const std::string command = "deleteme";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+ message["pass"] = 123;
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+ EXPECT_EQ(response.action, JsonCommander::Action::closeAndSend);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_NE(response.json["error"].asString(), "");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(DeleteFile, Positive) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "deletefile";
|
|
|
+ const std::string file = "asdf.txt";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+ message["file"] = file;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, deleteFile(file)).WillOnce(testing::Return(FileManager::Error::no_error));
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_EQ(response.json["file"].asString(), file);
|
|
|
+ EXPECT_TRUE(response.json["accept"].asBool());
|
|
|
+ EXPECT_EQ(response.json["error"].asString(), "");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(DeleteFile, InvalidRequest) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "deletefile";
|
|
|
+ const int file = 3641;
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+ message["file"] = file;
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::closeAndSend);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_EQ(response.json["file"].asString(), "");
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(DeleteFile, FileDoesNotExist) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "deletefile";
|
|
|
+ const std::string file = "asdf.txt";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+ message["file"] = file;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, deleteFile(file)).WillOnce(testing::Return(FileManager::Error::no_such_file));
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_EQ(response.json["file"].asString(), file);
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(DeleteFile, DisabledInConfig) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+
|
|
|
+ const std::string command = "deletefile";
|
|
|
+ const std::string file = "asdf.txt";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+ message["file"] = file;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, deleteFile(file)).WillOnce(testing::Return(FileManager::Error::not_allowed));
|
|
|
+
|
|
|
+ JsonCommander::Response response = jsonCommander.execute(message);
|
|
|
+ EXPECT_TRUE(response.action == JsonCommander::Action::send);
|
|
|
+ EXPECT_EQ(response.json["command"].asString(), command);
|
|
|
+ EXPECT_EQ(response.json["file"].asString(), file);
|
|
|
+ EXPECT_FALSE(response.json["accept"].asBool());
|
|
|
+ EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
|
|
|
+}
|
|
|
+
|
|
|
} // namespace
|