mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 01:09:22 +01:00
utils.reverseModes: don't reverse prefix/list modes that were never set
Charybdis/TS6 doesn't check this IRCd-side, so we don't want people to abuse this by say, overriding -b *!*@* in a relay channel and having the PyLink client set +b *!*@* in response,
This commit is contained in:
parent
9a139212dd
commit
9cd176b846
@ -108,13 +108,13 @@ class TestUtils(unittest.TestCase):
|
||||
def testReverseModes(self):
|
||||
test = lambda x, y: self.assertEqual(utils.reverseModes(self.irc, '#test', x), y)
|
||||
# Strings.
|
||||
self._reverseModes("+mi-lk test", "-mi+lk test")
|
||||
self._reverseModes("mi-k test", "-mi+k test")
|
||||
self._reverseModes("+mk-t test", "-mk+t test")
|
||||
self._reverseModes("ml-n 111", "-ml+n")
|
||||
# Lists.
|
||||
self._reverseModes([('+m', None), ('+r', None), ('+l', '3'), ('-o', 'person')],
|
||||
{('-m', None), ('-r', None), ('-l', None), ('+o', 'person')})
|
||||
self._reverseModes([('+m', None), ('+r', None), ('+l', '3')],
|
||||
{('-m', None), ('-r', None), ('-l', None)})
|
||||
# Sets.
|
||||
self._reverseModes({('s', None), ('+o', 'whoever')}, {('-s', None), ('-o', 'whoever')})
|
||||
self._reverseModes({('s', None)}, {('-s', None)})
|
||||
# Combining modes with an initial + and those without
|
||||
self._reverseModes({('s', None), ('+R', None)}, {('-s', None), ('-R', None)})
|
||||
|
||||
@ -139,5 +139,12 @@ class TestUtils(unittest.TestCase):
|
||||
self._reverseModes('+o 9PYAAAAAA', '+')
|
||||
self._reverseModes('+vvvvM test abcde atat abcd', '-vvvvM test abcde atat abcd')
|
||||
|
||||
# Ignore unsetting prefixmodes/list modes that were never set.
|
||||
self._reverseModes([('-v', '10XAAAAAA')], set())
|
||||
self._reverseModes('-ob 10XAAAAAA derp!*@*', '+')
|
||||
utils.applyModes(self.irc, '#test', [('+o', 'GLolol'), ('+b', '*!user@badisp.tk')])
|
||||
self._reverseModes('-voo GLolol GLolol 10XAAAAAA', '+o GLolol')
|
||||
self._reverseModes('-bb *!*@* *!user@badisp.tk', '+b *!user@badisp.tk')
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
6
utils.py
6
utils.py
@ -401,6 +401,12 @@ def reverseModes(irc, target, modes, oldobj=None):
|
||||
log.debug("(%s) reverseModes: skipping reversing '%s %s' with %s since we're "
|
||||
"setting a mode that's already set.", irc.name, char, arg, mpair)
|
||||
continue
|
||||
elif char[0] == '-' and (mchar, arg) not in oldmodes and mchar in possible_modes['*A']:
|
||||
# We're unsetting a prefixmode that was never set - don't set it in response!
|
||||
# Charybdis lacks verification for this server-side.
|
||||
log.debug("(%s) reverseModes: skipping reversing '%s %s' with %s since it "
|
||||
"wasn't previously set.", irc.name, char, arg, mpair)
|
||||
continue
|
||||
newmodes.append(mpair)
|
||||
|
||||
log.debug('(%s) reverseModes: new modes: %s', irc.name, newmodes)
|
||||
|
Loading…
Reference in New Issue
Block a user