2015-12-21 17:01:36 +00:00
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import shutil
|
|
|
|
import tempfile
|
|
|
|
import subprocess
|
|
|
|
|
2015-12-21 19:12:22 +00:00
|
|
|
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 = "*";
|
2015-12-21 19:12:22 +00:00
|
|
|
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;
|
|
|
|
}};
|
|
|
|
"""
|
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):
|
2015-12-22 18:55:48 +00:00
|
|
|
software_name = 'Charybdis'
|
2015-12-21 19:12:22 +00:00
|
|
|
supported_sasl_mechanisms = set()
|
2015-12-21 17:01:36 +00:00
|
|
|
def create_config(self):
|
|
|
|
super().create_config()
|
|
|
|
with self.open_file('server.conf'):
|
|
|
|
pass
|
|
|
|
|
2015-12-25 14:45:06 +00:00
|
|
|
def run(self, hostname, port, password=None, ssl=False,
|
2015-12-22 21:33:23 +00:00
|
|
|
valid_metadata_keys=None, invalid_metadata_keys=None):
|
|
|
|
if valid_metadata_keys or invalid_metadata_keys:
|
|
|
|
raise NotImplementedByController(
|
|
|
|
'Defining valid and invalid METADATA keys.')
|
2015-12-21 17:01:36 +00:00
|
|
|
assert self.proc is None
|
|
|
|
self.create_config()
|
2015-12-23 00:54:10 +00:00
|
|
|
self.port = port
|
2015-12-21 17:01:36 +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,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
ssl_config = ''
|
2015-12-21 17:01:36 +00:00
|
|
|
with self.open_file('server.conf') as fd:
|
|
|
|
fd.write(TEMPLATE_CONFIG.format(
|
|
|
|
hostname=hostname,
|
|
|
|
port=port,
|
2015-12-25 14:45:06 +00:00
|
|
|
password_field=password_field,
|
|
|
|
ssl_config=ssl_config,
|
2015-12-21 17:01:36 +00:00
|
|
|
))
|
2015-12-21 19:12:22 +00:00
|
|
|
self.proc = subprocess.Popen(['ircd', '-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 19:12:22 +00:00
|
|
|
|
2015-12-21 17:01:36 +00:00
|
|
|
def get_irctest_controller_class():
|
|
|
|
return CharybdisController
|