Files
Shivaram Lingamneni 7e112359a2 secret channel test (#135)
* silent.py tests for channels with mode +s appearing in LIST only when the user is connected to that channel

* Added assertions for exact content of lines with command RPL_LIST and checks for exact number of RPL_LIST replies

* fix linter errors

* only validate the first two parameters of RPL_LIST

* rename to secret channel test, add citation

* ignore ngircd pseudo-channel

* attempt to fix charybdis/solanum and ircu issues

* review fixes

Co-authored-by: William Rehwinkel <willrehwinkel@gmail.com>
2022-03-04 21:58:05 +01:00

56 lines
2.2 KiB
Python

from irctest import cases
from irctest.numerics import RPL_LIST
class SecretChannelTestCase(cases.BaseServerTestCase):
@cases.mark_specifications("RFC1459", "Modern")
def testSecretChannelListCommand(self):
"""
<https://datatracker.ietf.org/doc/html/rfc1459#section-4.2.6>
"Likewise, secret channels are not listed
at all unless the client is a member of the channel in question."
<https://modern.ircdocs.horse/#secret-channel-mode>
"A channel that is set to secret will not show up in responses to
the LIST or NAMES command unless the client sending the command is
joined to the channel."
"""
def get_listed_channels(replies):
channels = set()
for reply in replies:
# skip pseudo-channels (&SERVER, &NOTICES) listed by ngircd
# and ircu:
if reply.command == RPL_LIST and reply.params[1].startswith("#"):
channels.add(reply.params[1])
return channels
# test that a silent channel is shown in list if the user is in the channel.
self.connectClient("first", name="first")
self.joinChannel("first", "#gen")
self.getMessages("first")
self.sendLine("first", "MODE #gen +s")
# run command LIST
self.sendLine("first", "LIST")
replies = self.getMessages("first")
self.assertEqual(get_listed_channels(replies), {"#gen"})
# test that another client would not see the secret
# channel.
self.connectClient("second", name="second")
self.getMessages("second")
self.sendLine("second", "LIST")
replies = self.getMessages("second")
# RPL_LIST 322 should NOT be present this time.
self.assertEqual(get_listed_channels(replies), set())
# Second client will join the secret channel
# and call command LIST. The channel SHOULD
# appear this time.
self.joinChannel("second", "#gen")
self.sendLine("second", "LIST")
replies = self.getMessages("second")
# Should be only one line with command RPL_LIST
self.assertEqual(get_listed_channels(replies), {"#gen"})