2015-12-16 09:40:01 +01:00
|
|
|
import optparse
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import subprocess
|
|
|
|
import os
|
|
|
|
|
|
|
|
import sleekxmpp
|
|
|
|
import imp
|
2016-02-26 06:57:02 +01:00
|
|
|
import logging
|
|
|
|
|
|
|
|
#logging.basicConfig(level=logging.DEBUG,
|
|
|
|
#format='%(levelname)-8s %(message)s')
|
2015-12-16 09:40:01 +01:00
|
|
|
|
2015-12-21 17:57:29 +01:00
|
|
|
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)
|
|
|
|
|
2015-12-17 10:07:56 +01:00
|
|
|
class BaseTest:
|
|
|
|
def __init__(self, config, server_mode, room):
|
|
|
|
self.config = config
|
|
|
|
self.server_mode = server_mode
|
|
|
|
self.room = room
|
2015-12-21 17:57:29 +01:00
|
|
|
self.responder_jid = "responder@localhost"
|
|
|
|
self.client_jid = "client@localhost"
|
2015-12-22 18:05:48 +01:00
|
|
|
self.responder_password = "password"
|
|
|
|
self.client_password = "password"
|
|
|
|
self.client_room = room
|
|
|
|
self.responder_room = room
|
|
|
|
self.client_nick = "client"
|
|
|
|
self.responder_nick = "responder"
|
|
|
|
self.responder_roompassword = ""
|
2015-12-21 17:57:29 +01:00
|
|
|
|
|
|
|
def skip_test(self, test):
|
|
|
|
return False
|
2015-12-17 10:07:56 +01:00
|
|
|
|
|
|
|
def start(self, Client, Responder):
|
2015-12-24 10:08:19 +01:00
|
|
|
os.system("../../spectrum/src/spectrum2 -n ./" + self.config + " > spectrum2.log &")
|
2015-12-21 17:57:29 +01:00
|
|
|
self.pre_test()
|
2015-12-16 09:40:01 +01:00
|
|
|
time.sleep(1)
|
2015-12-17 10:07:56 +01:00
|
|
|
|
2015-12-22 18:05:48 +01:00
|
|
|
responder = Responder(self.responder_jid, self.responder_password, self.responder_room, self.responder_roompassword, self.responder_nick)
|
2015-12-17 10:07:56 +01:00
|
|
|
responder.register_plugin('xep_0030') # Service Discovery
|
|
|
|
responder.register_plugin('xep_0045') # Multi-User Chat
|
|
|
|
responder.register_plugin('xep_0199') # XMPP Ping
|
2016-02-04 08:09:37 +01:00
|
|
|
responder.register_plugin('xep_0153')
|
|
|
|
responder.register_plugin('xep_0054')
|
2015-12-17 10:07:56 +01:00
|
|
|
responder['feature_mechanisms'].unencrypted_plain = True
|
|
|
|
|
2015-12-22 18:05:48 +01:00
|
|
|
to = ("127.0.0.1", 5223)
|
|
|
|
if self.responder_password != "password":
|
|
|
|
to = ()
|
|
|
|
if responder.connect(to):
|
2015-12-17 10:07:56 +01:00
|
|
|
responder.process(block=False)
|
2015-12-16 09:40:01 +01:00
|
|
|
else:
|
2015-12-17 10:07:56 +01:00
|
|
|
print "connect() failed"
|
2015-12-21 17:57:29 +01:00
|
|
|
os.system("killall spectrum2")
|
|
|
|
self.post_test()
|
2015-12-17 10:07:56 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
2015-12-22 18:05:48 +01:00
|
|
|
client = Client(self.client_jid, self.client_password, self.client_room, self.client_nick)
|
2015-12-17 10:07:56 +01:00
|
|
|
client.register_plugin('xep_0030') # Service Discovery
|
|
|
|
client.register_plugin('xep_0045') # Multi-User Chat
|
|
|
|
client.register_plugin('xep_0199') # XMPP Ping
|
2016-02-04 08:09:37 +01:00
|
|
|
client.register_plugin('xep_0153')
|
|
|
|
client.register_plugin('xep_0054')
|
2015-12-17 10:07:56 +01:00
|
|
|
client['feature_mechanisms'].unencrypted_plain = True
|
|
|
|
|
2016-02-26 06:57:02 +01:00
|
|
|
time.sleep(1)
|
2015-12-17 10:07:56 +01:00
|
|
|
|
2015-12-22 18:05:48 +01:00
|
|
|
to = ("127.0.0.1", 5223)
|
|
|
|
if self.responder_password != "password":
|
|
|
|
to = ("127.0.0.1", 5222)
|
|
|
|
if client.connect(to):
|
2015-12-17 10:07:56 +01:00
|
|
|
client.process(block=False)
|
|
|
|
else:
|
|
|
|
print "connect() failed"
|
2015-12-21 17:57:29 +01:00
|
|
|
os.system("killall spectrum2")
|
|
|
|
self.post_test()
|
2015-12-17 10:07:56 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
2016-02-26 06:57:02 +01:00
|
|
|
|
2015-12-17 10:07:56 +01:00
|
|
|
max_time = 60
|
|
|
|
while not client.finished and not responder.finished and max_time > 0:
|
|
|
|
time.sleep(1)
|
|
|
|
max_time -= 1
|
|
|
|
client.disconnect()
|
|
|
|
responder.disconnect()
|
|
|
|
|
|
|
|
os.system("killall spectrum2")
|
|
|
|
self.post_test()
|
|
|
|
|
|
|
|
ret = True
|
|
|
|
tests = []
|
|
|
|
tests += client.tests.values()
|
|
|
|
tests += responder.tests.values()
|
|
|
|
for v in tests:
|
|
|
|
if v[1]:
|
|
|
|
print v[0] + ": PASSED"
|
|
|
|
else:
|
|
|
|
print v[0] + ": FAILED"
|
|
|
|
ret = False
|
2015-12-16 09:40:01 +01:00
|
|
|
|
2015-12-17 10:07:56 +01:00
|
|
|
if not ret:
|
|
|
|
os.system("cat spectrum2.log")
|
2015-12-16 09:40:01 +01:00
|
|
|
|
2015-12-17 10:07:56 +01:00
|
|
|
return ret
|
|
|
|
|
|
|
|
class LibcommuniServerModeSingleServerConf(BaseTest):
|
|
|
|
def __init__(self):
|
2015-12-24 10:08:19 +01:00
|
|
|
BaseTest.__init__(self, "../libcommuni/irc_test.cfg", True, "#channel@localhost")
|
|
|
|
self.directory = "../libcommuni/"
|
2015-12-17 10:07:56 +01:00
|
|
|
|
2016-02-26 06:57:02 +01:00
|
|
|
def skip_test(self, test):
|
|
|
|
if test in ["muc_join_nickname_used.py"]:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2015-12-17 10:07:56 +01:00
|
|
|
def pre_test(self):
|
2015-12-24 10:08:19 +01:00
|
|
|
os.system("ngircd -f ../libcommuni/ngircd.conf &")
|
2015-12-17 10:07:56 +01:00
|
|
|
|
|
|
|
def post_test(self):
|
|
|
|
os.system("killall ngircd 2>/dev/null")
|
|
|
|
os.system("killall spectrum2_libcommuni_backend 2>/dev/null")
|
|
|
|
|
|
|
|
class LibcommuniServerModeConf(BaseTest):
|
|
|
|
def __init__(self):
|
2015-12-24 10:08:19 +01:00
|
|
|
BaseTest.__init__(self, "../libcommuni/irc_test2.cfg", True, "#channel%localhost@localhost")
|
|
|
|
self.directory = "../libcommuni/"
|
2015-12-17 10:07:56 +01:00
|
|
|
|
|
|
|
def pre_test(self):
|
2015-12-24 10:08:19 +01:00
|
|
|
os.system("ngircd -f ../libcommuni/ngircd.conf &")
|
2015-12-17 10:07:56 +01:00
|
|
|
|
|
|
|
def post_test(self):
|
|
|
|
os.system("killall ngircd 2>/dev/null")
|
|
|
|
os.system("killall spectrum2_libcommuni_backend 2>/dev/null")
|
|
|
|
|
2015-12-21 17:57:29 +01:00
|
|
|
class JabberServerModeConf(BaseTest):
|
|
|
|
def __init__(self):
|
2015-12-24 10:08:19 +01:00
|
|
|
BaseTest.__init__(self, "../libpurple_jabber/jabber_test.cfg", True, "room%conference.localhost@localhostxmpp")
|
|
|
|
self.directory = "../libpurple_jabber/"
|
2015-12-21 17:57:29 +01:00
|
|
|
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):
|
2015-12-24 10:08:19 +01:00
|
|
|
os.system("prosody --config ../libpurple_jabber/prosody.cfg.lua >prosody.log &")
|
2015-12-21 17:57:29 +01:00
|
|
|
time.sleep(3)
|
2015-12-24 10:08:19 +01:00
|
|
|
os.system("../../spectrum_manager/src/spectrum2_manager -c ../libpurple_jabber/manager.conf localhostxmpp register client%localhost@localhostxmpp client@localhost password 2>/dev/null >/dev/null")
|
|
|
|
os.system("../../spectrum_manager/src/spectrum2_manager -c ../libpurple_jabber/manager.conf localhostxmpp register responder%localhost@localhostxmpp responder@localhost password 2>/dev/null >/dev/null")
|
2015-12-21 17:57:29 +01:00
|
|
|
|
|
|
|
def post_test(self):
|
|
|
|
os.system("killall lua-5.1 2>/dev/null")
|
|
|
|
os.system("killall spectrum2_libpurple_backend 2>/dev/null")
|
|
|
|
|
2015-12-22 18:05:48 +01:00
|
|
|
class JabberSlackServerModeConf(BaseTest):
|
|
|
|
def __init__(self):
|
2015-12-24 10:08:19 +01:00
|
|
|
BaseTest.__init__(self, "../slack_jabber/jabber_slack_test.cfg", True, "room%conference.localhost@localhostxmpp")
|
|
|
|
self.directory = "../slack_jabber/"
|
2015-12-22 18:05:48 +01:00
|
|
|
self.client_jid = "client@localhost"
|
|
|
|
self.client_room = "room@conference.localhost"
|
|
|
|
self.responder_jid = "owner@spectrum2tests.xmpp.slack.com"
|
2015-12-29 10:18:31 +01:00
|
|
|
self.responder_password = "spectrum2tests.e2zJwtKjLhLmt14VsMKq"
|
2015-12-22 18:05:48 +01:00
|
|
|
self.responder_room = "spectrum2_room@conference.spectrum2tests.xmpp.slack.com"
|
|
|
|
self.responder_nick = "owner"
|
2015-12-29 10:18:31 +01:00
|
|
|
self.responder_roompassword = "spectrum2tests.e2zJwtKjLhLmt14VsMKq"
|
2015-12-22 18:05:48 +01:00
|
|
|
|
|
|
|
def skip_test(self, test):
|
2015-12-24 12:19:07 +01:00
|
|
|
os.system("cp ../slack_jabber/slack.sql .")
|
2015-12-24 15:44:25 +01:00
|
|
|
if test.find("bad_password") != -1:
|
|
|
|
print "Changing password to 'badpassword'"
|
|
|
|
os.system("sqlite3 slack.sql \"UPDATE users SET password='badpassword' WHERE id=1\"")
|
2015-12-22 18:05:48 +01:00
|
|
|
return False
|
|
|
|
|
|
|
|
def pre_test(self):
|
2015-12-24 10:08:19 +01:00
|
|
|
os.system("prosody --config ../slack_jabber/prosody.cfg.lua > prosody.log &")
|
2015-12-22 18:05:48 +01:00
|
|
|
|
|
|
|
def post_test(self):
|
|
|
|
os.system("killall lua-5.1 2>/dev/null")
|
|
|
|
os.system("killall spectrum2_libpurple_backend 2>/dev/null")
|
|
|
|
|
2015-12-27 16:31:00 +01:00
|
|
|
class TwitterServerModeConf(BaseTest):
|
|
|
|
def __init__(self):
|
|
|
|
BaseTest.__init__(self, "../twitter/twitter_test.cfg", True, "")
|
|
|
|
self.directory = "../twitter/"
|
|
|
|
self.client_password = "testpass123"
|
|
|
|
|
|
|
|
def skip_test(self, test):
|
|
|
|
os.system("cp ../twitter/twitter.sql .")
|
|
|
|
|
|
|
|
def pre_test(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def post_test(self):
|
|
|
|
os.system("killall spectrum2_twitter_backend 2>/dev/null")
|
|
|
|
|
2015-12-17 10:07:56 +01:00
|
|
|
configurations = []
|
2015-12-21 19:13:21 +01:00
|
|
|
configurations.append(LibcommuniServerModeSingleServerConf())
|
|
|
|
configurations.append(LibcommuniServerModeConf())
|
2016-02-28 11:42:05 +01:00
|
|
|
#configurations.append(JabberServerModeConf())
|
2016-02-26 06:57:02 +01:00
|
|
|
##configurations.append(JabberSlackServerModeConf())
|
|
|
|
#configurations.append(TwitterServerModeConf())
|
2015-12-16 09:40:01 +01:00
|
|
|
|
|
|
|
exitcode = 0
|
2015-12-17 10:07:56 +01:00
|
|
|
|
|
|
|
for conf in configurations:
|
2015-12-24 10:08:19 +01:00
|
|
|
for f in os.listdir(conf.directory):
|
2015-12-17 10:07:56 +01:00
|
|
|
if not f.endswith(".py") or f == "start.py":
|
|
|
|
continue
|
|
|
|
|
2015-12-17 18:25:26 +01:00
|
|
|
if len(sys.argv) == 2 and sys.argv[1] != f:
|
|
|
|
continue
|
|
|
|
|
2015-12-17 10:07:56 +01:00
|
|
|
print conf.__class__.__name__ + ": Starting " + f + " test ..."
|
2015-12-24 10:08:19 +01:00
|
|
|
test = imp.load_source('test', conf.directory + f)
|
2015-12-21 17:57:29 +01:00
|
|
|
if conf.skip_test(f):
|
|
|
|
print "Skipped."
|
|
|
|
continue
|
|
|
|
#try:
|
|
|
|
ret = conf.start(test.Client, test.Responder)
|
|
|
|
#except:
|
|
|
|
#ret = False
|
2015-12-17 10:07:56 +01:00
|
|
|
if not ret:
|
|
|
|
exitcode = -1
|
2015-12-16 09:40:01 +01:00
|
|
|
|
|
|
|
sys.exit(exitcode)
|
|
|
|
|