Files
@ 7ebbe408b160
Branch filter:
Location: libtransport.git/tests/libtransport/AdminInterface.cpp
7ebbe408b160
4.8 KiB
text/x-c++hdr
Docker image: updates purple-facebook (#191)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | #include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <Swiften/Swiften.h>
#include <Swiften/EventLoop/DummyEventLoop.h>
#include <Swiften/Server/Server.h>
#include <Swiften/Network/DummyNetworkFactories.h>
#include <Swiften/Network/DummyConnectionServer.h>
#include "Swiften/SwiftenCompat.h"
#include "Swiften/Server/ServerStanzaChannel.h"
#include "Swiften/Server/ServerFromClientSession.h"
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
#include "BasicSlackTest.h"
#include "transport/AdminInterface.h"
#if !HAVE_SWIFTEN_3
#define get_value_or(X) substr()
#endif
using namespace Transport;
class AdminInterfaceTest : public CPPUNIT_NS :: TestFixture, public BasicSlackTest {
CPPUNIT_TEST_SUITE(AdminInterfaceTest);
CPPUNIT_TEST(helpCommand);
CPPUNIT_TEST(statusCommand);
CPPUNIT_TEST(joinRoomArgs);
CPPUNIT_TEST(getOAuth2URLCommand);
CPPUNIT_TEST(unknownCommand);
CPPUNIT_TEST(listJoinLeaveRoomsCommand);
CPPUNIT_TEST(badArgCount);
CPPUNIT_TEST(commandsCommand);
CPPUNIT_TEST(variablesCommand);
CPPUNIT_TEST_SUITE_END();
public:
AdminInterface *admin;
NetworkPluginServer *serv;
void setUp (void) {
setMeUp();
serv = new NetworkPluginServer(component, cfg, userManager, NULL);
admin = new AdminInterface(component, userManager, serv, storage, NULL);
component->setAdminInterface(admin);
}
void tearDown (void) {
delete admin;
delete serv;
tearMeDown();
}
std::string sendAdminMessage(const std::string &cmd) {
Swift::Message::ref msg = SWIFTEN_SHRPTR_NAMESPACE::shared_ptr<Swift::Message>(new Swift::Message());
msg->setFrom(Swift::JID("me@localhost"));
msg->setTo(Swift::JID("localhost"));
msg->setBody(cmd);
admin->handleMessageReceived(msg);
return msg->getBody().get_value_or("");
}
void helpCommand() {
std::string resp = sendAdminMessage("help");
CPPUNIT_ASSERT(resp.find(" VAR status - Shows instance status\n") != std::string::npos);
}
void statusCommand() {
std::string resp = sendAdminMessage("status");
CPPUNIT_ASSERT_EQUAL(std::string("Running (0 users connected using 0 backends)"), resp);
}
void joinRoomArgs() {
std::string resp = sendAdminMessage("args join_room");
CPPUNIT_ASSERT_EQUAL(std::string("nickname - \"Nickname in 3rd-party room\" Example: \"BotNickname\" Type: \"string\"\n"
"legacy_room - \"3rd-party room name\" Example: \"3rd-party room name\" Type: \"string\"\n"
"legacy_server - \"3rd-party server\" Example: \"3rd.party.server.org\" Type: \"string\"\n"
"slack_channel - \"Slack Chanel\" Example: \"mychannel\" Type: \"string\"\n"), resp);
}
void getOAuth2URLCommand() {
std::string resp = sendAdminMessage("get_oauth2_url x y z");
CPPUNIT_ASSERT(resp.find("https://slack.com/oauth/authorize?client_id=&scope=channels%3Aread%20channels%3Awrite%20team%3Aread%20im%3Aread%20im%3Awrite%20chat%3Awrite%3Abot%20bot&redirect_uri=https%3A%2F%2Fslack.spectrum.im%2Foauth2%2Flocalhost&state=") != std::string::npos);
}
void unknownCommand() {
std::string resp = sendAdminMessage("unknown_command test");
CPPUNIT_ASSERT_EQUAL(std::string("Error: Unknown variable or command"), resp);
}
void listJoinLeaveRoomsCommand() {
addUser();
std::string resp = sendAdminMessage("list_rooms user@localhost");
CPPUNIT_ASSERT_EQUAL(std::string(""), resp);
resp = sendAdminMessage("join_room user@localhost SlackBot spectrum conference.spectrum.im slack_channel");
CPPUNIT_ASSERT_EQUAL(std::string("Joined the room"), resp);
resp = sendAdminMessage("list_rooms user@localhost");
CPPUNIT_ASSERT_EQUAL(std::string("connected room SlackBot spectrum conference.spectrum.im slack_channel\n"), resp);
resp = sendAdminMessage("leave_room user@localhost slack_channel");
CPPUNIT_ASSERT_EQUAL(std::string("Left the room"), resp);
resp = sendAdminMessage("list_rooms user@localhost");
CPPUNIT_ASSERT_EQUAL(std::string(""), resp);
}
void badArgCount() {
addUser();
std::string resp;
resp = sendAdminMessage("join_room user@localhost SlackBot spectrum conference.spectrum.im slack_channel unknown");
CPPUNIT_ASSERT_EQUAL(std::string("Error: Too many arguments."), resp);
resp = sendAdminMessage("join_room user@localhost SlackBot spectrum conference.spectrum.im");
CPPUNIT_ASSERT_EQUAL(std::string("Error: Argument is missing."), resp);
}
void commandsCommand() {
addUser();
std::string resp;
resp = sendAdminMessage("commands");
CPPUNIT_ASSERT(resp.find("join_room - \"Join the room\" Category: Frontend AccesMode: User Context: User") != std::string::npos);
}
void variablesCommand() {
addUser();
std::string resp;
resp = sendAdminMessage("variables");
CPPUNIT_ASSERT(resp.find("backends_count - \"Number of active backends\" Value: \"0\" Read-only: true") != std::string::npos);
}
};
CPPUNIT_TEST_SUITE_REGISTRATION (AdminInterfaceTest);
|