Test libpurple backend with prosody

This commit is contained in:
Jan Kaluza 2015-12-21 17:57:29 +01:00
parent 004f941038
commit 05dbf6ce37
10 changed files with 127 additions and 16 deletions

View file

@ -9,8 +9,9 @@ before_script:
- curl -k https://swift.im/keys/packages.key | sudo apt-key add -
- echo "deb http://swift.im/packages/ubuntu/trusty development main" | sudo tee -a /etc/apt/sources.list
- echo "deb http://packages.spectrum.im/spectrum2/ trusty main" | sudo tee -a /etc/apt/sources.list
- echo " deb http://packages.prosody.im/debian trusty main" | sudo tee -a /etc/apt/sources.list
- sudo apt-get update -qq
- sudo apt-get install -y --force-yes ngircd python-sleekxmpp libswiften-dev libprotobuf-dev protobuf-compiler pidgin-dev liblog4cxx10-dev libpopt-dev libboost-dev libboost-signals-dev libboost-system-dev libboost-thread-dev libboost-filesystem-dev libboost-program-options-dev libboost-regex-dev libboost-date-time-dev libcppunit-dev libcommuni-dev
- sudo apt-get install -y --force-yes prosody ngircd python-sleekxmpp libswiften-dev libprotobuf-dev protobuf-compiler pidgin-dev liblog4cxx10-dev libpopt-dev libboost-dev libboost-signals-dev libboost-system-dev libboost-thread-dev libboost-filesystem-dev libboost-program-options-dev libboost-regex-dev libboost-date-time-dev libcppunit-dev libcommuni-dev
install: "pip install --user sleekxmpp"
script:
- cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON . && make && ./src/libtransport_test && cd ./spectrum/src/tests && python -V && python start.py

View file

