From 48eeeb73120f5fdd6c613556c46ead13a4b24a17 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 27 Jun 2021 13:01:03 +0200 Subject: [PATCH] Always request the 'sasl' cap before using AUTHENTICATE InspIRCd ignores AUTHENTICATE when the cap is not negotiated. --- irctest/cases.py | 36 +++++++++++++--------- irctest/server_tests/test_extended_join.py | 1 + irctest/server_tests/test_sasl.py | 5 +++ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/irctest/cases.py b/irctest/cases.py index 122600b..7ca7f86 100644 --- a/irctest/cases.py +++ b/irctest/cases.py @@ -561,6 +561,27 @@ class BaseServerTestCase( if m.command == "001": return result + def requestCapabilities( + self, + client: TClientName, + capabilities: List[str], + skip_if_cap_nak: bool = False, + ) -> None: + self.sendLine(client, "CAP REQ :{}".format(" ".join(capabilities))) + m = self.getRegistrationMessage(client) + try: + self.assertMessageMatch( + m, command="CAP", fail_msg="Expected CAP ACK, got: {msg}" + ) + self.assertEqual( + m.params[1], "ACK", m, fail_msg="Expected CAP ACK, got: {msg}" + ) + except AssertionError: + if skip_if_cap_nak: + raise runner.CapabilityNotSupported(" or ".join(capabilities)) + else: + raise + def connectClient( self, nick: str, @@ -580,20 +601,7 @@ class BaseServerTestCase( if capabilities: self.sendLine(client, "CAP LS 302") m = self.getRegistrationMessage(client) - self.sendLine(client, "CAP REQ :{}".format(" ".join(capabilities))) - m = self.getRegistrationMessage(client) - try: - self.assertMessageMatch( - m, command="CAP", fail_msg="Expected CAP ACK, got: {msg}" - ) - self.assertEqual( - m.params[1], "ACK", m, fail_msg="Expected CAP ACK, got: {msg}" - ) - except AssertionError: - if skip_if_cap_nak: - raise runner.CapabilityNotSupported(" or ".join(capabilities)) - else: - raise + self.requestCapabilities(client, capabilities, skip_if_cap_nak) if password is not None: if "sasl" not in (capabilities or ()): raise ValueError("Used 'password' option without sasl capbilitiy") diff --git a/irctest/server_tests/test_extended_join.py b/irctest/server_tests/test_extended_join.py index 205af03..a408c89 100644 --- a/irctest/server_tests/test_extended_join.py +++ b/irctest/server_tests/test_extended_join.py @@ -11,6 +11,7 @@ class MetadataTestCase(cases.BaseServerTestCase, cases.OptionalityHelper): self.sendLine(2, "CAP LS 302") capabilities = self.getCapLs(2) assert "sasl" in capabilities + self.requestCapabilities(2, ["sasl"], skip_if_cap_nak=False) self.sendLine(2, "AUTHENTICATE PLAIN") m = self.getRegistrationMessage(2) self.assertMessageMatch( diff --git a/irctest/server_tests/test_sasl.py b/irctest/server_tests/test_sasl.py index d4e9a60..c24f436 100644 --- a/irctest/server_tests/test_sasl.py +++ b/irctest/server_tests/test_sasl.py @@ -31,6 +31,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper): capabilities["sasl"], fail_msg="Does not have PLAIN mechanism as the controller " "claims", ) + self.requestCapabilities(1, ["sasl"], skip_if_cap_nak=False) self.sendLine(1, "AUTHENTICATE PLAIN") m = self.getRegistrationMessage(1) self.assertMessageMatch( @@ -90,6 +91,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper): capabilities["sasl"], fail_msg="Does not have PLAIN mechanism as the controller " "claims", ) + self.requestCapabilities(1, ["sasl"], skip_if_cap_nak=False) self.sendLine(1, "AUTHENTICATE PLAIN") m = self.getRegistrationMessage(1) self.assertMessageMatch( @@ -122,6 +124,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper): capabilities, fail_msg="Does not have SASL as the controller claims.", ) + self.requestCapabilities(1, ["sasl"], skip_if_cap_nak=False) self.sendLine(1, "AUTHENTICATE FOO") m = self.getRegistrationMessage(1) self.assertMessageMatch( @@ -155,6 +158,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper): capabilities["sasl"], fail_msg="Does not have PLAIN mechanism as the controller " "claims", ) + self.requestCapabilities(1, ["sasl"], skip_if_cap_nak=False) self.sendLine(1, "AUTHENTICATE PLAIN") m = self.getRegistrationMessage(1) self.assertMessageMatch( @@ -217,6 +221,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper): capabilities["sasl"], fail_msg="Does not have PLAIN mechanism as the controller " "claims", ) + self.requestCapabilities(1, ["sasl"], skip_if_cap_nak=False) self.sendLine(1, "AUTHENTICATE PLAIN") m = self.getRegistrationMessage(1) self.assertMessageMatch(