Skip to content

Commit

Permalink
avoid implicit cap-notify + switch from server-time to multi-prefix a…
Browse files Browse the repository at this point in the history
…s it's better supported + ignore Unreal
  • Loading branch information
progval committed Sep 2, 2023
1 parent 83f9401 commit d86a5df
Showing 1 changed file with 62 additions and 34 deletions.
96 changes: 62 additions & 34 deletions irctest/server_tests/cap.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def testInvalidCapSubcommand(self):
m = self.getRegistrationMessage(1)
self.assertTrue(
self.messageDiffers(m, command="PONG", params=[ANYSTR, "test123"]),
"Sending “CAP NOTACOMMAND” as first message got no reply"
"Sending “CAP NOTACOMMAND” as first message got no reply",
)
self.assertMessageMatch(
m,
Expand Down Expand Up @@ -56,27 +56,33 @@ def testNoReq(self):
)

@cases.mark_specifications("IRCv3")
@cases.xfailIfSoftware(
["UnrealIRCd"],
"UnrealIRCd sends a trailing space on CAP ACK: https://github.com/unrealircd/unrealircd/pull/148",
)
def testReqOne(self):
"""Tests requesting a single capability"""
self.addClient(1)
self.sendLine(1, "CAP LS 302")
self.sendLine(1, "CAP LS")
self.getCapLs(1)
self.sendLine(1, "USER foo foo foo :foo")
self.sendLine(1, "NICK foo")
self.sendLine(1, "CAP REQ :server-time")
self.sendLine(1, "CAP REQ :multi-prefix")
m = self.getRegistrationMessage(1)
self.assertMessageMatch(
m, command="CAP", params=[ANYSTR, "ACK", "server-time"],
fail_msg="Expected CAP ACK after sending CAP REQ, got {msg}."
m,
command="CAP",
params=[ANYSTR, "ACK", "multi-prefix"],
fail_msg="Expected CAP ACK after sending CAP REQ, got {msg}.",
)

self.sendLine(1, "CAP LIST")
m = self.getRegistrationMessage(1)
self.assertMessageMatch(
m,
command="CAP",
params=[ANYSTR, "LIST", "server-time"],
fail_msg="Expected CAP LIST after sending CAP LIST, got {msg}."
params=[ANYSTR, "LIST", "multi-prefix"],
fail_msg="Expected CAP LIST after sending CAP LIST, got {msg}.",
)

self.sendLine(1, "CAP END")
Expand All @@ -86,27 +92,33 @@ def testReqOne(self):
)

@cases.mark_specifications("IRCv3")
@cases.xfailIfSoftware(
["UnrealIRCd"],
"UnrealIRCd sends a trailing space on CAP ACK: https://github.com/unrealircd/unrealircd/pull/148",
)
def testReqTwo(self):
"""Tests requesting two capabilities at once"""
self.addClient(1)
self.sendLine(1, "CAP LS 302")
self.sendLine(1, "CAP LS")
self.getCapLs(1)
self.sendLine(1, "USER foo foo foo :foo")
self.sendLine(1, "NICK foo")
self.sendLine(1, "CAP REQ :server-time userhost-in-names")
self.sendLine(1, "CAP REQ :multi-prefix userhost-in-names")
m = self.getRegistrationMessage(1)
self.assertMessageMatch(
m, command="CAP", params=[ANYSTR, "ACK", "server-time userhost-in-names"],
fail_msg="Expected CAP ACK after sending CAP REQ, got {msg}."
m,
command="CAP",
params=[ANYSTR, "ACK", "multi-prefix userhost-in-names"],
fail_msg="Expected CAP ACK after sending CAP REQ, got {msg}.",
)

self.sendLine(1, "CAP LIST")
m = self.getRegistrationMessage(1)
self.assertMessageMatch(
m,
command="CAP",
params=[ANYSTR, "LIST", "server-time userhost-in-names"],
fail_msg="Expected CAP LIST after sending CAP LIST, got {msg}."
params=[ANYSTR, "LIST", "multi-prefix userhost-in-names"],
fail_msg="Expected CAP LIST after sending CAP LIST, got {msg}.",
)

self.sendLine(1, "CAP END")
Expand All @@ -116,35 +128,43 @@ def testReqTwo(self):
)

@cases.mark_specifications("IRCv3")
@cases.xfailIfSoftware(
["UnrealIRCd"],
"UnrealIRCd sends a trailing space on CAP ACK: https://github.com/unrealircd/unrealircd/pull/148",
)
def testReqOneThenOne(self):
"""Tests requesting two capabilities in different messages"""
self.addClient(1)
self.sendLine(1, "CAP LS 302")
self.sendLine(1, "CAP LS")
self.getCapLs(1)
self.sendLine(1, "USER foo foo foo :foo")
self.sendLine(1, "NICK foo")

self.sendLine(1, "CAP REQ :server-time")
self.sendLine(1, "CAP REQ :multi-prefix")
m = self.getRegistrationMessage(1)
self.assertMessageMatch(
m, command="CAP", params=[ANYSTR, "ACK", "server-time"],
fail_msg="Expected CAP ACK after sending CAP REQ, got {msg}."
m,
command="CAP",
params=[ANYSTR, "ACK", "multi-prefix"],
fail_msg="Expected CAP ACK after sending CAP REQ, got {msg}.",
)

