Always request the 'sasl' cap before using AUTHENTICATE

InspIRCd ignores AUTHENTICATE when the cap is not negotiated.
This commit is contained in:
2021-06-27 13:01:03 +02:00
committed by Val Lorentz
parent 7ac4d7f80f
commit 48eeeb7312
3 changed files with 28 additions and 14 deletions

View File

@ -561,6 +561,27 @@ class BaseServerTestCase(
if m.command == "001": if m.command == "001":
return result 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( def connectClient(
self, self,
nick: str, nick: str,
@ -580,20 +601,7 @@ class BaseServerTestCase(
if capabilities: if capabilities:
self.sendLine(client, "CAP LS 302") self.sendLine(client, "CAP LS 302")
m = self.getRegistrationMessage(client) m = self.getRegistrationMessage(client)
self.sendLine(client, "CAP REQ :{}".format(" ".join(capabilities))) self.requestCapabilities(client, capabilities, skip_if_cap_nak)
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
if password is not None: if password is not None:
if "sasl" not in (capabilities or ()): if "sasl" not in (capabilities or ()):
raise ValueError("Used 'password' option without sasl capbilitiy") raise ValueError("Used 'password' option without sasl capbilitiy")

View File

@ -11,6 +11,7 @@ class MetadataTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
self.sendLine(2, "CAP LS 302") self.sendLine(2, "CAP LS 302")
capabilities = self.getCapLs(2) capabilities = self.getCapLs(2)
assert "sasl" in capabilities assert "sasl" in capabilities
self.requestCapabilities(2, ["sasl"], skip_if_cap_nak=False)
self.sendLine(2, "AUTHENTICATE PLAIN") self.sendLine(2, "AUTHENTICATE PLAIN")
m = self.getRegistrationMessage(2) m = self.getRegistrationMessage(2)
self.assertMessageMatch( self.assertMessageMatch(

View File

@ -31,6 +31,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
capabilities["sasl"], capabilities["sasl"],
fail_msg="Does not have PLAIN mechanism as the controller " "claims", 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") self.sendLine(1, "AUTHENTICATE PLAIN")
m = self.getRegistrationMessage(1) m = self.getRegistrationMessage(1)
self.assertMessageMatch( self.assertMessageMatch(
@ -90,6 +91,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
capabilities["sasl"], capabilities["sasl"],
fail_msg="Does not have PLAIN mechanism as the controller " "claims", 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") self.sendLine(1, "AUTHENTICATE PLAIN")
m = self.getRegistrationMessage(1) m = self.getRegistrationMessage(1)
self.assertMessageMatch( self.assertMessageMatch(
@ -122,6 +124,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
capabilities, capabilities,
fail_msg="Does not have SASL as the controller claims.", fail_msg="Does not have SASL as the controller claims.",
) )
self.requestCapabilities(1, ["sasl"], skip_if_cap_nak=False)
self.sendLine(1, "AUTHENTICATE FOO") self.sendLine(1, "AUTHENTICATE FOO")
m = self.getRegistrationMessage(1) m = self.getRegistrationMessage(1)
self.assertMessageMatch( self.assertMessageMatch(
@ -155,6 +158,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
capabilities["sasl"], capabilities["sasl"],
fail_msg="Does not have PLAIN mechanism as the controller " "claims", 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") self.sendLine(1, "AUTHENTICATE PLAIN")
m = self.getRegistrationMessage(1) m = self.getRegistrationMessage(1)
self.assertMessageMatch( self.assertMessageMatch(
@ -217,6 +221,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
capabilities["sasl"], capabilities["sasl"],
fail_msg="Does not have PLAIN mechanism as the controller " "claims", 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") self.sendLine(1, "AUTHENTICATE PLAIN")
m = self.getRegistrationMessage(1) m = self.getRegistrationMessage(1)
self.assertMessageMatch( self.assertMessageMatch(