Add tests for LINKS (#147)

This commit is contained in:
Val Lorentz 2022-04-13 18:56:29 +02:00 committed by GitHub
parent 6539ed881a
commit 363b62cc80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 140 additions and 4 deletions

View File

@ -83,7 +83,7 @@ TEMPLATE_CONFIG = """
# Misc: # Misc:
<log method="file" type="*" level="debug" target="/tmp/ircd-{port}.log"> <log method="file" type="*" level="debug" target="/tmp/ircd-{port}.log">
<server name="My.Little.Server" description="testnet" id="000" network="testnet"> <server name="My.Little.Server" description="test server" id="000" network="testnet">
""" """
TEMPLATE_SSL_CONFIG = """ TEMPLATE_SSL_CONFIG = """

View File

@ -10,7 +10,7 @@ from irctest.basecontrollers import (
TEMPLATE_CONFIG = """ TEMPLATE_CONFIG = """
# M:<Server NAME>:<YOUR Internet IP#>:<Geographic Location>:<Port>:<SID>: # M:<Server NAME>:<YOUR Internet IP#>:<Geographic Location>:<Port>:<SID>:
M:My.Little.Server:{hostname}:Somewhere:{port}:0042: M:My.Little.Server:{hostname}:test server:{port}:0042:
# A:<Your Name/Location>:<Your E-Mail Addr>:<other info>::<network name>: # A:<Your Name/Location>:<Your E-Mail Addr>:<other info>::<network name>:
A:Organization, IRC dept.:Daemon <ircd@example.irc.org>:Client Server::IRCnet: A:Organization, IRC dept.:Daemon <ircd@example.irc.org>:Client Server::IRCnet:

View File

@ -12,7 +12,7 @@ from irctest.irc_utils.junkdrawer import find_hostname_and_port
TEMPLATE_CONFIG = """ TEMPLATE_CONFIG = """
[Global] [Global]
Name = My.Little.Server Name = My.Little.Server
Info = ExampleNET Server Info = test server
Bind = {hostname} Bind = {hostname}
Ports = {port} Ports = {port}
AdminInfo1 = Bob Smith AdminInfo1 = Bob Smith

View File

@ -22,7 +22,7 @@ include "help/help.conf";
me {{ me {{
name "My.Little.Server"; name "My.Little.Server";
info "ExampleNET Server"; info "test server";
sid "001"; sid "001";
}} }}
admin {{ admin {{

View File

@ -0,0 +1,136 @@
from irctest import cases, runner
from irctest.numerics import ERR_UNKNOWNCOMMAND, RPL_ENDOFLINKS, RPL_LINKS
from irctest.patma import ANYSTR, StrRe
class LinksTestCase(cases.BaseServerTestCase):
@cases.mark_specifications("RFC1459", "RFC2812", "Modern")
def testLinksSingleServer(self):
"""
Only testing the parameter-less case.
https://datatracker.ietf.org/doc/html/rfc1459#section-4.3.3
https://datatracker.ietf.org/doc/html/rfc2812#section-3.4.5
https://github.com/ircdocs/modern-irc/pull/175
"
364 RPL_LINKS
"<mask> <server> :<hopcount> <server info>"
365 RPL_ENDOFLINKS
"<mask> :End of /LINKS list"
- In replying to the LINKS message, a server must send
replies back using the RPL_LINKS numeric and mark the
end of the list using an RPL_ENDOFLINKS reply.
"
-- https://datatracker.ietf.org/doc/html/rfc1459#page-51
-- https://datatracker.ietf.org/doc/html/rfc2812#page-48
RPL_LINKS: "<client> * <server> :<hopcount> <server info>"
RPL_ENDOFLINKS: "<client> * :End of /LINKS list"
-- https://github.com/ircdocs/modern-irc/pull/175/files
"""
self.connectClient("nick")
self.sendLine(1, "LINKS")
messages = self.getMessages(1)
if messages[0].command == ERR_UNKNOWNCOMMAND:
raise runner.NotImplementedByController("LINKS")
# Ignore '/LINKS has been disabled' from ircu2
messages = [m for m in messages if m.command != "NOTICE"]
self.assertMessageMatch(
messages.pop(-1),
command=RPL_ENDOFLINKS,
params=["nick", "*", ANYSTR],
)
if not messages:
# This server probably redacts links
return
self.assertMessageMatch(
messages[0],
command=RPL_LINKS,
params=[
"nick",
"My.Little.Server",
"My.Little.Server",
StrRe("0 (0042 )?test server"),
],
)
@cases.mark_services
class ServicesLinksTestCase(cases.BaseServerTestCase):
# On every IRCd but Ergo, services are linked.
# Ergo does not implement LINKS at all, so this test is skipped.
@cases.mark_specifications("RFC1459", "RFC2812", "Modern")
def testLinksWithServices(self):
"""
Only testing the parameter-less case.
https://datatracker.ietf.org/doc/html/rfc1459#section-4.3.3
https://datatracker.ietf.org/doc/html/rfc2812#section-3.4.5
"
364 RPL_LINKS
"<mask> <server> :<hopcount> <server info>"
365 RPL_ENDOFLINKS
"<mask> :End of /LINKS list"
- In replying to the LINKS message, a server must send
replies back using the RPL_LINKS numeric and mark the
end of the list using an RPL_ENDOFLINKS reply.
"
-- https://datatracker.ietf.org/doc/html/rfc1459#page-51
-- https://datatracker.ietf.org/doc/html/rfc2812#page-48
RPL_LINKS: "<client> * <server> :<hopcount> <server info>"
RPL_ENDOFLINKS: "<client> * :End of /LINKS list"
-- https://github.com/ircdocs/modern-irc/pull/175/files
"""
self.connectClient("nick")
self.sendLine(1, "LINKS")
messages = self.getMessages(1)
if messages[0].command == ERR_UNKNOWNCOMMAND:
raise runner.NotImplementedByController("LINKS")
# Ignore '/LINKS has been disabled' from ircu2
messages = [m for m in messages if m.command != "NOTICE"]
self.assertMessageMatch(
messages.pop(-1),
command=RPL_ENDOFLINKS,
params=["nick", "*", ANYSTR],
)
if not messages:
# This server redacts links
return
messages.sort(key=lambda m: m.params[-1])
self.assertMessageMatch(
messages.pop(0),
command=RPL_LINKS,
params=[
"nick",
"My.Little.Server",
"My.Little.Server",
StrRe("0 (0042 )?test server"),
],
)
self.assertMessageMatch(
messages.pop(0),
command=RPL_LINKS,
params=[
"nick",
"services.example.org",
"My.Little.Server",
StrRe("1 .+"), # SID instead of description for Anope...
],
)
self.assertEqual(messages, [])