Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 37 additions & 22 deletions irctest/server_tests/bouncer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,26 @@ def setUp(self):
self.sendLine(2, "USER a 0 * a")
self.sendLine(2, "CAP REQ :server-time message-tags")
self.sendLine(2, "CAP END")
messages = self.getMessages(2)
welcomes = [message for message in messages if message.command == RPL_WELCOME]
self.assertEqual(len(welcomes), 1)
# should see a regburst for testnick
self.assertMessageMatch(welcomes[0], params=["testnick", ANYSTR])
self._waitForWelcome(2, "testnick")
self.joinChannel(2, "#chan")

def _waitForWelcome(self, client, nick):
"""Waits for numeric 001, and returns every message after that."""
while True:
messages = iter(self.getMessages(client, synchronize=False))
for message in messages:
if message.command == "001":
# should see a regburst for testnick
self.assertMessageMatch(message, params=[nick, ANYSTR])

messages_after_welcome = list(messages)
messages_after_welcome += self.getMessages(client)

# check there is no other 001
for message in messages_after_welcome:
self.assertNotEqual(message.command, "001")
return messages_after_welcome

def _connectClient3(self):
self.addClient()
self.sendLine(3, "CAP LS 302")
Expand All @@ -48,11 +61,8 @@ def _connectClient3(self):
self.sendLine(3, "USER a 0 * a")
self.sendLine(3, "CAP REQ :server-time message-tags account-tag")
self.sendLine(3, "CAP END")
messages = self.getMessages(3)
welcomes = [message for message in messages if message.command == RPL_WELCOME]
self.assertEqual(len(welcomes), 1)
# should see the *same* regburst for testnick
self.assertMessageMatch(welcomes[0], params=["testnick", ANYSTR])
messages = self._waitForWelcome(3, "testnick")
joins = [message for message in messages if message.command == "JOIN"]
# we should be automatically joined to #chan
self.assertMessageMatch(joins[0], params=["#chan"])
Expand All @@ -68,16 +78,15 @@ def _connectClient4(self):
self.sendLine(4, "USER a 0 * a")
self.sendLine(4, "CAP REQ server-time")
self.sendLine(4, "CAP END")
messages = self.getMessages(4)
welcomes = [message for message in messages if message.command == RPL_WELCOME]
self.assertEqual(len(welcomes), 1)
# should see the *same* regburst for testnick
self._waitForWelcome(4, "testnick")

@cases.mark_specifications("Ergo")
@cases.mark_specifications("Ergo", "Sable")
def testAutomaticResumption(self):
"""Test logging into an account that already has a client joins the client's session"""
self._connectClient3()

@cases.mark_specifications("Ergo")
@cases.mark_specifications("Ergo", "Sable")
def testChannelMessageFromOther(self):
"""Test that all clients attached to a session get messages sent by someone else
to a channel"""
Expand Down Expand Up @@ -111,7 +120,7 @@ def testChannelMessageFromOther(self):
self.assertNotIn("account", messageforfour.tags)
self.assertNotIn("msgid", messageforfour.tags)

@cases.mark_specifications("Ergo")
@cases.mark_specifications("Ergo", "Sable")
def testChannelMessageFromSelf(self):
"""Test that all clients attached to a session get messages sent by an other client

Expand Down Expand Up @@ -149,7 +158,7 @@ def testChannelMessageFromSelf(self):
self.assertNotIn("account", messageforfour.tags)
self.assertNotIn("msgid", messageforfour.tags)

@cases.mark_specifications("Ergo")
@cases.mark_specifications("Ergo", "Sable")
def testDirectMessageFromOther(self):
"""Test that all clients attached to a session get copies of messages sent
by an other client of that session directly to an other user"""
Expand All @@ -167,7 +176,7 @@ def testDirectMessageFromOther(self):
self.assertEqual(messagefortwo.params, messageforthree.params)
self.assertEqual(messagefortwo.tags["msgid"], messageforthree.tags["msgid"])

@cases.mark_specifications("Ergo")
@cases.mark_specifications("Ergo", "Sable")
def testDirectMessageFromSelf(self):
"""Test that all clients attached to a session get copies of messages sent
by an other client of that session directly to an other user"""
Expand All @@ -187,17 +196,20 @@ def testDirectMessageFromSelf(self):
messageForRecipient.tags["msgid"], copyForOtherSession.tags["msgid"]
)

@cases.mark_specifications("Ergo")
@cases.mark_specifications("Ergo", "Sable")
def testQuit(self):
"""Test that a single client of a session does not make the whole user quit
(and is generally not visible to anyone else, not even their other sessions),
until the last client quits"""
self._connectClient3()
self._connectClient4()
self.sendLine(2, "QUIT :two out")
quitLines = [msg for msg in self.getMessages(2) if msg.command == "QUIT"]
quitLines = [
msg for msg in self.getMessages(2) if msg.command in ("QUIT", "ERROR")
]
self.assertEqual(len(quitLines), 1)
self.assertMessageMatch(quitLines[0], params=[StrRe(".*two out.*")])
if quitLines[0].command == "QUIT":
self.assertMessageMatch(quitLines[0], params=[StrRe(".*two out.*")])
# neither the observer nor the other attached session should see a quit here
quitLines = [msg for msg in self.getMessages(1) if msg.command == "QUIT"]
self.assertEqual(quitLines, [])
Expand All @@ -218,9 +230,12 @@ def testQuit(self):
self.sendLine(4, "QUIT :four out")
self.getMessages(4)
self.sendLine(3, "QUIT :three out")
quitLines = [msg for msg in self.getMessages(3) if msg.command == "QUIT"]
quitLines = [
msg for msg in self.getMessages(3) if msg.command in ("QUIT", "ERROR")
]
self.assertEqual(len(quitLines), 1)
self.assertMessageMatch(quitLines[0], params=[StrRe(".*three out.*")])
if quitLines[0].command == "QUIT":
self.assertMessageMatch(quitLines[0], params=[StrRe(".*three out.*")])
# observer should see *this* quit
quitLines = [msg for msg in self.getMessages(1) if msg.command == "QUIT"]
self.assertEqual(len(quitLines), 1)
Expand Down
1 change: 1 addition & 0 deletions irctest/specifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Specifications(enum.Enum):
RFC2812 = "RFC2812"
IRCv3 = "IRCv3" # Mark with capabilities whenever possible
Ergo = "Ergo"
SABLE = "Sable"

Ircdocs = "ircdocs"
"""Any document on ircdocs.horse (especially defs.ircdocs.horse),
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ markers =
modern
ircdocs
Ergo
Sable

# misc marks
strict
Expand Down
Loading