self.sendLine(1, "CAP REQ :userhost-in-names")
m = self.getRegistrationMessage(1)
self.assertMessageMatch(
m, command="CAP", params=[ANYSTR, "ACK", "userhost-in-names"],
fail_msg="Expected CAP ACK after sending CAP REQ, got {msg}."
m,
command="CAP",
params=[ANYSTR, "ACK", "userhost-in-names"],
fail_msg="Expected CAP ACK after sending CAP REQ, got {msg}.",
)

self.sendLine(1, "CAP LIST")
m = self.getRegistrationMessage(1)
self.assertMessageMatch(
m,
command="CAP",
params=[ANYSTR, "LIST", "server-time userhost-in-names"],
fail_msg="Expected CAP LIST after sending CAP LIST, got {msg}."
params=[ANYSTR, "LIST", "multi-prefix userhost-in-names"],
fail_msg="Expected CAP LIST after sending CAP LIST, got {msg}.",
)

self.sendLine(1, "CAP END")
Expand All @@ -154,28 +174,34 @@ def testReqOneThenOne(self):
)

@cases.mark_specifications("IRCv3")
@cases.xfailIfSoftware(
["UnrealIRCd"],
"UnrealIRCd sends a trailing space on CAP ACK: https://github.com/unrealircd/unrealircd/pull/148",
)
def testReqPostRegistration(self):
"""Tests requesting more capabilities after CAP END"""
self.addClient(1)
self.sendLine(1, "CAP LS 302")
self.sendLine(1, "CAP LS")
self.getCapLs(1)
self.sendLine(1, "USER foo foo foo :foo")
self.sendLine(1, "NICK foo")

self.sendLine(1, "CAP REQ :server-time")
self.sendLine(1, "CAP REQ :multi-prefix")
m = self.getRegistrationMessage(1)
self.assertMessageMatch(
m, command="CAP", params=[ANYSTR, "ACK", "server-time"],
fail_msg="Expected CAP ACK after sending CAP REQ, got {msg}."
m,
command="CAP",
params=[ANYSTR, "ACK", "multi-prefix"],
fail_msg="Expected CAP ACK after sending CAP REQ, got {msg}.",
)

self.sendLine(1, "CAP LIST")
m = self.getRegistrationMessage(1)
self.assertMessageMatch(
m,
command="CAP",
params=[ANYSTR, "LIST", "server-time"],
fail_msg="Expected CAP LIST after sending CAP LIST, got {msg}."
params=[ANYSTR, "LIST", "multi-prefix"],
fail_msg="Expected CAP LIST after sending CAP LIST, got {msg}.",
)

self.sendLine(1, "CAP END")
Expand All @@ -189,17 +215,19 @@ def testReqPostRegistration(self):
self.sendLine(1, "CAP REQ :userhost-in-names")
m = self.getRegistrationMessage(1)
self.assertMessageMatch(
m, command="CAP", params=[ANYSTR, "ACK", "userhost-in-names"],
fail_msg="Expected CAP ACK after sending CAP REQ, got {msg}."
m,
command="CAP",
params=[ANYSTR, "ACK", "userhost-in-names"],
fail_msg="Expected CAP ACK after sending CAP REQ, got {msg}.",
)

self.sendLine(1, "CAP LIST")
m = self.getMessage(1)
self.assertMessageMatch(
m,
command="CAP",
params=[ANYSTR, "LIST", "server-time userhost-in-names"],
fail_msg="Expected CAP LIST after sending CAP LIST, got {msg}."
params=[ANYSTR, "LIST", "multi-prefix userhost-in-names"],
fail_msg="Expected CAP LIST after sending CAP LIST, got {msg}.",
)

@cases.mark_specifications("IRCv3")
Expand Down Expand Up @@ -309,7 +337,7 @@ def testNakWhole(self):
def testCapRemovalByClient(self):
"""Test CAP LIST and removal of caps via CAP REQ :-tagname."""
cap1 = "echo-message"
cap2 = "server-time"
cap2 = "multi-prefix"
self.addClient(1)
self.connectClient("sender")
self.sendLine(1, "CAP LS 302")
Expand Down Expand Up @@ -340,7 +368,7 @@ def testCapRemovalByClient(self):
m = self.getMessage(1)
self.assertIn("time", m.tags, m)

# remove the server-time cap
# remove the multi-prefix cap
self.sendLine(1, f"CAP REQ :-{cap2}")
m = self.getMessage(1)
# Must be either ACK or NAK
Expand All @@ -350,7 +378,7 @@ def testCapRemovalByClient(self):
)
raise ImplementationChoice(f"Does not support CAP REQ -{cap2}")

# server-time should be disabled
# multi-prefix should be disabled
self.sendLine(1, "CAP LIST")
messages = self.getMessages(1)
cap_list = [m for m in messages if m.command == "CAP"][0]
Expand Down

0 comments on commit d86a5df

Please sign in to comment.