From 83867dad3267603281244166444ec329c15d27d9 Mon Sep 17 00:00:00 2001 From: Val Lorentz Date: Wed, 13 Apr 2022 18:59:34 +0200 Subject: [PATCH] testWrongPassword: Add stricter check of the reply's command (#144) --- irctest/server_tests/connection_registration.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/irctest/server_tests/connection_registration.py b/irctest/server_tests/connection_registration.py index d726cfc..7399cb9 100644 --- a/irctest/server_tests/connection_registration.py +++ b/irctest/server_tests/connection_registration.py @@ -7,7 +7,7 @@ TODO: cross-reference Modern and RFC 2812 too from irctest import cases from irctest.client_mock import ConnectionClosed -from irctest.numerics import ERR_NEEDMOREPARAMS +from irctest.numerics import ERR_NEEDMOREPARAMS, ERR_PASSWDMISMATCH from irctest.patma import ANYSTR, StrRe @@ -38,8 +38,14 @@ class PasswordedConnectionRegistrationTestCase(cases.BaseServerTestCase): m.command, "001", msg="Got 001 after NICK+USER but missing PASS" ) - @cases.mark_specifications("RFC1459", "RFC2812") + @cases.mark_specifications("Modern") def testWrongPassword(self): + """ + "If the password supplied does not match the password expected by the server, + then the server SHOULD send ERR_PASSWDMISMATCH and MUST close the connection + with ERROR." + -- https://github.com/ircdocs/modern-irc/pull/172 + """ self.addClient() self.sendLine(1, "PASS {}".format(self.password + "garbage")) self.sendLine(1, "NICK foo") @@ -48,6 +54,13 @@ class PasswordedConnectionRegistrationTestCase(cases.BaseServerTestCase): self.assertNotEqual( m.command, "001", msg="Got 001 after NICK+USER but incorrect PASS" ) + self.assertIn(m.command, {ERR_PASSWDMISMATCH, "ERROR"}) + + if m.command == "ERR_PASSWDMISMATCH": + m = self.getRegistrationMessage(1) + self.assertEqual( + m.command, "ERROR", msg="ERR_PASSWDMISMATCH not followed by ERROR." + ) @cases.mark_specifications("RFC1459", "RFC2812", strict=True) def testPassAfterNickuser(self):