From 8796ff774894330206d0cbff85a93eac29d004c6 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Wed, 26 Oct 2022 14:01:56 -0400 Subject: [PATCH] more tests, test tweaks --- test/test_coretasks.py | 51 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/test/test_coretasks.py b/test/test_coretasks.py index cdb98837b7..b03dad5738 100644 --- a/test/test_coretasks.py +++ b/test/test_coretasks.py @@ -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] @@ -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]