mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 06:49:24 +01:00
Unix: Channel-specific list of files for @fortune.
Also forbid file names starting with a dash, because arguments to the fortune argument could be used for DoSing.
This commit is contained in:
parent
49ff291f61
commit
b42437c711
@ -52,6 +52,20 @@ def configure(advanced):
|
||||
default=True):
|
||||
conf.supybot.commands.disabled().add('Unix.progstats')
|
||||
|
||||
class NonOptionString(registry.String):
|
||||
errormsg = _('Value must be a string not starting with a dash (-), not %r.')
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.__parent = super(NonOptionString, self)
|
||||
self.__parent.__init__(*args, **kwargs)
|
||||
def setValue(self, v):
|
||||
if v.startswith('-'):
|
||||
self.error(v)
|
||||
else:
|
||||
self.__parent.setValue(v)
|
||||
|
||||
class SpaceSeparatedListOfNonOptionStrings(registry.SpaceSeparatedListOfStrings):
|
||||
Value = NonOptionString
|
||||
|
||||
|
||||
Unix = conf.registerPlugin('Unix')
|
||||
conf.registerGroup(Unix, 'fortune')
|
||||
@ -70,8 +84,8 @@ conf.registerChannelValue(Unix.fortune, 'offensive',
|
||||
registry.Boolean(False, _("""Determines whether fortune will retrieve
|
||||
offensive fortunes along with the normal fortunes. This sends the -a
|
||||
option to the fortune program.""")))
|
||||
conf.registerGlobalValue(Unix.fortune, 'files',
|
||||
registry.SpaceSeparatedListOfStrings([], _("""Determines what specific file
|
||||
conf.registerChannelValue(Unix.fortune, 'files',
|
||||
SpaceSeparatedListOfNonOptionStrings([], _("""Determines what specific file
|
||||
(if any) will be used with the fortune command; if none is given, the
|
||||
system-wide default will be used. Do note that this fortune file must be
|
||||
placed with the rest of your system's fortune files.""")))
|
||||
|
@ -53,6 +53,15 @@ else:
|
||||
skipUnlessPing6 = skipIf(utils.findBinaryInPath('ping6') is None,
|
||||
'ping6 not available.')
|
||||
|
||||
class UnixConfigTestCase(ChannelPluginTestCase):
|
||||
plugins = ('Unix',)
|
||||
def testFortuneFiles(self):
|
||||
self.assertNotError('config channel plugins.Unix.fortune.files '
|
||||
'foo bar')
|
||||
self.assertRegexp('config channel plugins.Unix.fortune.files '
|
||||
'"-foo bar"',
|
||||
'Error:.*dash.*not \'-foo\'')
|
||||
self.assertNotError('config channel plugins.Unix.fortune.files ""')
|
||||
|
||||
|
||||
if os.name == 'posix':
|
||||
|
Loading…
Reference in New Issue
Block a user