Skip to content

Commit

Permalink
Add SETNAME tests (#209)
Browse files Browse the repository at this point in the history
* Add SETNAME tests

* fix race condition

* fix synchronization issue

sendLine does not synchronize by itself; call getMessage to synchronize
and test the message since we have it

* Update irctest/server_tests/setname.py

Co-authored-by: Val Lorentz <[email protected]>

---------

Co-authored-by: Shivaram Lingamneni <[email protected]>
Co-authored-by: Val Lorentz <[email protected]>
  • Loading branch information
3 people authored Jun 4, 2023
1 parent e5f22e8 commit 321e254
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions irctest/server_tests/setname.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
`IRCv3 SETNAME<https://ircv3.net/specs/extensions/setname>`_
"""

from irctest import cases
from irctest.numerics import RPL_WHOISUSER


class SetnameMessageTestCase(cases.BaseServerTestCase):
@cases.mark_specifications("IRCv3")
@cases.mark_capabilities("setname")
def testSetnameMessage(self):
self.connectClient("foo", capabilities=["setname"], skip_if_cap_nak=True)

self.sendLine(1, "SETNAME bar")
self.assertMessageMatch(
self.getMessage(1),
command="SETNAME",
params=["bar"],
)

self.sendLine(1, "WHOIS foo")
whoisuser = [m for m in self.getMessages(1) if m.command == RPL_WHOISUSER][0]
self.assertEqual(whoisuser.params[-1], "bar")

@cases.mark_specifications("IRCv3")
@cases.mark_capabilities("setname")
def testSetnameChannel(self):
"""“[Servers] MUST send the server-to-client version of the
SETNAME message to all clients in common channels, as well as
to the client from which it originated, to confirm the change
has occurred.
The SETNAME message MUST NOT be sent to clients which do not
have the setname capability negotiated.“
"""
self.connectClient("foo", capabilities=["setname"], skip_if_cap_nak=True)
self.connectClient("bar", capabilities=["setname"], skip_if_cap_nak=True)
self.connectClient("baz")

self.joinChannel(1, "#chan")
self.joinChannel(2, "#chan")
self.joinChannel(3, "#chan")
self.getMessages(1)
self.getMessages(2)
self.getMessages(3)

self.sendLine(1, "SETNAME qux")
self.assertMessageMatch(
self.getMessage(1),
command="SETNAME",
params=["qux"],
)

self.assertMessageMatch(
self.getMessage(2),
command="SETNAME",
params=["qux"],
)

self.assertEqual(
self.getMessages(3),
[],
"Got SETNAME response when it was not negotiated",
)

0 comments on commit 321e254

Please sign in to comment.