From 9b6781938858039678ef6bd7b7a083332ff34cb5 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Sun, 12 Nov 2023 22:31:13 -0500 Subject: [PATCH] squashme --- test/coretasks/test_coretasks_sasl.py | 44 ++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/test/coretasks/test_coretasks_sasl.py b/test/coretasks/test_coretasks_sasl.py index d35d9fdb7..b89a3ad14 100644 --- a/test/coretasks/test_coretasks_sasl.py +++ b/test/coretasks/test_coretasks_sasl.py @@ -59,6 +59,15 @@ auth_method = sasl """ +TMP_CONFIG_SASL_EXTERNAL = """ +[core] +owner = Uowner +nick = TestBot +enable = coretasks +auth_method = sasl +auth_target = EXTERNAL +""" + @pytest.fixture def tmpconfig(configfactory: ConfigFactory) -> Config: @@ -253,14 +262,34 @@ def test_sasl_plain_no_password( ), 'No password is a configuration error and the bot must quit.' -# https://github.com/sopel-irc/sopel/issues/2560 def test_sasl_external_no_password( botfactory: BotFactory, configfactory: ConfigFactory, ) -> None: - tmpconfig = configfactory("conf.ini", TMP_CONFIG_SASL_NO_PASSWORD) + tmpconfig = configfactory("conf.ini", TMP_CONFIG_SASL_EXTERNAL) + mockbot = botfactory.preloaded(tmpconfig, preloads=["coretasks"]) + mockbot.backend.connected = True + + # connect and capability negotiation + mockbot.on_connect() + mockbot.on_message(":irc.example.com CAP * LS :sasl=PLAIN,EXTERNAL") + n = len(mockbot.backend.message_sent) + mockbot.on_message(":irc.example.com CAP * ACK :sasl") + mockbot.on_message("AUTHENTICATE +") + mockbot.on_message(":irc.example.com 903 SopelTest :SASL authentication successful") + assert mockbot.backend.message_sent[n:] == rawlist( + "AUTHENTICATE EXTERNAL", + "AUTHENTICATE +", + "CAP END", + ), "SASL EXTERNAL authentication should continue without a password set." + + +def test_sasl_external_fail( + botfactory: BotFactory, + configfactory: ConfigFactory, +) -> None: + tmpconfig = configfactory("conf.ini", TMP_CONFIG_SASL_EXTERNAL) mockbot = botfactory.preloaded(tmpconfig, preloads=["coretasks"]) - mockbot.settings.core.auth_target = "EXTERNAL" mockbot.backend.connected = True # connect and capability negotiation @@ -268,9 +297,14 @@ def test_sasl_external_no_password( mockbot.on_message(":irc.example.com CAP * LS :sasl=PLAIN,EXTERNAL") n = len(mockbot.backend.message_sent) mockbot.on_message(":irc.example.com CAP * ACK :sasl") + mockbot.on_message("AUTHENTICATE +") + mockbot.on_message(":irc.example.com 904 SopelTest :SASL authentication failed") assert mockbot.backend.message_sent[n:] == rawlist( - "AUTHENTICATE EXTERNAL" - ), "SASL EXTERNAL did not continue without a password configured." + "AUTHENTICATE EXTERNAL", + "AUTHENTICATE +", + "CAP END", + "QUIT :SASL Auth Failed", + ), "SASL EXTERNAL failure should trigger CAP END and QUIT." def test_sasl_plain_bad_password(botfactory: BotFactory, tmpconfig) -> None: