Skip to content

Commit

Permalink
squashme
Browse files Browse the repository at this point in the history
  • Loading branch information
half-duplex committed Nov 13, 2023
1 parent cd904a9 commit 9b67819
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions test/coretasks/test_coretasks_sasl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -253,24 +262,49 @@ 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
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 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:
Expand Down

0 comments on commit 9b67819

Please sign in to comment.