|
1 | 1 | import base64
|
2 | 2 |
|
3 | 3 | from irctest import cases, runner, scram
|
4 |
| -from irctest.numerics import ERR_SASLFAIL |
| 4 | +from irctest.numerics import ERR_SASLFAIL, RPL_LOGGEDIN, RPL_SASLMECHS |
5 | 5 | from irctest.patma import ANYSTR
|
6 | 6 |
|
7 | 7 |
|
@@ -48,11 +48,37 @@ def testPlain(self):
|
48 | 48 | m = self.getRegistrationMessage(1)
|
49 | 49 | self.assertMessageMatch(
|
50 | 50 | m,
|
51 |
| - command="900", |
| 51 | + command=RPL_LOGGEDIN, |
52 | 52 | params=[ANYSTR, ANYSTR, "jilles", ANYSTR],
|
53 | 53 | fail_msg="Unexpected reply to correct SASL authentication: {msg}",
|
54 | 54 | )
|
55 | 55 |
|
| 56 | + @cases.mark_specifications("IRCv3") |
| 57 | + @cases.skipUnlessHasMechanism("PLAIN") |
| 58 | + def testPlainFailure(self): |
| 59 | + """PLAIN authentication with incorrect username/password.""" |
| 60 | + self.controller.registerUser(self, "jilles", "sesame") |
| 61 | + self.addClient() |
| 62 | + self.requestCapabilities(1, ["sasl"], skip_if_cap_nak=False) |
| 63 | + self.sendLine(1, "AUTHENTICATE PLAIN") |
| 64 | + m = self.getRegistrationMessage(1) |
| 65 | + self.assertMessageMatch( |
| 66 | + m, |
| 67 | + command="AUTHENTICATE", |
| 68 | + params=["+"], |
| 69 | + fail_msg="Sent “AUTHENTICATE PLAIN”, server should have " |
| 70 | + "replied with “AUTHENTICATE +”, but instead sent: {msg}", |
| 71 | + ) |
| 72 | + # password 'millet' |
| 73 | + self.sendLine(1, "AUTHENTICATE amlsbGVzAGppbGxlcwBtaWxsZXQ=") |
| 74 | + m = self.getRegistrationMessage(1) |
| 75 | + self.assertMessageMatch( |
| 76 | + m, |
| 77 | + command=ERR_SASLFAIL, |
| 78 | + params=[ANYSTR, ANYSTR], |
| 79 | + fail_msg="Unexpected reply to incorrect SASL authentication: {msg}", |
| 80 | + ) |
| 81 | + |
56 | 82 | @cases.mark_specifications("IRCv3")
|
57 | 83 | @cases.skipUnlessHasMechanism("PLAIN")
|
58 | 84 | def testPlainNonAscii(self):
|
@@ -161,11 +187,11 @@ def testMechanismNotAvailable(self):
|
161 | 187 | self.requestCapabilities(1, ["sasl"], skip_if_cap_nak=False)
|
162 | 188 | self.sendLine(1, "AUTHENTICATE FOO")
|
163 | 189 | m = self.getRegistrationMessage(1)
|
164 |
| - while m.command == "908": # RPL_SASLMECHS |
| 190 | + while m.command == RPL_SASLMECHS: |
165 | 191 | m = self.getRegistrationMessage(1)
|
166 | 192 | self.assertMessageMatch(
|
167 | 193 | m,
|
168 |
| - command="904", |
| 194 | + command=ERR_SASLFAIL, |
169 | 195 | fail_msg="Did not reply with 904 to “AUTHENTICATE FOO”: {msg}",
|
170 | 196 | )
|
171 | 197 |
|
|
0 commit comments