ircdb.checkIgnored: return False for messages from servers

These do not pass the `ircutils.isUserHostmask` check despite being a valid msg.prefix. We should probably return gracefully here instead of forcing plugins to deal with such a case themselves.

Closes GH-1548
This commit is contained in:
James Lu 2023-08-12 14:50:33 -07:00 committed by Val Lorentz
parent a2e55ca1f6
commit 3e5291f6d2
2 changed files with 23 additions and 1 deletions

View File

@ -468,7 +468,12 @@ class IrcChannel(object):
return True return True
if world.testing: if world.testing:
return False return False
assert ircutils.isUserHostmask(hostmask), 'got %s' % hostmask if not ircutils.isUserHostmask(hostmask):
# Treat messages from a server (e.g. snomasks) as not ignored, as
# the ignores system doesn't understand them
if '.' not in hostmask:
raise ValueError("Expected full prefix, got %r" % hostmask)
return False
if self.checkBan(hostmask): if self.checkBan(hostmask):
return True return True
if self.ignores.match(hostmask): if self.ignores.match(hostmask):

View File

@ -350,6 +350,23 @@ class IrcChannelTestCase(IrcdbTestCase):
c.removeBan(banmask) c.removeBan(banmask)
self.assertFalse(c.checkIgnored(prefix)) self.assertFalse(c.checkIgnored(prefix))
# Only full n!u@h is accepted here
self.assertRaises(ValueError, c.checkIgnored, 'foo')
def testIgnoredServerNames(self):
c = ircdb.IrcChannel()
# Server names are not handled by the ignores system, so this is false
self.assertFalse(c.checkIgnored('irc.example.com'))
# But we should treat full prefixes that match nick!user@host normally,
# even if they include "." like a server name
prefix = 'irc.example.com!bar@baz'
banmask = ircutils.banmask(prefix)
self.assertFalse(c.checkIgnored(prefix))
c.addIgnore(banmask)
self.assertTrue(c.checkIgnored(prefix))
c.removeIgnore(banmask)
self.assertFalse(c.checkIgnored(prefix))
class IrcNetworkTestCase(IrcdbTestCase): class IrcNetworkTestCase(IrcdbTestCase):
def testDefaults(self): def testDefaults(self):
n = ircdb.IrcNetwork() n = ircdb.IrcNetwork()