Skip to content

Commit

Permalink
squashme
Browse files Browse the repository at this point in the history
  • Loading branch information
half-duplex committed Nov 25, 2023
1 parent cd904a9 commit fe81317
Showing 1 changed file with 55 additions and 5 deletions.
60 changes: 55 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,14 +262,12 @@ 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.settings.core.auth_target = "EXTERNAL"
mockbot.backend.connected = True

# connect and capability negotiation
Expand All @@ -269,8 +276,51 @@ def test_sasl_external_no_password(
n = len(mockbot.backend.message_sent)
mockbot.on_message(":irc.example.com CAP * ACK :sasl")
assert mockbot.backend.message_sent[n:] == rawlist(
"AUTHENTICATE EXTERNAL"
), "SASL EXTERNAL did not continue without a password configured."
"AUTHENTICATE EXTERNAL",
), "The bot should initiate SASL EXTERNAL authentication without a password set."
n += 1
mockbot.on_message("AUTHENTICATE +")
assert mockbot.backend.message_sent[n:] == rawlist(
"AUTHENTICATE +",
), "SASL EXTERNAL authentication should continue without a password set."
n += 1

mockbot.on_message(":irc.example.com 903 SopelTest :SASL authentication successful")
assert mockbot.backend.message_sent[n:] == rawlist(
"CAP END",
), "SASL success must resume capability negotiation."


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.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")
assert mockbot.backend.message_sent[n:] == rawlist(
"AUTHENTICATE EXTERNAL",
), "The bot should initiate SASL EXTERNAL authentication without a password set."
n += 1

mockbot.on_message("AUTHENTICATE +")
assert mockbot.backend.message_sent[n:] == rawlist(
"AUTHENTICATE +",
), "SASL EXTERNAL authentication should continue without a password set."
n += 1

mockbot.on_message(":irc.example.com 904 SopelTest :SASL authentication failed")
assert mockbot.backend.message_sent[n:] == rawlist(
"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 fe81317

Please sign in to comment.