2022-03-20 13:05:45 +00:00
|
|
|
import shutil
|
2015-12-19 22:09:06 +00:00
|
|
|
import subprocess
|
2021-02-28 16:08:27 +00:00
|
|
|
from typing import Optional, Set, Type
|
2015-12-19 22:09:06 +00:00
|
|
|
|
2021-02-22 18:04:23 +00:00
|
|
|
from irctest.basecontrollers import (
|
|
|
|
BaseServerController,
|
|
|
|
DirectoryBasedController,
|
|
|
|
NotImplementedByController,
|
|
|
|
)
|
2021-06-27 12:42:13 +00:00
|
|
|
from irctest.irc_utils.junkdrawer import find_hostname_and_port
|
2015-12-19 22:09:06 +00:00
|
|
|
|
|
|
|
TEMPLATE_CONFIG = """
|
2021-06-27 12:42:13 +00:00
|
|
|
# Clients:
|
2015-12-19 22:09:06 +00:00
|
|
|
<bind address="{hostname}" port="{port}" type="clients">
|
2015-12-25 14:45:06 +00:00
|
|
|
{ssl_config}
|
2021-06-27 12:42:13 +00:00
|
|
|
<connect allow="*"
|
|
|
|
resolvehostnames="no" # Faster
|
|
|
|
recvq="40960" # Needs to be larger than a valid message with tags
|
|
|
|
timeout="10" # So tests don't hang too long
|
2021-11-25 19:32:05 +00:00
|
|
|
localmax="1000"
|
|
|
|
globalmax="1000"
|
2021-06-27 12:42:13 +00:00
|
|
|
{password_field}>
|
|
|
|
|
2021-08-29 14:38:38 +00:00
|
|
|
<class
|
|
|
|
name="ServerOperators"
|
2021-09-19 13:33:31 +00:00
|
|
|
commands="WALLOPS GLOBOPS"
|
2021-08-29 14:38:38 +00:00
|
|
|
privs="channels/auspex users/auspex channels/auspex servers/auspex"
|
|
|
|
>
|
|
|
|
<type
|
|
|
|
name="NetAdmin"
|
|
|
|
classes="ServerOperators"
|
|
|
|
>
|
|
|
|
<oper name="operuser"
|
|
|
|
password="operpassword"
|
|
|
|
host="*@*"
|
|
|
|
type="NetAdmin"
|
|
|
|
class="ServerOperators"
|
|
|
|
>
|
|
|
|
|
2021-07-07 13:06:00 +00:00
|
|
|
<options casemapping="ascii">
|
|
|
|
|
2021-08-26 19:04:45 +00:00
|
|
|
# Disable 'NOTICE #chan :*** foo invited bar into the channel-
|
|
|
|
<security announceinvites="none">
|
|
|
|
|
2021-06-27 12:42:13 +00:00
|
|
|
# Services:
|
|
|
|
<bind address="{services_hostname}" port="{services_port}" type="servers">
|
|
|
|
<link name="services.example.org"
|
|
|
|
ipaddr="{services_hostname}"
|
|
|
|
port="{services_port}"
|
|
|
|
allowmask="*"
|
|
|
|
recvpass="password"
|
|
|
|
sendpass="password"
|
|
|
|
>
|
|
|
|
<module name="spanningtree">
|
|
|
|
<module name="services_account">
|
2021-07-07 13:06:00 +00:00
|
|
|
<module name="hidechans"> # Anope errors when missing
|
2021-06-27 12:42:13 +00:00
|
|
|
<module name="svshold"> # Atheme raises a warning when missing
|
|
|
|
<sasl requiressl="no"
|
|
|
|
target="services.example.org">
|
|
|
|
|
|
|
|
# Protocol:
|
2022-04-16 06:12:27 +00:00
|
|
|
<module name="banexception">
|
2021-07-01 13:34:26 +00:00
|
|
|
<module name="botmode">
|
2015-12-19 22:09:06 +00:00
|
|
|
<module name="cap">
|
2022-04-14 19:28:12 +00:00
|
|
|
<module name="inviteexception">
|
2015-12-19 22:44:51 +00:00
|
|
|
<module name="ircv3">
|
2021-06-27 12:42:13 +00:00
|
|
|
<module name="ircv3_accounttag">
|
2021-02-27 11:43:19 +00:00
|
|
|
<module name="ircv3_batch">
|
2015-12-19 22:44:51 +00:00
|
|
|
<module name="ircv3_capnotify">
|
2021-02-27 11:43:19 +00:00
|
|
|
<module name="ircv3_ctctags">
|
2015-12-24 19:52:36 +00:00
|
|
|
<module name="ircv3_echomessage">
|
2021-02-27 11:43:19 +00:00
|
|
|
<module name="ircv3_invitenotify">
|
|
|
|
<module name="ircv3_labeledresponse">
|
|
|
|
<module name="ircv3_msgid">
|
|
|
|
<module name="ircv3_servertime">
|
|
|
|
<module name="monitor">
|
2021-02-26 23:21:23 +00:00
|
|
|
<module name="m_muteban"> # for testing mute extbans
|
2015-12-20 01:20:12 +00:00
|
|
|
<module name="namesx"> # For multi-prefix
|
2021-06-27 12:42:13 +00:00
|
|
|
<module name="sasl">
|
|
|
|
|
2022-01-10 22:55:24 +00:00
|
|
|
# HELP/HELPOP
|
|
|
|
<module name="alias"> # for the HELP alias
|
|
|
|
<module name="helpop">
|
|
|
|
<include file="examples/helpop.conf.example">
|
|
|
|
|
2021-06-27 12:42:13 +00:00
|
|
|
# Misc:
|
2015-12-21 15:36:22 +00:00
|
|
|
<log method="file" type="*" level="debug" target="/tmp/ircd-{port}.log">
|
2022-04-13 16:56:29 +00:00
|
|
|
<server name="My.Little.Server" description="test server" id="000" network="testnet">
|
2015-12-19 22:09:06 +00:00
|
|
|
"""
|
|
|
|
|
2015-12-25 14:45:06 +00:00
|
|
|
TEMPLATE_SSL_CONFIG = """
|
|
|
|
<module name="ssl_openssl">
|
|
|
|
<openssl certfile="{pem_path}" keyfile="{key_path}" dhfile="{dh_path}" hash="sha1">
|
|
|
|
"""
|
|
|
|
|
2021-02-22 18:02:13 +00:00
|
|
|
|
2021-06-27 13:10:10 +00:00
|
|
|
class InspircdController(BaseServerController, DirectoryBasedController):
|
2021-02-22 18:02:13 +00:00
|
|
|
software_name = "InspIRCd"
|
2021-06-27 12:42:13 +00:00
|
|
|
supported_sasl_mechanisms = {"PLAIN"}
|
|
|
|
supports_sts = False
|
2021-07-02 19:41:35 +00:00
|
|
|
extban_mute_char = "m"
|
2019-12-08 20:26:21 +00:00
|
|
|
|
2021-02-28 16:08:27 +00:00
|
|
|
def create_config(self) -> None:
|
2015-12-19 22:09:06 +00:00
|
|
|
super().create_config()
|
2021-02-22 18:02:13 +00:00
|
|
|
with self.open_file("server.conf"):
|
2015-12-19 22:09:06 +00:00
|
|
|
pass
|
|
|
|
|
2021-02-22 18:02:13 +00:00
|
|
|
def run(
|
|
|
|
self,
|
2021-02-28 16:08:27 +00:00
|
|
|
hostname: str,
|
|
|
|
port: int,
|
|
|
|
*,
|
|
|
|
password: Optional[str],
|
|
|
|
ssl: bool,
|
2021-06-27 12:42:13 +00:00
|
|
|
run_services: bool,
|
2021-02-28 16:08:27 +00:00
|
|
|
valid_metadata_keys: Optional[Set[str]] = None,
|
|
|
|
invalid_metadata_keys: Optional[Set[str]] = None,
|
|
|
|
restricted_metadata_keys: Optional[Set[str]] = None,
|
2022-03-20 13:05:45 +00:00
|
|
|
faketime: Optional[str] = None,
|
2021-02-28 16:08:27 +00:00
|
|
|
) -> None:
|
2015-12-22 21:33:23 +00:00
|
|
|
if valid_metadata_keys or invalid_metadata_keys:
|
|
|
|
raise NotImplementedByController(
|
2021-02-22 18:02:13 +00:00
|
|
|
"Defining valid and invalid METADATA keys."
|
|
|
|
)
|
2015-12-19 22:09:06 +00:00
|
|
|
assert self.proc is None
|
2015-12-23 00:54:10 +00:00
|
|
|
self.port = port
|
2021-06-27 12:42:13 +00:00
|
|
|
self.hostname = hostname
|
2015-12-19 22:09:06 +00:00
|
|
|
self.create_config()
|
2021-06-27 12:42:13 +00:00
|
|
|
(services_hostname, services_port) = find_hostname_and_port()
|
|
|
|
|
2021-02-22 18:02:13 +00:00
|
|
|
password_field = 'password="{}"'.format(password) if password else ""
|
2021-06-27 12:42:13 +00:00
|
|
|
|
2015-12-25 14:45:06 +00:00
|
|
|
if ssl:
|
|
|
|
self.gen_ssl()
|
|
|
|
ssl_config = TEMPLATE_SSL_CONFIG.format(
|
2021-02-22 18:27:43 +00:00
|
|
|
key_path=self.key_path, pem_path=self.pem_path, dh_path=self.dh_path
|
2021-02-22 18:02:13 +00:00
|
|
|
)
|
2015-12-25 14:45:06 +00:00
|
|
|
else:
|
2021-02-22 18:02:13 +00:00
|
|
|
ssl_config = ""
|
2021-06-27 12:42:13 +00:00
|
|
|
|
2021-02-22 18:02:13 +00:00
|
|
|
with self.open_file("server.conf") as fd:
|
|
|
|
fd.write(
|
|
|
|
TEMPLATE_CONFIG.format(
|
|
|
|
hostname=hostname,
|
|
|
|
port=port,
|
2021-06-27 12:42:13 +00:00
|
|
|
services_hostname=services_hostname,
|
|
|
|
services_port=services_port,
|
2021-02-22 18:02:13 +00:00
|
|
|
password_field=password_field,
|
|
|
|
ssl_config=ssl_config,
|
|
|
|
)
|
2015-12-21 19:12:57 +00:00
|
|
|
)
|
2021-02-28 16:08:27 +00:00
|
|
|
assert self.directory
|
2022-03-20 13:05:45 +00:00
|
|
|
|
|
|
|
if faketime and shutil.which("faketime"):
|
|
|
|
faketime_cmd = ["faketime", "-f", faketime]
|
|
|
|
self.faketime_enabled = True
|
|
|
|
else:
|
|
|
|
faketime_cmd = []
|
|
|
|
|
2021-02-22 18:02:13 +00:00
|
|
|
self.proc = subprocess.Popen(
|
|
|
|
[
|
2022-03-20 13:05:45 +00:00
|
|
|
*faketime_cmd,
|
2021-02-22 18:02:13 +00:00
|
|
|
"inspircd",
|
|
|
|
"--nofork",
|
|
|
|
"--config",
|
2022-09-10 09:38:29 +00:00
|
|
|
self.directory / "server.conf",
|
2021-02-22 18:02:13 +00:00
|
|
|
],
|
|
|
|
stdout=subprocess.DEVNULL,
|
|
|
|
)
|
|
|
|
|
2021-06-27 12:42:13 +00:00
|
|
|
if run_services:
|
2021-06-27 14:48:21 +00:00
|
|
|
self.wait_for_port()
|
2021-07-07 11:30:16 +00:00
|
|
|
self.services_controller = self.services_controller_class(
|
|
|
|
self.test_config, self
|
|
|
|
)
|
2021-06-27 13:10:10 +00:00
|
|
|
self.services_controller.run(
|
2021-07-07 11:30:16 +00:00
|
|
|
protocol="inspircd3",
|
2021-06-27 14:48:21 +00:00
|
|
|
server_hostname=services_hostname,
|
|
|
|
server_port=services_port,
|
2021-06-27 12:42:13 +00:00
|
|
|
)
|
|
|
|
|
2015-12-19 22:09:06 +00:00
|
|
|
|
2021-02-28 16:08:27 +00:00
|
|
|
def get_irctest_controller_class() -> Type[InspircdController]:
|
2015-12-19 22:09:06 +00:00
|
|
|
return InspircdController
|