Commit 45f442b6 authored by louiz’'s avatar louiz’

More tests

parent e0ee881f
...@@ -87,6 +87,7 @@ class XMPPComponent(slixmpp.BaseXMPP): ...@@ -87,6 +87,7 @@ class XMPPComponent(slixmpp.BaseXMPP):
def check_stanza_against_all_expected_xpaths(self): def check_stanza_against_all_expected_xpaths(self):
pass pass
def check_xpath(xpaths, stanza): def check_xpath(xpaths, stanza):
for xpath in xpaths: for xpath in xpaths:
tree = lxml.etree.parse(io.StringIO(str(stanza))) tree = lxml.etree.parse(io.StringIO(str(stanza)))
...@@ -118,6 +119,7 @@ class Scenario: ...@@ -118,6 +119,7 @@ class Scenario:
else: else:
self.steps.append(elem) self.steps.append(elem)
class ProcessRunner: class ProcessRunner:
def __init__(self): def __init__(self):
self.process = None self.process = None
...@@ -155,13 +157,14 @@ class BiboumiRunner(ProcessRunner): ...@@ -155,13 +157,14 @@ class BiboumiRunner(ProcessRunner):
self.create = asyncio.create_subprocess_exec("./biboumi", "test.conf", stdin=None, stdout=self.fd, self.create = asyncio.create_subprocess_exec("./biboumi", "test.conf", stdin=None, stdout=self.fd,
stderr=self.fd, loop=None, limit=None) stderr=self.fd, loop=None, limit=None)
class IrcServerRunner(ProcessRunner): class IrcServerRunner(ProcessRunner):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.create = asyncio.create_subprocess_exec("mammond", "--debug", "--nofork", self.create = asyncio.create_subprocess_exec("/home/louiz/sources/charybdis/ircd/charybdis", "-foreground",
"--config", "../tests/end_to_end/mammond.conf",
stderr=asyncio.subprocess.PIPE) stderr=asyncio.subprocess.PIPE)
def send_stanza(stanza, xmpp, biboumi): def send_stanza(stanza, xmpp, biboumi):
xmpp.send_raw(stanza.format_map(common_replacements)) xmpp.send_raw(stanza.format_map(common_replacements))
asyncio.get_event_loop().call_soon(xmpp.run_scenario) asyncio.get_event_loop().call_soon(xmpp.run_scenario)
...@@ -175,6 +178,7 @@ def expect_stanza(xpaths, xmpp, biboumi): ...@@ -175,6 +178,7 @@ def expect_stanza(xpaths, xmpp, biboumi):
else: else:
print("Warning, from argument type passed to expect_stanza: %s" % (type(xpaths))) print("Warning, from argument type passed to expect_stanza: %s" % (type(xpaths)))
class BiboumiTest: class BiboumiTest:
""" """
Spawns a biboumi process and a fake XMPP Component that will run a Spawns a biboumi process and a fake XMPP Component that will run a
...@@ -330,20 +334,69 @@ if __name__ == '__main__': ...@@ -330,20 +334,69 @@ if __name__ == '__main__':
# Second user joins # Second user joins
partial(send_stanza, partial(send_stanza,
"<presence from='{jid_two}/{resource_one}' to='#foo%{irc_server_one}/{nick_two}' />"), "<presence from='{jid_two}/{resource_one}' to='#foo%{irc_server_one}/{nick_two}' />"),
connection_sequence("irc.localhost", '{jid_two}/{resource_one}'),
# Our presence, sent to the other user
partial(expect_stanza,
("/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_two}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~bobby@localhost'][@role='participant']",)),
# The other user presence
partial(expect_stanza,
("/presence[@to='{jid_second}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~nick@localhost'][@role='participant']")
),
# Our own presence
partial(expect_stanza,
("/presence[@to='{jid_two}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_two}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~bobby@localhost'][@role='participant']",
"/presence/muc_user:x/muc_user:status[@code='110']")
),
partial(expect_stanza, "/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]"),
]),
Scenario("channel_custom_topic",
[
handshake_sequence(),
# First user joins
partial(send_stanza,
"<presence from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}/{nick_one}' />"),
connection_sequence("irc.localhost", '{jid_one}/{resource_one}'),
partial(expect_stanza,
("/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~nick@localhost'][@role='participant']",
"/presence/muc_user:x/muc_user:status[@code='110']")
),
partial(expect_stanza, "/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]"),
# First user sets the topic
partial(send_stanza,
"<message from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}/{nick_one}' type='groupchat'><subject>TOPIC\nTEST</subject></message>"),
partial(expect_stanza, "/message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat'][@to='{jid_one}/{resource_one}']/subject[text()='TOPIC\nTEST']"),
# # Second user joins
# partial(send_stanza,
# "<presence from='{jid_two}/{resource_one}' to='#foo%{irc_server_one}/{nick_two}' />"),
# connection_sequence("irc.localhost", '{jid_two}/{resource_one}'), # connection_sequence("irc.localhost", '{jid_two}/{resource_one}'),
# # Our presence, sent to the other user
# partial(expect_stanza,
# ("/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_two}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~bobby@localhost'][@role='participant']",)),
# # The other user presence
# partial(expect_stanza,
# ("/presence[@to='{jid_second}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~nick@localhost'][@role='participant']")
# ),
# # Our own presence
# partial(expect_stanza,
# ("/presence[@to='{jid_two}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_two}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~bobby@localhost'][@role='participant']",
# "/presence/muc_user:x/muc_user:status[@code='110']")
# ),
# partial(expect_stanza, "/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]"),
]), ]),
) )
failures = 0 failures = 0
irc = IrcServerRunner() irc = IrcServerRunner()
print("Starting mammond server…") print("Starting irc server…")
asyncio.get_event_loop().run_until_complete(irc.start()) asyncio.get_event_loop().run_until_complete(irc.start())
while True: while True:
res = asyncio.get_event_loop().run_until_complete(irc.process.stderr.readline()) res = asyncio.get_event_loop().run_until_complete(irc.process.stderr.readline())
if b"init finished..." in res: if b"now running in foreground mode" in res:
break break
print("mammond server started.") print("irc server started.")
print("Running %s checks for biboumi." % (len(scenarios))) print("Running %s checks for biboumi." % (len(scenarios)))
for scenario in scenarios: for scenario in scenarios:
...@@ -353,7 +406,7 @@ if __name__ == '__main__': ...@@ -353,7 +406,7 @@ if __name__ == '__main__':
(scenario.name, scenario.name)) (scenario.name, scenario.name))
failures += 1 failures += 1
print("Waiting for mammond to exit…") print("Waiting for irc server to exit…")
irc.stop() irc.stop()
code = asyncio.get_event_loop().run_until_complete(irc.wait()) code = asyncio.get_event_loop().run_until_complete(irc.wait())
......
...@@ -233,7 +233,7 @@ opers: ...@@ -233,7 +233,7 @@ opers:
# name - the name of the operator # name - the name of the operator
"nobody": "nobody":
# password - the plaintext oper password # password - the plaintext oper password
password: "nothing" # password: "nothing"
# hostmask - if defined, the hostmask the oper must connect from # hostmask - if defined, the hostmask the oper must connect from
hostmask: "*@localhost" hostmask: "*@localhost"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment