irctest/irctest/controllers/charybdis.py

105 lines
2.6 KiB
Python
Raw Normal View History

2015-12-21 17:01:36 +00:00
import os
import time
import shutil
import tempfile
import subprocess
from irctest import client_mock
2015-12-21 17:01:36 +00:00
from irctest import authentication
2015-12-22 21:33:23 +00:00
from irctest.basecontrollers import NotImplementedByController
2015-12-21 17:01:36 +00:00
from irctest.basecontrollers import BaseServerController, DirectoryBasedController
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"
supported_sasl_mechanisms = set()
2019-12-08 20:26:21 +00:00
supported_capabilities = set() # Not exhaustive
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(
2021-02-22 18:02:13 +00:00
key_path=self.key_path,
pem_path=self.pem_path,
dh_path=self.dh_path,
)
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(
[
"charybdis",
"-foreground",
"-configfile",
os.path.join(self.directory, "server.conf"),
"-pidfile",
os.path.join(self.directory, "server.pid"),
],
stderr=subprocess.DEVNULL,
)
2015-12-21 17:01:36 +00:00
2015-12-21 17:01:36 +00:00
def get_irctest_controller_class():
return CharybdisController