mirror of
https://github.com/progval/irctest.git
synced 2025-04-06 07:19:54 +00:00
Add Mammon controller.
This commit is contained in:
@ -12,14 +12,17 @@ class DirectoryBasedController(_BaseController):
|
||||
super().__init__()
|
||||
self.directory = None
|
||||
self.proc = None
|
||||
|
||||
def kill_proc(self):
|
||||
self.proc.terminate()
|
||||
try:
|
||||
self.proc.wait(5)
|
||||
except subprocess.TimeoutExpired:
|
||||
self.proc.kill()
|
||||
self.proc = None
|
||||
def kill(self):
|
||||
if self.proc:
|
||||
self.proc.terminate()
|
||||
try:
|
||||
self.proc.wait(5)
|
||||
except subprocess.TimeoutExpired:
|
||||
self.proc.kill()
|
||||
self.proc = None
|
||||
self.kill_proc()
|
||||
if self.directory:
|
||||
shutil.rmtree(self.directory)
|
||||
def open_file(self, name, mode='a'):
|
||||
|
@ -8,6 +8,11 @@ from .irc_utils import message_parser
|
||||
class _IrcTestCase(unittest.TestCase):
|
||||
controllerClass = None # Will be set by __main__.py
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.controller = self.controllerClass()
|
||||
if self.show_io:
|
||||
print('---- new test ----')
|
||||
def getLine(self):
|
||||
raise NotImplementedError()
|
||||
def getMessage(self, *args, filter_pred=None):
|
||||
@ -41,7 +46,7 @@ class BaseClientTestCase(_IrcTestCase):
|
||||
nick = None
|
||||
user = None
|
||||
def setUp(self):
|
||||
self.controller = self.controllerClass()
|
||||
super().setUp()
|
||||
self._setUpServer()
|
||||
def tearDown(self):
|
||||
self.conn.sendall(b'QUIT :end of test.')
|
||||
@ -148,8 +153,8 @@ class BaseServerTestCase(_IrcTestCase):
|
||||
"""Basic class for server tests. Handles spawning a server and exchanging
|
||||
messages with it."""
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.find_hostname_and_port()
|
||||
self.controller = self.controllerClass()
|
||||
self.controller.run(self.hostname, self.port)
|
||||
self.clients = {}
|
||||
def tearDown(self):
|
||||
@ -192,3 +197,15 @@ class BaseServerTestCase(_IrcTestCase):
|
||||
assert ret is None
|
||||
if self.show_io:
|
||||
print('{} -> S: {}'.format(client, line.strip()))
|
||||
|
||||
def getCapLs(self, client):
|
||||
capabilities = []
|
||||
while True:
|
||||
m = self.getMessage(client,
|
||||
filter_pred=lambda m:m.command != 'NOTICE')
|
||||
self.assertMessageEqual(m, command='CAP', subcommand='LS')
|
||||
if m.params[2] == '*':
|
||||
capabilities.extend(m.params[3].split())
|
||||
else:
|
||||
capabilities.extend(m.params[2].split())
|
||||
return capabilities
|
||||
|
83
irctest/controllers/mammon.py
Normal file
83
irctest/controllers/mammon.py
Normal file
@ -0,0 +1,83 @@
|
||||
import os
|
||||
import time
|
||||
import shutil
|
||||
import tempfile
|
||||
import subprocess
|
||||
|
||||
from irctest import authentication
|
||||
from irctest.basecontrollers import BaseServerController, DirectoryBasedController
|
||||
|
||||
TEMPLATE_CONFIG = """
|
||||
clients:
|
||||
# ping_frequency - client ping frequency
|
||||
ping_frequency:
|
||||
minutes: 1000
|
||||
|
||||
# ping_timeout - ping timeout length
|
||||
ping_timeout:
|
||||
seconds: 10
|
||||
data:
|
||||
format: json
|
||||
filename: {directory}/data.json
|
||||
save_frequency:
|
||||
minutes: 5
|
||||
extensions:
|
||||
- mammon.ext.rfc1459.42
|
||||
- mammon.ext.rfc1459.ident
|
||||
- mammon.ext.ircv3.account_notify
|
||||
- mammon.ext.ircv3.server_time
|
||||
- mammon.ext.ircv3.echo_message
|
||||
- mammon.ext.ircv3.register
|
||||
- mammon.ext.ircv3.sasl
|
||||
- mammon.ext.misc.nopost
|
||||
metadata:
|
||||
restricted_keys:
|
||||
monitor:
|
||||
limit: 20
|
||||
motd:
|
||||
- "Hi"
|
||||
limits:
|
||||
foo: bar
|
||||
listeners:
|
||||
- {{"host": "{hostname}", "port": {port}, "ssl": false}}
|
||||
logs:
|
||||
{{
|
||||
}}
|
||||
register:
|
||||
foo: bar
|
||||
roles:
|
||||
"placeholder":
|
||||
title: "Just a placeholder"
|
||||
server:
|
||||
name: MyLittleServer
|
||||
network: MyLittleNetwork
|
||||
recvq_len: 20
|
||||
"""
|
||||
|
||||
class InspircdController(BaseServerController, DirectoryBasedController):
|
||||
def create_config(self):
|
||||
super().create_config()
|
||||
with self.open_file('server.conf'):
|
||||
pass
|
||||
|
||||
def kill_proc(self):
|
||||
# Mammon does not seem to handle SIGTERM very well
|
||||
self.proc.kill()
|
||||
|
||||
def run(self, hostname, port):
|
||||
assert self.proc is None
|
||||
self.create_config()
|
||||
with self.open_file('server.yml') as fd:
|
||||
fd.write(TEMPLATE_CONFIG.format(
|
||||
directory=self.directory,
|
||||
hostname=hostname,
|
||||
port=port,
|
||||
))
|
||||
self.proc = subprocess.Popen(['python3', '-m', 'mammon', '--nofork', #'--debug',
|
||||
'--config', os.path.join(self.directory, 'server.yml')])
|
||||
time.sleep(0.5) # FIXME: do better than this to wait for Mammon to start
|
||||
|
||||
def get_irctest_controller_class():
|
||||
return InspircdController
|
||||
|
||||
|
@ -5,9 +5,7 @@ class CapTestCase(cases.BaseServerTestCase):
|
||||
def testNoReq(self):
|
||||
self.addClient(1)
|
||||
self.sendLine(1, 'CAP LS 302')
|
||||
m = self.getMessage(1, filter_pred=lambda m:m.command != 'NOTICE')
|
||||
self.assertMessageEqual(m, command='CAP', target='*',
|
||||
subcommand='LS')
|
||||
self.getCapLs(1)
|
||||
self.sendLine(1, 'USER foo foo foo :foo')
|
||||
self.sendLine(1, 'NICK foo')
|
||||
self.sendLine(1, 'CAP END')
|
||||
@ -17,10 +15,7 @@ class CapTestCase(cases.BaseServerTestCase):
|
||||
def testReqUnavailable(self):
|
||||
self.addClient(1)
|
||||
self.sendLine(1, 'CAP LS 302')
|
||||
m = self.getMessage(1, filter_pred=lambda m:m.command != 'NOTICE')
|
||||
self.assertMessageEqual(m, command='CAP')
|
||||
self.assertMessageEqual(m, command='CAP', target='*',
|
||||
subcommand='LS')
|
||||
self.getCapLs(1)
|
||||
self.sendLine(1, 'USER foo foo foo :foo')
|
||||
self.sendLine(1, 'NICK foo')
|
||||
self.sendLine(1, 'CAP REQ :invalid-capability')
|
||||
@ -36,10 +31,7 @@ class CapTestCase(cases.BaseServerTestCase):
|
||||
required by the spec <http://ircv3.net/specs/core/capability-negotiation-3.1.html#the-cap-nak-subcommand>"""
|
||||
self.addClient(1)
|
||||
self.sendLine(1, 'CAP LS 302')
|
||||
m = self.getMessage(1, filter_pred=lambda m:m.command != 'NOTICE')
|
||||
self.assertMessageEqual(m, command='CAP')
|
||||
self.assertMessageEqual(m, command='CAP', target='*',
|
||||
subcommand='LS')
|
||||
self.getCapLs(1)
|
||||
# Five should be enough to check there is no reordering, even
|
||||
# alphabetical
|
||||
self.sendLine(1, 'CAP REQ :foo bar baz qux quux')
|
||||
|
Reference in New Issue
Block a user