From 2e1ddeb6547e140e9651231fedcd00e8ee4b1ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 14 Jun 2020 22:54:42 +0200 Subject: Implement SASL plain authentication --- tests/end_to_end/__main__.py | 2 ++ tests/end_to_end/scenarios/sasl.py | 34 +++++++++++++++++++++++ tests/end_to_end/scenarios/simple_channel_join.py | 1 - tests/end_to_end/sequences.py | 18 ++++++------ 4 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 tests/end_to_end/scenarios/sasl.py (limited to 'tests') diff --git a/tests/end_to_end/__main__.py b/tests/end_to_end/__main__.py index 1e4ffca..6e753f6 100644 --- a/tests/end_to_end/__main__.py +++ b/tests/end_to_end/__main__.py @@ -184,6 +184,8 @@ class BiboumiRunner(ProcessRunner): class IrcServerRunner(ProcessRunner): def __init__(self): super().__init__() + # Always start with a fresh state + os.remove("ircd.db") subprocess.run(["oragono", "mkcerts", "--conf", os.getcwd() + "/../tests/end_to_end/ircd.yaml"]) self.create = asyncio.create_subprocess_exec("oragono", "run", "--conf", os.getcwd() + "/../tests/end_to_end/ircd.yaml", stderr=asyncio.subprocess.PIPE) diff --git a/tests/end_to_end/scenarios/sasl.py b/tests/end_to_end/scenarios/sasl.py new file mode 100644 index 0000000..5f71b7a --- /dev/null +++ b/tests/end_to_end/scenarios/sasl.py @@ -0,0 +1,34 @@ +from scenarios import * + +scenario = ( + send_stanza(""), + sequences.connection(), + + simple_channel_join.expect_self_join_presence(jid = '{jid_one}/{resource_one}', chan = "#foo", nick = "RegisteredUser"), + + # Create an account by talking to nickserv directly + send_stanza("register P4SSW0RD"), + expect_stanza("/message/body[text()='Account created']"), + expect_stanza("/message/body[text()=\"You're now logged in as RegisteredUser\"]"), + send_stanza(""), + expect_stanza("/presence[@type='unavailable']"), + + # Configure an sasl password + send_stanza(""), + expect_stanza("/iq[@type='result']/commands:command[@node='configure'][@sessionid][@status='executing']", + "/iq/commands:command/dataform:x[@type='form']/dataform:field[@type='text-private'][@var='sasl_password']", + after = save_value("sessionid", extract_attribute("/iq[@type='result']/commands:command[@node='configure']", "sessionid"))), + + send_stanza("" + "" + "" + "P4SSW0RD" + "6667" + "RegisteredUser" + "66976670" + ""), + expect_stanza("/iq[@type='result']/commands:command[@node='configure'][@status='completed']/commands:note[@type='info'][text()='Configuration successfully applied.']"), + + send_stanza(""), + sequences.connection(login="RegisteredUser") +) diff --git a/tests/end_to_end/scenarios/simple_channel_join.py b/tests/end_to_end/scenarios/simple_channel_join.py index 9beba3b..6b57207 100644 --- a/tests/end_to_end/scenarios/simple_channel_join.py +++ b/tests/end_to_end/scenarios/simple_channel_join.py @@ -15,6 +15,5 @@ scenario = ( sequences.connection(), expect_self_join_presence(jid = '{jid_one}/{resource_one}', chan = "#foo", nick = "{nick_one}"), - ) diff --git a/tests/end_to_end/sequences.py b/tests/end_to_end/sequences.py index b545b1c..f151bc7 100644 --- a/tests/end_to_end/sequences.py +++ b/tests/end_to_end/sequences.py @@ -6,7 +6,7 @@ def handshake(): send_stanza("") ) -def connection_begin(irc_host, jid, expected_irc_presence=False, fixed_irc_server=False): +def connection_begin(irc_host, jid, expected_irc_presence=False, fixed_irc_server=False, login=None): jid = jid.format_map(common_replacements) if fixed_irc_server: xpath = "/message[@to='" + jid + "'][@from='biboumi.localhost']/body[text()='%s']" @@ -26,12 +26,12 @@ def connection_begin(irc_host, jid, expected_irc_presence=False, fixed_irc_serve if expected_irc_presence: result += (expect_stanza("/presence[@from='" + irc_host + "@biboumi.localhost']"),) + if login is not None: + result += (expect_stanza("/message/body[text()='irc.localhost: You are now logged in as %s']" % (login,)),) result += ( - expect_stanza("/message/body[text()='irc.localhost: ACK multi-prefix']"), expect_stanza("/message/body[text()='irc.localhost: *** Looking up your hostname...']"), - expect_stanza("/message/body[text()='irc.localhost: *** Found your hostname']"), - ), - + expect_stanza("/message/body[text()='irc.localhost: *** Found your hostname']") + ) return result def connection_tls_begin(irc_host, jid, fixed_irc_server): @@ -47,9 +47,8 @@ def connection_tls_begin(irc_host, jid, fixed_irc_server): "/message/carbon:private", ), expect_stanza(xpath % 'Connected to IRC server (encrypted).'), - expect_stanza("/message/body[text()='irc.localhost: ACK multi-prefix']"), expect_stanza("/message/body[text()='irc.localhost: *** Looking up your hostname...']"), - expect_stanza("/message/body[text()='irc.localhost: *** Found your hostname']"), + expect_stanza("/message/body[text()='irc.localhost: *** Found your hostname']") ) def connection_end(irc_host, jid, fixed_irc_server=False): @@ -75,8 +74,9 @@ def connection_end(irc_host, jid, fixed_irc_server=False): expect_stanza(xpath_re % (r'.+? \+Z',)), ) -def connection(irc_host="irc.localhost", jid="{jid_one}/{resource_one}", expected_irc_presence=False, fixed_irc_server=False): - return connection_begin(irc_host, jid, expected_irc_presence, fixed_irc_server=fixed_irc_server) + \ + +def connection(irc_host="irc.localhost", jid="{jid_one}/{resource_one}", expected_irc_presence=False, fixed_irc_server=False, login=None): + return connection_begin(irc_host, jid, expected_irc_presence, fixed_irc_server=fixed_irc_server, login=login) + \ connection_end(irc_host, jid, fixed_irc_server=fixed_irc_server) def connection_tls(irc_host="irc.localhost", jid="{jid_one}/{resource_one}", fixed_irc_server=False): -- cgit v1.2.3