Skip to content

Commit

Permalink
more tests, test tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
half-duplex committed Oct 26, 2022
1 parent a77e80c commit 8796ff7
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions test/test_coretasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,7 @@ def test_sasl_scram_sha_256_nonsense_server_first(mockbot):
scram_server.set_client_first(
b64decode(mockbot.backend.message_sent[-1].split(b" ")[-1]).decode("utf-8")
)
mockbot.on_message(
"AUTHENTICATE "
+ b64encode(b"j=unk").decode("utf-8")
)
mockbot.on_message("AUTHENTICATE " + b64encode(b"junk").decode("utf-8"))
assert (
len(mockbot.backend.message_sent) == 3
and mockbot.backend.message_sent[-1] == rawlist("AUTHENTICATE *")[0]
Expand Down Expand Up @@ -628,10 +625,54 @@ def test_sasl_scram_sha_256_nonsense_server_final(mockbot):
scram_server.set_client_final(
b64decode(mockbot.backend.message_sent[-1].split(b" ")[-1]).decode("utf-8")
)
mockbot.on_message("AUTHENTICATE " + b64encode(b"junk").decode("utf-8"))
assert (
len(mockbot.backend.message_sent) == 4
and mockbot.backend.message_sent[-1] == rawlist("AUTHENTICATE *")[0]
)


def test_sasl_scram_sha_256_error_server_first(mockbot):
"""Verify the bot handles an error SCRAM-SHA-256 server_first correctly."""

mockbot.settings.core.auth_method = "sasl"
mockbot.settings.core.auth_target = "SCRAM-SHA-256"
mockbot.on_message("CAP TestBot ACK :sasl")
mockbot.on_message("AUTHENTICATE +")

mockbot.on_message("AUTHENTICATE " + b64encode(b"e=some-error").decode("utf-8"))
assert (
len(mockbot.backend.message_sent) == 3
and mockbot.backend.message_sent[-1] == rawlist("AUTHENTICATE *")[0]
)


def test_sasl_scram_sha_256_error_server_final(mockbot):
"""Verify the bot handles an error SCRAM-SHA-256 server_final correctly."""
mech = ScramMechanism()
salt, stored_key, server_key, iter_count = mech.make_auth_info(
"hunter2", iteration_count=5000
)
scram_server = mech.make_server(
lambda x: (salt, stored_key, server_key, iter_count)
)

mockbot.settings.core.auth_method = "sasl"
mockbot.settings.core.auth_target = "SCRAM-SHA-256"
mockbot.on_message("CAP TestBot ACK :sasl")
mockbot.on_message("AUTHENTICATE +")

scram_server.set_client_first(
b64decode(mockbot.backend.message_sent[-1].split(b" ")[-1]).decode("utf-8")
)
mockbot.on_message(
"AUTHENTICATE "
+ b64encode(b"j=unk").decode("utf-8")
+ b64encode(scram_server.get_server_first().encode("utf-8")).decode("utf-8")
)
scram_server.set_client_final(
b64decode(mockbot.backend.message_sent[-1].split(b" ")[-1]).decode("utf-8")
)
mockbot.on_message("AUTHENTICATE " + b64encode(b"e=some-error").decode("utf-8"))
assert (
len(mockbot.backend.message_sent) == 4
and mockbot.backend.message_sent[-1] == rawlist("AUTHENTICATE *")[0]
Expand Down

0 comments on commit 8796ff7

Please sign in to comment.