@ -1124,10 +1124,14 @@ static void conv_write_im(PurpleConversation *conv, const char *who, const char
if (purple_conversation_get_type_wrapped(conv) == PURPLE_CONV_TYPE_IM) {
std::string w = purple_normalize_wrapped(account, who);
std::string n;
size_t pos = w.find("/");
if (pos != std::string::npos)
if (pos != std::string::npos) {
n = w.substr((int) pos + 1, w.length() - (int) pos);
w.erase((int) pos, w.length() - (int) pos);
np->handleMessage(np->m_accounts[account], w, message_, "", xhtml_, timestamp);
}
LOG4CXX_INFO(logger, "Received message body='" << message_ << "' name='" << w);
np->handleMessage(np->m_accounts[account], w, message_, n, xhtml_, timestamp);
}
else {
LOG4CXX_INFO(logger, "Received message body='" << message_ << "' name='" << purple_conversation_get_name_wrapped(conv) << "' " << who);

View file

@ -2,7 +2,7 @@
jid = localhost
password = secret
server = 127.0.0.1
port = 5222
port = 5223
server_mode = 1
backend_host=127.0.0.1
pidfile=./test.pid

View file

@ -2,7 +2,7 @@
jid = localhost
password = secret
server = 127.0.0.1
port = 5222
port = 5223
server_mode = 1
backend_host=127.0.0.1
pidfile=./test.pid

View file

@ -0,0 +1,44 @@
[service]
jid = localhostxmpp
password = secret
server = 0.0.0.0
port = 5223
server_mode = 1
backend_host=127.0.0.1
pidfile=./test.pid
# < this option doesn't work yet
#backend_port=10001
admin_jid=admin
admin_password=test
#cert=server.pfx #patch to PKCS#12 certificate
#cert_password=test #password to that certificate if any
users_per_backend=10
#backend=../..//backends/swiften/spectrum2_swiften_backend
#backend=../../../backends/twitter/spectrum2_twitter_backend
backend=../../../backends/libpurple/spectrum2_libpurple_backend
protocol=prpl-jabber
#protocol=prpl-msn
#protocol=any
#protocol=prpl-icq
working_dir=./
portfile=./$jid.port
irc_server=localhost
[backend]
#default_avatar=catmelonhead.jpg
#no_vcard_fetch=true
[logging]
#config=logging.cfg # log4cxx/log4j logging configuration file
#backend_config=/home/hanzz/code/libtransport/spectrum/src/backend-logging.cfg # log4cxx/log4j logging configuration file for backends
[database]
type=sqlite3 # or "none" without database backend
database=users.sqlite
prefix=twitter
#type = mysql # or "none" without database backend.......................................................................................................................
#database = test
#prefix=
#user=root
#password=yourrootsqlpassword
#encryption_key=hanzzik

View file

@ -0,0 +1,3 @@
return {
["password"] = "password";
};

View file

@ -0,0 +1,3 @@
return {
["password"] = "password";
};

View file

@ -0,0 +1,9 @@
[service]
admin_username=admin
admin_password=test
config_directory=./
[servers]
server=localhostxmpp
#server=icq.spectrum.im
#server=msn.spectrum.im

View file

@ -7,30 +7,49 @@ import os
import sleekxmpp
import imp
def registerXMPPAccount(user, password):
responder = sleekxmpp.ClientXMPP(user, password)
responder.register_plugin('xep_0030') # Service Discovery
responder.register_plugin('xep_0077')
responder['feature_mechanisms'].unencrypted_plain = True
if responder.connect(("127.0.0.1", 5222)):
responder.process(block=False)
else:
print "connect() failed"
sys.exit(1)
class BaseTest:
def __init__(self, config, server_mode, room):
self.config = config
self.server_mode = server_mode
self.room = room
self.responder_jid = "responder@localhost"
self.client_jid = "client@localhost"
def skip_test(self, test):
return False
def start(self, Client, Responder):
self.pre_test()
os.system("../spectrum2 -n ./" + self.config + " > spectrum2.log &")
self.pre_test()
time.sleep(1)
responder = Responder("responder@localhost", "password", self.room, "responder")
responder = Responder(self.responder_jid, "password", self.room, "responder")
responder.register_plugin('xep_0030') # Service Discovery
responder.register_plugin('xep_0045') # Multi-User Chat
responder.register_plugin('xep_0199') # XMPP Ping
responder['feature_mechanisms'].unencrypted_plain = True
if responder.connect():
if responder.connect(("127.0.0.1", 5223)):
responder.process(block=False)
else:
print "connect() failed"
os.system("killall spectrum2")
self.post_test()
sys.exit(1)
client = Client("client@localhost", "password", self.room, "client")
client = Client(self.client_jid, "password", self.room, "client")
client.register_plugin('xep_0030') # Service Discovery
client.register_plugin('xep_0045') # Multi-User Chat
client.register_plugin('xep_0199') # XMPP Ping
@ -38,10 +57,12 @@ class BaseTest:
time.sleep(2)
if client.connect():
if client.connect(("127.0.0.1", 5223)):
client.process(block=False)
else:
print "connect() failed"
os.system("killall spectrum2")
self.post_test()
sys.exit(1)
max_time = 60
@ -92,9 +113,31 @@ class LibcommuniServerModeConf(BaseTest):
os.system("killall ngircd 2>/dev/null")
os.system("killall spectrum2_libcommuni_backend 2>/dev/null")
class JabberServerModeConf(BaseTest):
def __init__(self):
BaseTest.__init__(self, "jabber_test.cfg", True, "room%conference.localhost@localhostxmpp")
self.client_jid = "client%localhost@localhostxmpp"
self.responder_jid = "responder%localhost@localhostxmpp"
def skip_test(self, test):
if test in ["muc_whois.py", "muc_change_topic.py"]:
return True
return False
def pre_test(self):
os.system("prosody --config prosody.cfg.lua >prosody.log &")
time.sleep(3)
os.system("../../../spectrum_manager/src/spectrum2_manager -c manager.conf localhostxmpp register client%localhost@localhostxmpp client@localhost password 2>/dev/null >/dev/null")
os.system("../../../spectrum_manager/src/spectrum2_manager -c manager.conf localhostxmpp register responder%localhost@localhostxmpp responder@localhost password 2>/dev/null >/dev/null")
def post_test(self):
os.system("killall lua-5.1 2>/dev/null")
os.system("killall spectrum2_libpurple_backend 2>/dev/null")
configurations = []
configurations.append(LibcommuniServerModeSingleServerConf())
configurations.append(LibcommuniServerModeConf())
#configurations.append(LibcommuniServerModeSingleServerConf())
#configurations.append(LibcommuniServerModeConf())
configurations.append(JabberServerModeConf())
exitcode = 0
@ -108,10 +151,13 @@ for conf in configurations:
print conf.__class__.__name__ + ": Starting " + f + " test ..."
test = imp.load_source('test', './' + f)
try:
ret = conf.start(test.Client, test.Responder)
except:
ret = False
if conf.skip_test(f):
print "Skipped."
continue
#try:
ret = conf.start(test.Client, test.Responder)
#except:
#ret = False
if not ret:
exitcode = -1

View file

@ -60,6 +60,7 @@ User::User(const Swift::JID &jid, UserInfo &userInfo, Component *component, User
m_ignoreDisconnect = false;
m_resources = 0;
m_reconnectCounter = 0;
m_reconnectLimit = 3;
m_reconnectTimer = m_component->getNetworkFactories()->getTimerFactory()->createTimer(5000);
m_reconnectTimer->onTick.connect(boost::bind(&User::onConnectingTimeout, this));