mirror of
https://github.com/progval/irctest.git
synced 2025-04-05 14:59:49 +00:00
Remove useless 'OptionalityHelper'.
This commit is contained in:
@ -732,24 +732,10 @@ class BaseServerTestCase(
|
||||
raise ChannelJoinException(msg.command, msg.params)
|
||||
|
||||
|
||||
_TSelf = TypeVar("_TSelf", bound="OptionalityHelper")
|
||||
_TSelf = TypeVar("_TSelf", bound="_IrcTestCase")
|
||||
_TReturn = TypeVar("_TReturn")
|
||||
|
||||
|
||||
class OptionalityHelper(Generic[TController]):
|
||||
controller: TController
|
||||
|
||||
def checkSaslSupport(self) -> None:
|
||||
if self.controller.supported_sasl_mechanisms:
|
||||
return
|
||||
raise runner.NotImplementedByController("SASL")
|
||||
|
||||
def checkMechanismSupport(self, mechanism: str) -> None:
|
||||
if mechanism in self.controller.supported_sasl_mechanisms:
|
||||
return
|
||||
raise runner.OptionalSaslMechanismNotSupported(mechanism)
|
||||
|
||||
@staticmethod
|
||||
def skipUnlessHasMechanism(
|
||||
mech: str,
|
||||
) -> Callable[[Callable[..., _TReturn]], Callable[..., _TReturn]]:
|
||||
@ -760,18 +746,20 @@ class OptionalityHelper(Generic[TController]):
|
||||
def decorator(f: Callable[..., _TReturn]) -> Callable[..., _TReturn]:
|
||||
@functools.wraps(f)
|
||||
def newf(self: _TSelf, *args: Any, **kwargs: Any) -> _TReturn:
|
||||
self.checkMechanismSupport(mech)
|
||||
if mech not in self.controller.supported_sasl_mechanisms:
|
||||
raise runner.OptionalSaslMechanismNotSupported(mech)
|
||||
return f(self, *args, **kwargs)
|
||||
|
||||
return newf
|
||||
|
||||
return decorator
|
||||
|
||||
@staticmethod
|
||||
|
||||
def skipUnlessHasSasl(f: Callable[..., _TReturn]) -> Callable[..., _TReturn]:
|
||||
@functools.wraps(f)
|
||||
def newf(self: _TSelf, *args: Any, **kwargs: Any) -> _TReturn:
|
||||
self.checkSaslSupport()
|
||||
if not self.controller.supported_sasl_mechanisms:
|
||||
raise runner.NotImplementedByController("SASL")
|
||||
return f(self, *args, **kwargs)
|
||||
|
||||
return newf
|
||||
|
@ -39,8 +39,8 @@ class IdentityHash:
|
||||
return self._data
|
||||
|
||||
|
||||
class SaslTestCase(cases.BaseClientTestCase, cases.OptionalityHelper):
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("PLAIN")
|
||||
class SaslTestCase(cases.BaseClientTestCase):
|
||||
@cases.skipUnlessHasMechanism("PLAIN")
|
||||
def testPlain(self):
|
||||
"""Test PLAIN authentication with correct username/password."""
|
||||
auth = authentication.Authentication(
|
||||
@ -60,7 +60,7 @@ class SaslTestCase(cases.BaseClientTestCase, cases.OptionalityHelper):
|
||||
m = self.negotiateCapabilities(["sasl"], False)
|
||||
self.assertEqual(m, Message({}, None, "CAP", ["END"]))
|
||||
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("PLAIN")
|
||||
@cases.skipUnlessHasMechanism("PLAIN")
|
||||
def testPlainNotAvailable(self):
|
||||
"""`sasl=EXTERNAL` is advertized, whereas the client is configured
|
||||
to use PLAIN.
|
||||
@ -90,7 +90,7 @@ class SaslTestCase(cases.BaseClientTestCase, cases.OptionalityHelper):
|
||||
self.assertMessageMatch(m, command="CAP")
|
||||
|
||||
@pytest.mark.parametrize("pattern", ["barbaz", "éèà"])
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("PLAIN")
|
||||
@cases.skipUnlessHasMechanism("PLAIN")
|
||||
def testPlainLarge(self, pattern):
|
||||
"""Test the client splits large AUTHENTICATE messages whose payload
|
||||
is not a multiple of 400.
|
||||
@ -119,7 +119,7 @@ class SaslTestCase(cases.BaseClientTestCase, cases.OptionalityHelper):
|
||||
m = self.negotiateCapabilities(["sasl"], False)
|
||||
self.assertEqual(m, Message({}, None, "CAP", ["END"]))
|
||||
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("PLAIN")
|
||||
@cases.skipUnlessHasMechanism("PLAIN")
|
||||
@pytest.mark.parametrize("pattern", ["quux", "éè"])
|
||||
def testPlainLargeMultiple(self, pattern):
|
||||
"""Test the client splits large AUTHENTICATE messages whose payload
|
||||
@ -150,7 +150,7 @@ class SaslTestCase(cases.BaseClientTestCase, cases.OptionalityHelper):
|
||||
self.assertEqual(m, Message({}, None, "CAP", ["END"]))
|
||||
|
||||
@pytest.mark.skipif(ecdsa is None, reason="python3-ecdsa is not available")
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("ECDSA-NIST256P-CHALLENGE")
|
||||
@cases.skipUnlessHasMechanism("ECDSA-NIST256P-CHALLENGE")
|
||||
def testEcdsa(self):
|
||||
"""Test ECDSA authentication."""
|
||||
auth = authentication.Authentication(
|
||||
@ -184,7 +184,7 @@ class SaslTestCase(cases.BaseClientTestCase, cases.OptionalityHelper):
|
||||
m = self.negotiateCapabilities(["sasl"], False)
|
||||
self.assertEqual(m, Message({}, None, "CAP", ["END"]))
|
||||
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("SCRAM-SHA-256")
|
||||
@cases.skipUnlessHasMechanism("SCRAM-SHA-256")
|
||||
def testScram(self):
|
||||
"""Test SCRAM-SHA-256 authentication."""
|
||||
auth = authentication.Authentication(
|
||||
@ -226,7 +226,7 @@ class SaslTestCase(cases.BaseClientTestCase, cases.OptionalityHelper):
|
||||
self.assertEqual(m.command, "AUTHENTICATE", m)
|
||||
self.assertEqual(m.params, ["+"], m)
|
||||
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("SCRAM-SHA-256")
|
||||
@cases.skipUnlessHasMechanism("SCRAM-SHA-256")
|
||||
def testScramBadPassword(self):
|
||||
"""Test SCRAM-SHA-256 authentication with a bad password."""
|
||||
auth = authentication.Authentication(
|
||||
@ -261,8 +261,8 @@ class SaslTestCase(cases.BaseClientTestCase, cases.OptionalityHelper):
|
||||
authenticator.response(msg)
|
||||
|
||||
|
||||
class Irc302SaslTestCase(cases.BaseClientTestCase, cases.OptionalityHelper):
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("PLAIN")
|
||||
class Irc302SaslTestCase(cases.BaseClientTestCase):
|
||||
@cases.skipUnlessHasMechanism("PLAIN")
|
||||
def testPlainNotAvailable(self):
|
||||
"""Test the client does not try to authenticate using a mechanism the
|
||||
server does not advertise.
|
||||
|
@ -140,7 +140,7 @@ class TlsTestCase(cases.BaseClientTestCase):
|
||||
self.getMessage()
|
||||
|
||||
|
||||
class StsTestCase(cases.BaseClientTestCase, cases.OptionalityHelper):
|
||||
class StsTestCase(cases.BaseClientTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.insecure_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
@ -6,7 +6,7 @@ from irctest import cases
|
||||
|
||||
|
||||
@cases.mark_services
|
||||
class AccountTagTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
class AccountTagTestCase(cases.BaseServerTestCase):
|
||||
def connectRegisteredClient(self, nick):
|
||||
self.addClient()
|
||||
self.sendLine(2, "CAP LS 302")
|
||||
@ -40,7 +40,7 @@ class AccountTagTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
self.skipToWelcome(2)
|
||||
|
||||
@cases.mark_capabilities("account-tag")
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("PLAIN")
|
||||
@cases.skipUnlessHasMechanism("PLAIN")
|
||||
def testPrivmsg(self):
|
||||
self.connectClient("foo", capabilities=["account-tag"], skip_if_cap_nak=True)
|
||||
self.getMessages(1)
|
||||
@ -54,7 +54,7 @@ class AccountTagTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
)
|
||||
|
||||
@cases.mark_capabilities("account-tag")
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("PLAIN")
|
||||
@cases.skipUnlessHasMechanism("PLAIN")
|
||||
def testInvite(self):
|
||||
self.connectClient("foo", capabilities=["account-tag"], skip_if_cap_nak=True)
|
||||
self.getMessages(1)
|
||||
|
@ -5,7 +5,7 @@
|
||||
from irctest import cases
|
||||
|
||||
|
||||
class AwayNotifyTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
class AwayNotifyTestCase(cases.BaseServerTestCase):
|
||||
@cases.mark_capabilities("away-notify")
|
||||
def testAwayNotify(self):
|
||||
"""Basic away-notify test."""
|
||||
|
@ -8,7 +8,7 @@ from irctest.patma import ANYSTR
|
||||
from irctest.runner import CapabilityNotSupported, ImplementationChoice
|
||||
|
||||
|
||||
class CapTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
class CapTestCase(cases.BaseServerTestCase):
|
||||
@cases.mark_specifications("IRCv3")
|
||||
def testNoReq(self):
|
||||
"""Test the server handles gracefully clients which do not send
|
||||
|
@ -6,7 +6,7 @@ from irctest import cases
|
||||
|
||||
|
||||
@cases.mark_services
|
||||
class MetadataTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
class MetadataTestCase(cases.BaseServerTestCase):
|
||||
def connectRegisteredClient(self, nick):
|
||||
self.addClient()
|
||||
self.sendLine(2, "CAP LS 302")
|
||||
@ -50,7 +50,7 @@ class MetadataTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
)
|
||||
|
||||
@cases.mark_capabilities("extended-join")
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("PLAIN")
|
||||
@cases.skipUnlessHasMechanism("PLAIN")
|
||||
def testLoggedIn(self):
|
||||
self.connectClient("foo", capabilities=["extended-join"], skip_if_cap_nak=True)
|
||||
self.joinChannel(1, "#chan")
|
||||
|
@ -14,7 +14,7 @@ from irctest.numerics import ERR_UNKNOWNCOMMAND
|
||||
from irctest.patma import ANYDICT, ANYOPTSTR, NotStrRe, RemainingKeys, StrRe
|
||||
|
||||
|
||||
class LabeledResponsesTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
class LabeledResponsesTestCase(cases.BaseServerTestCase):
|
||||
@cases.mark_capabilities("echo-message", "batch", "labeled-response")
|
||||
def testLabeledPrivmsgResponsesToMultipleClients(self):
|
||||
self.connectClient(
|
||||
|
@ -10,7 +10,7 @@ from irctest.numerics import ERR_INPUTTOOLONG
|
||||
from irctest.patma import ANYDICT, ANYSTR, StrRe
|
||||
|
||||
|
||||
class MessageTagsTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
class MessageTagsTestCase(cases.BaseServerTestCase):
|
||||
@pytest.mark.arbitrary_client_tags
|
||||
@cases.mark_capabilities("message-tags")
|
||||
def testBasic(self):
|
||||
|
@ -12,7 +12,7 @@ CONCAT_TAG = "draft/multiline-concat"
|
||||
base_caps = ["message-tags", "batch", "echo-message", "server-time", "labeled-response"]
|
||||
|
||||
|
||||
class MultilineTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
class MultilineTestCase(cases.BaseServerTestCase):
|
||||
@cases.mark_capabilities("draft/multiline")
|
||||
def testBasic(self):
|
||||
self.connectClient(
|
||||
|
@ -12,9 +12,9 @@ class RegistrationTestCase(cases.BaseServerTestCase):
|
||||
|
||||
|
||||
@cases.mark_services
|
||||
class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
class SaslTestCase(cases.BaseServerTestCase):
|
||||
@cases.mark_specifications("IRCv3")
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("PLAIN")
|
||||
@cases.skipUnlessHasMechanism("PLAIN")
|
||||
def testPlain(self):
|
||||
"""PLAIN authentication with correct username/password."""
|
||||
self.controller.registerUser(self, "foo", "sesame")
|
||||
@ -54,7 +54,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
)
|
||||
|
||||
@cases.mark_specifications("IRCv3")
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("PLAIN")
|
||||
@cases.skipUnlessHasMechanism("PLAIN")
|
||||
def testPlainNonAscii(self):
|
||||
password = "é" * 100
|
||||
authstring = base64.b64encode(
|
||||
@ -82,7 +82,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
)
|
||||
|
||||
@cases.mark_specifications("IRCv3")
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("PLAIN")
|
||||
@cases.skipUnlessHasMechanism("PLAIN")
|
||||
def testPlainNoAuthzid(self):
|
||||
"""“message = [authzid] UTF8NUL authcid UTF8NUL passwd
|
||||
|
||||
@ -170,7 +170,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
)
|
||||
|
||||
@cases.mark_specifications("IRCv3")
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("PLAIN")
|
||||
@cases.skipUnlessHasMechanism("PLAIN")
|
||||
def testPlainLarge(self):
|
||||
"""Test the client splits large AUTHENTICATE messages whose payload
|
||||
is not a multiple of 400.
|
||||
@ -232,7 +232,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
# message's length too big for it to be valid.
|
||||
|
||||
@cases.mark_specifications("IRCv3")
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("PLAIN")
|
||||
@cases.skipUnlessHasMechanism("PLAIN")
|
||||
def testPlainLargeEquals400(self):
|
||||
"""Test the client splits large AUTHENTICATE messages whose payload
|
||||
is not a multiple of 400.
|
||||
@ -277,7 +277,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
# message's length too big for it to be valid.
|
||||
|
||||
@cases.mark_specifications("IRCv3")
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("SCRAM-SHA-256")
|
||||
@cases.skipUnlessHasMechanism("SCRAM-SHA-256")
|
||||
def testScramSha256Success(self):
|
||||
self.controller.registerUser(self, "Scramtest", "sesame")
|
||||
|
||||
@ -333,7 +333,7 @@ class SaslTestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
self.confirmSuccessfulAuth()
|
||||
|
||||
@cases.mark_specifications("IRCv3")
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("SCRAM-SHA-256")
|
||||
@cases.skipUnlessHasMechanism("SCRAM-SHA-256")
|
||||
def testScramSha256Failure(self):
|
||||
self.controller.registerUser(self, "Scramtest", "sesame")
|
||||
|
||||
|
@ -9,7 +9,7 @@ from irctest import cases
|
||||
from irctest.patma import ANYSTR
|
||||
|
||||
|
||||
class Utf8TestCase(cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
class Utf8TestCase(cases.BaseServerTestCase):
|
||||
@cases.mark_specifications("Ergo")
|
||||
def testUtf8Validation(self):
|
||||
self.connectClient(
|
||||
|
@ -84,7 +84,7 @@ class BaseWhoTestCase:
|
||||
)
|
||||
|
||||
|
||||
class WhoTestCase(BaseWhoTestCase, cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
class WhoTestCase(BaseWhoTestCase, cases.BaseServerTestCase):
|
||||
@cases.mark_specifications("Modern")
|
||||
def testWhoStar(self):
|
||||
self._init()
|
||||
@ -422,9 +422,7 @@ class WhoTestCase(BaseWhoTestCase, cases.BaseServerTestCase, cases.OptionalityHe
|
||||
|
||||
|
||||
@cases.mark_services
|
||||
class WhoServicesTestCase(
|
||||
BaseWhoTestCase, cases.BaseServerTestCase, cases.OptionalityHelper
|
||||
):
|
||||
class WhoServicesTestCase(BaseWhoTestCase, cases.BaseServerTestCase):
|
||||
@cases.mark_specifications("IRCv3")
|
||||
@cases.mark_isupport("WHOX")
|
||||
def testWhoxAccount(self):
|
||||
|
@ -164,7 +164,7 @@ class _WhoisTestMixin(cases.BaseServerTestCase):
|
||||
)
|
||||
|
||||
|
||||
class WhoisTestCase(_WhoisTestMixin, cases.BaseServerTestCase, cases.OptionalityHelper):
|
||||
class WhoisTestCase(_WhoisTestMixin, cases.BaseServerTestCase):
|
||||
@pytest.mark.parametrize(
|
||||
"server",
|
||||
["", "My.Little.Server", "coolNick"],
|
||||
@ -210,11 +210,9 @@ class WhoisTestCase(_WhoisTestMixin, cases.BaseServerTestCase, cases.Optionality
|
||||
|
||||
|
||||
@cases.mark_services
|
||||
class ServicesWhoisTestCase(
|
||||
_WhoisTestMixin, cases.BaseServerTestCase, cases.OptionalityHelper
|
||||
):
|
||||
class ServicesWhoisTestCase(_WhoisTestMixin, cases.BaseServerTestCase):
|
||||
@pytest.mark.parametrize("oper", [False, True], ids=["normal", "oper"])
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("PLAIN")
|
||||
@cases.skipUnlessHasMechanism("PLAIN")
|
||||
@cases.mark_specifications("Modern")
|
||||
def testWhoisNumerics(self, oper):
|
||||
"""Tests all numerics are in the exhaustive list defined in the Modern spec,
|
||||
@ -297,7 +295,7 @@ class ServicesWhoisTestCase(
|
||||
"RPL_WHOISCHANNELS should be sent for a non-invisible nick",
|
||||
)
|
||||
|
||||
@cases.OptionalityHelper.skipUnlessHasMechanism("PLAIN")
|
||||
@cases.skipUnlessHasMechanism("PLAIN")
|
||||
@cases.mark_specifications("ircdocs")
|
||||
def testWhoisAccount(self):
|
||||
"""Test numeric 330, RPL_WHOISACCOUNT.
|
||||
|
Reference in New Issue
Block a user