irctest/irctest/controllers/charybdis.py

103 lines
2.5 KiB
Python
Raw Normal View History

2015-12-21 17:01:36 +00:00
import os
import subprocess
from typing import Set
2015-12-21 17:01:36 +00:00
2021-02-22 18:04:23 +00:00
from irctest.basecontrollers import (
BaseServerController,
DirectoryBasedController,
NotImplementedByController,
)
2015-12-21 17:01:36 +00:00
TEMPLATE_CONFIG = """
serverinfo {{
name = "My.Little.Server";
sid = "42X";
description = "test server";
2015-12-25 14:45:06 +00:00
{ssl_config}
2015-12-21 17:01:36 +00:00
}};
listen {{
defer_accept = yes;
host = "{hostname}";
port = {port};
}};
auth {{
user = "*";
flags = exceed_limit;
2015-12-21 17:01:36 +00:00
{password_field}
}};
channel {{
disable_local_channels = no;
no_create_on_split = no;
no_join_on_split = no;
displayed_usercount = 0;
2015-12-21 17:01:36 +00:00
}};
"""
2015-12-25 14:45:06 +00:00
TEMPLATE_SSL_CONFIG = """
ssl_private_key = "{key_path}";
ssl_cert = "{pem_path}";
ssl_dh_params = "{dh_path}";
"""
2015-12-21 17:01:36 +00:00
class CharybdisController(BaseServerController, DirectoryBasedController):
2021-02-22 18:02:13 +00:00
software_name = "Charybdis"
2021-02-27 13:43:52 +00:00
binary_name = "charybdis"
supported_sasl_mechanisms: Set[str] = set()
supports_sts = False
2021-02-22 18:02:13 +00:00
2015-12-21 17:01:36 +00:00
def create_config(self):
super().create_config()
2021-02-22 18:02:13 +00:00
with self.open_file("server.conf"):
2015-12-21 17:01:36 +00:00
pass
2021-02-22 18:02:13 +00:00
def run(
self,
hostname,
port,
password=None,
ssl=False,
valid_metadata_keys=None,
invalid_metadata_keys=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-21 17:01:36 +00:00
assert self.proc is None
self.create_config()
self.port = port
2021-02-22 18:02:13 +00:00
password_field = 'password = "{}";'.format(password) if password else ""
2015-12-25 14:45:06 +00:00
if ssl:
self.gen_ssl()
ssl_config = TEMPLATE_SSL_CONFIG.format(
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 = ""
with self.open_file("server.conf") as fd:
fd.write(
TEMPLATE_CONFIG.format(
hostname=hostname,
port=port,
password_field=password_field,
ssl_config=ssl_config,
)
)
2021-02-22 18:02:13 +00:00
self.proc = subprocess.Popen(
[
2021-02-27 13:43:52 +00:00
self.binary_name,
2021-02-22 18:02:13 +00:00
"-foreground",
"-configfile",
os.path.join(self.directory, "server.conf"),
"-pidfile",
os.path.join(self.directory, "server.pid"),
],
2021-02-27 13:43:52 +00:00
# stderr=subprocess.DEVNULL,
2021-02-22 18:02:13 +00:00
)
2015-12-21 17:01:36 +00:00
2015-12-21 17:01:36 +00:00
def get_irctest_controller_class():
return CharybdisController