|
@@ -1,8 +1,11 @@
|
|
|
#include <gmock/gmock.h>
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
+#include "../include/Config.h"
|
|
|
#include "../include/JsonCommander.h"
|
|
|
#include "../include/Notifications.h"
|
|
|
+#include "../include/Queue.h"
|
|
|
+#include "ChannelControlsMock.h"
|
|
|
#include "FileManagerMock.h"
|
|
|
|
|
|
namespace {
|
|
@@ -1197,6 +1200,230 @@ TEST(DeleteFile, DisabledInConfig) {
|
|
|
EXPECT_TRUE(response.json["error"].asString().compare("") != 0);
|
|
|
}
|
|
|
|
|
|
+TEST(ExtendedStatus, NoUploadOrDownload) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+ ChannelControlsMock channelControls;
|
|
|
+ Queue::channel = &channelControls;
|
|
|
+ Queue::queue.clear();
|
|
|
+
|
|
|
+ const std::string command = "extendedstatus";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, isUploading()).WillOnce(testing::Return(false));
|
|
|
+ EXPECT_CALL(fileManager, isDownloading()).WillOnce(testing::Return(false));
|
|
|
+ EXPECT_CALL(channelControls, isTransferRunning()).WillOnce(testing::Return(false));
|
|
|
+
|
|
|
+ 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["error"].asString(), "");
|
|
|
+ EXPECT_TRUE(response.json["transfersclientserver"].isNull());
|
|
|
+ EXPECT_TRUE(response.json["transfersserverserver"].isNull());
|
|
|
+}
|
|
|
+
|
|
|
+TEST(ExtendedStatus, ClientServerDownload) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+ ChannelControlsMock channelControls;
|
|
|
+ Queue::channel = &channelControls;
|
|
|
+ Queue::queue.clear();
|
|
|
+
|
|
|
+ const std::string command = "extendedstatus";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, isUploading()).WillOnce(testing::Return(false));
|
|
|
+ EXPECT_CALL(fileManager, isDownloading()).WillOnce(testing::Return(true));
|
|
|
+ EXPECT_CALL(fileManager, getGetBaseFileName()).WillOnce(testing::Return("asdf"));
|
|
|
+ EXPECT_CALL(channelControls, isTransferRunning()).WillOnce(testing::Return(false));
|
|
|
+
|
|
|
+ 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["error"].asString(), "");
|
|
|
+ EXPECT_EQ(response.json["transfersclientserver"].size(), 1);
|
|
|
+ EXPECT_FALSE(response.json["transfersclientserver"][0]["upload"].asBool());
|
|
|
+ EXPECT_EQ(response.json["transfersclientserver"][0]["file"].asString(), "asdf");
|
|
|
+ EXPECT_EQ(response.json["transfersclientserver"][0]["progress"].asInt(), 0);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(ExtendedStatus, ClientServerUpload) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+ ChannelControlsMock channelControls;
|
|
|
+ Queue::channel = &channelControls;
|
|
|
+ Queue::queue.clear();
|
|
|
+
|
|
|
+ const std::string command = "extendedstatus";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, isUploading()).WillOnce(testing::Return(true));
|
|
|
+ EXPECT_CALL(fileManager, isDownloading()).WillOnce(testing::Return(false));
|
|
|
+ EXPECT_CALL(fileManager, getPutBaseFileName()).WillOnce(testing::Return("asdf"));
|
|
|
+ EXPECT_CALL(channelControls, isTransferRunning()).WillOnce(testing::Return(false));
|
|
|
+
|
|
|
+ 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["error"].asString(), "");
|
|
|
+ EXPECT_EQ(response.json["transfersclientserver"].size(), 1);
|
|
|
+ EXPECT_TRUE(response.json["transfersclientserver"][0]["upload"].asBool());
|
|
|
+ EXPECT_EQ(response.json["transfersclientserver"][0]["file"].asString(), "asdf");
|
|
|
+ EXPECT_EQ(response.json["transfersclientserver"][0]["progress"].asInt(), 0);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(ExtendedStatus, ClientServerDonwloadAndUpload) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+ ChannelControlsMock channelControls;
|
|
|
+ Queue::channel = &channelControls;
|
|
|
+ Queue::queue.clear();
|
|
|
+
|
|
|
+ const std::string command = "extendedstatus";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, isUploading()).WillOnce(testing::Return(true));
|
|
|
+ EXPECT_CALL(fileManager, isDownloading()).WillOnce(testing::Return(true));
|
|
|
+ EXPECT_CALL(fileManager, getGetBaseFileName()).WillOnce(testing::Return("asdfGet"));
|
|
|
+ EXPECT_CALL(fileManager, getPutBaseFileName()).WillOnce(testing::Return("asdfPut"));
|
|
|
+ EXPECT_CALL(channelControls, isTransferRunning()).WillOnce(testing::Return(false));
|
|
|
+
|
|
|
+ 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["error"].asString(), "");
|
|
|
+ EXPECT_EQ(response.json["transfersclientserver"].size(), 2);
|
|
|
+ EXPECT_TRUE(response.json["transfersclientserver"][0]["upload"].asBool());
|
|
|
+ EXPECT_EQ(response.json["transfersclientserver"][0]["file"].asString(), "asdfPut");
|
|
|
+ EXPECT_EQ(response.json["transfersclientserver"][0]["progress"].asInt(), 0);
|
|
|
+ EXPECT_FALSE(response.json["transfersclientserver"][1]["upload"].asBool());
|
|
|
+ EXPECT_EQ(response.json["transfersclientserver"][1]["file"].asString(), "asdfGet");
|
|
|
+ EXPECT_EQ(response.json["transfersclientserver"][1]["progress"].asInt(), 0);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(ExtendedStatus, ServerServerDownload) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+ ChannelControlsMock channelControls;
|
|
|
+ Queue::channel = &channelControls;
|
|
|
+ Queue::queue.clear();
|
|
|
+ Queue::curTransfer = "a.txt";
|
|
|
+ Config::storage.clear();
|
|
|
+ Config::storage.insert(std::pair<std::string, std::string>("passiveMode", "true"));
|
|
|
+ Config::storage.insert(std::pair<std::string, std::string>("covertChannelMode", "m"));
|
|
|
+
|
|
|
+ const std::string command = "extendedstatus";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, isUploading()).WillOnce(testing::Return(false));
|
|
|
+ EXPECT_CALL(fileManager, isDownloading()).WillOnce(testing::Return(false));
|
|
|
+ EXPECT_CALL(channelControls, isTransferRunning()).WillOnce(testing::Return(true));
|
|
|
+ EXPECT_CALL(channelControls, getProgress()).WillOnce(testing::Return(std::pair<int, int>(1, 2)));
|
|
|
+ EXPECT_CALL(channelControls, getTransferStart()).WillOnce(testing::Return(0));
|
|
|
+
|
|
|
+ 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["error"].asString(), "");
|
|
|
+ EXPECT_EQ(response.json["transfersclientserver"].size(), 0);
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"].size(), 1);
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][0]["type"].asString(), "download");
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][0]["file"].asString(), "a.txt");
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][0]["progress"].asInt(), 50);
|
|
|
+ EXPECT_TRUE(response.json["transfersserverserver"][0]["speed"].isDouble());
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][0]["method"].asString(), "m");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(ExtendedStatus, ServerServerUpload) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+ ChannelControlsMock channelControls;
|
|
|
+ Queue::channel = &channelControls;
|
|
|
+ Queue::queue.clear();
|
|
|
+ Queue::curTransfer = "a.txt";
|
|
|
+ Config::storage.clear();
|
|
|
+ Config::storage.insert(std::pair<std::string, std::string>("passiveMode", "false"));
|
|
|
+ Config::storage.insert(std::pair<std::string, std::string>("covertChannelMode", "m"));
|
|
|
+
|
|
|
+ const std::string command = "extendedstatus";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, isUploading()).WillOnce(testing::Return(false));
|
|
|
+ EXPECT_CALL(fileManager, isDownloading()).WillOnce(testing::Return(false));
|
|
|
+ EXPECT_CALL(channelControls, isTransferRunning()).WillOnce(testing::Return(true));
|
|
|
+ EXPECT_CALL(channelControls, getProgress()).WillOnce(testing::Return(std::pair<int, int>(1, 2)));
|
|
|
+ EXPECT_CALL(channelControls, getTransferStart()).WillOnce(testing::Return(0));
|
|
|
+
|
|
|
+ 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["error"].asString(), "");
|
|
|
+ EXPECT_EQ(response.json["transfersclientserver"].size(), 0);
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"].size(), 1);
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][0]["type"].asString(), "upload");
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][0]["file"].asString(), "a.txt");
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][0]["progress"].asInt(), 50);
|
|
|
+ EXPECT_TRUE(response.json["transfersserverserver"][0]["speed"].isDouble());
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][0]["method"].asString(), "m");
|
|
|
+}
|
|
|
+
|
|
|
+TEST(ExtendedStatus, QueueNotEmpty) {
|
|
|
+ FileManagerMock fileManager;
|
|
|
+ JsonCommander jsonCommander(fileManager);
|
|
|
+ ChannelControlsMock channelControls;
|
|
|
+ Queue::channel = &channelControls;
|
|
|
+ Queue::queue.clear();
|
|
|
+ Queue::queue.push_back("a");
|
|
|
+ Queue::queue.push_back("b");
|
|
|
+ Config::storage.clear();
|
|
|
+ Config::storage.insert(std::pair<std::string, std::string>("covertChannelMode", "m"));
|
|
|
+
|
|
|
+ const std::string command = "extendedstatus";
|
|
|
+
|
|
|
+ Json::Value message;
|
|
|
+ message["command"] = command;
|
|
|
+
|
|
|
+ EXPECT_CALL(fileManager, isUploading()).WillOnce(testing::Return(false));
|
|
|
+ EXPECT_CALL(fileManager, isDownloading()).WillOnce(testing::Return(false));
|
|
|
+ EXPECT_CALL(channelControls, isTransferRunning()).WillOnce(testing::Return(false));
|
|
|
+
|
|
|
+ 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["error"].asString(), "");
|
|
|
+ EXPECT_EQ(response.json["transfersclientserver"].size(), 0);
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"].size(), 2);
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][0]["type"], "queued");
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][0]["file"], "a");
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][0]["progress"], 0);
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][0]["speed"], 0);
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][0]["method"], "m");
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][1]["type"], "queued");
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][1]["file"], "b");
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][1]["progress"], 0);
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][1]["speed"], 0);
|
|
|
+ EXPECT_EQ(response.json["transfersserverserver"][1]["method"], "m");
|
|
|
+}
|
|
|
+
|
|
|
TEST(Notifications, NoMessage) {
|
|
|
FileManagerMock fileManager;
|
|
|
|