Beispiel #1
0
 def testBanmask(self):
     for msg in msgs:
         if ircutils.isUserHostmask(msg.prefix):
             banmask = ircutils.banmask(msg.prefix)
             self.failUnless(
                 ircutils.hostmaskPatternEqual(banmask, msg.prefix), "%r didn't match %r" % (msg.prefix, banmask)
             )
     self.assertEqual(ircutils.banmask("foobar!user@host"), "*!*@host")
     self.assertEqual(ircutils.banmask("[email protected]"), "*!*@host.tld")
     self.assertEqual(ircutils.banmask("[email protected]"), "*!*@*.host.tld")
     self.assertEqual(ircutils.banmask("foo!bar@2001::"), "*!*@2001::*")
Beispiel #2
0
 def testBanmask(self):
     for msg in msgs:
         if ircutils.isUserHostmask(msg.prefix):
             banmask = ircutils.banmask(msg.prefix)
             self.failUnless(
                 ircutils.hostmaskPatternEqual(banmask, msg.prefix),
                 '%r didn\'t match %r' % (msg.prefix, banmask))
     self.assertEqual(ircutils.banmask('foobar!user@host'), '*!*@host')
     self.assertEqual(ircutils.banmask('[email protected]'),
                      '*!*@host.tld')
     self.assertEqual(ircutils.banmask('[email protected]'),
                      '*!*@*.host.tld')
     self.assertEqual(ircutils.banmask('foo!bar@2001::'), '*!*@2001::*')
Beispiel #3
0
 def testBanmask(self):
     for msg in msgs:
         if ircutils.isUserHostmask(msg.prefix):
             banmask = ircutils.banmask(msg.prefix)
             self.failUnless(ircutils.hostmaskPatternEqual(banmask,
                                                           msg.prefix),
                             '%r didn\'t match %r' % (msg.prefix, banmask))
     self.assertEqual(ircutils.banmask('foobar!user@host'), '*!*@host')
     self.assertEqual(ircutils.banmask('[email protected]'),
                      '*!*@host.tld')
     self.assertEqual(ircutils.banmask('[email protected]'),
                      '*!*@*.host.tld')
     self.assertEqual(ircutils.banmask('foo!bar@2001::'), '*!*@2001::*')
Beispiel #4
0
 def doPrivmsg(self, irc, msg):
     assert self is irc.callbacks[0], \
            'Owner isn\'t first callback: %r' % irc.callbacks
     if ircmsgs.isCtcp(msg):
         return
     s = callbacks.addressed(irc.nick, msg)
     if s:
         ignored = ircdb.checkIgnored(msg.prefix)
         if ignored:
             self.log.info('Ignoring command from %s.', msg.prefix)
             return
         maximum = conf.supybot.abuse.flood.command.maximum()
         self.commands.enqueue(msg)
         if conf.supybot.abuse.flood.command() \
            and self.commands.len(msg) > maximum \
            and not ircdb.checkCapability(msg.prefix, 'trusted'):
             punishment = conf.supybot.abuse.flood.command.punishment()
             banmask = ircutils.banmask(msg.prefix)
             self.log.info('Ignoring %s for %s seconds due to an apparent '
                           'command flood.', banmask, punishment)
             ircdb.ignores.add(banmask, time.time() + punishment)
             irc.reply('You\'ve given me %s commands within the last '
                       'minute; I\'m now ignoring you for %s.' %
                       (maximum,
                        utils.timeElapsed(punishment, seconds=False)))
             return
         try:
             tokens = callbacks.tokenize(s, channel=msg.args[0])
             self.Proxy(irc, msg, tokens)
         except SyntaxError, e:
             irc.queueMsg(callbacks.error(msg, str(e)))
Beispiel #5
0
 def doPrivmsg(self, irc, msg):
     assert self is irc.callbacks[0], \
            'Owner isn\'t first callback: %r' % irc.callbacks
     if ircmsgs.isCtcp(msg):
         return
     s = callbacks.addressed(irc.nick, msg)
     if s:
         ignored = ircdb.checkIgnored(msg.prefix)
         if ignored:
             self.log.info('Ignoring command from %s.', msg.prefix)
             return
         maximum = conf.supybot.abuse.flood.command.maximum()
         self.commands.enqueue(msg)
         if conf.supybot.abuse.flood.command() \
            and self.commands.len(msg) > maximum \
            and not ircdb.checkCapability(msg.prefix, 'trusted'):
             punishment = conf.supybot.abuse.flood.command.punishment()
             banmask = ircutils.banmask(msg.prefix)
             self.log.info(
                 'Ignoring %s for %s seconds due to an apparent '
                 'command flood.', banmask, punishment)
             ircdb.ignores.add(banmask, time.time() + punishment)
             irc.reply('You\'ve given me %s commands within the last '
                       '%i seconds; I\'m now ignoring you for %s.' %
                       (maximum, conf.supybot.abuse.flood.interval(),
                        utils.timeElapsed(punishment, seconds=False)))
             return
         try:
             tokens = callbacks.tokenize(s, channel=msg.args[0])
             self.Proxy(irc, msg, tokens)
         except SyntaxError as e:
             irc.queueMsg(callbacks.error(msg, str(e)))
Beispiel #6
0
 def testIterAndNumUsers(self):
     self.assertEqual(self.users.numUsers(), 0)
     u = self.users.newUser()
     hostmask = '[email protected]'
     banmask = ircutils.banmask(hostmask)
     u.addHostmask(banmask)
     u.name = 'foo'
     self.users.setUser(u)
     self.assertEqual(self.users.numUsers(), 1)
     u = self.users.newUser()
     hostmask = 'biff!fladksfj@blakjdsf'
     banmask = ircutils.banmask(hostmask)
     u.addHostmask(banmask)
     u.name = 'biff'
     self.users.setUser(u)
     self.assertEqual(self.users.numUsers(), 2)
     self.users.delUser(2)
     self.assertEqual(self.users.numUsers(), 1)
     self.users.delUser(1)
     self.assertEqual(self.users.numUsers(), 0)
Beispiel #7
0
 def testIterAndNumUsers(self):
     self.assertEqual(self.users.numUsers(), 0)
     u = self.users.newUser()
     hostmask = '[email protected]'
     banmask = ircutils.banmask(hostmask)
     u.addHostmask(banmask)
     u.name = 'foo'
     self.users.setUser(u)
     self.assertEqual(self.users.numUsers(), 1)
     u = self.users.newUser()
     hostmask = 'biff!fladksfj@blakjdsf'
     banmask = ircutils.banmask(hostmask)
     u.addHostmask(banmask)
     u.name = 'biff'
     self.users.setUser(u)
     self.assertEqual(self.users.numUsers(), 2)
     self.users.delUser(2)
     self.assertEqual(self.users.numUsers(), 1)
     self.users.delUser(1)
     self.assertEqual(self.users.numUsers(), 0)
Beispiel #8
0
 def testHostmaskPatternEqual(self):
     for msg in msgs:
         if msg.prefix and ircutils.isUserHostmask(msg.prefix):
             s = msg.prefix
             self.failUnless(ircutils.hostmaskPatternEqual(s, s), "%r did not match itself." % s)
             banmask = ircutils.banmask(s)
             self.failUnless(ircutils.hostmaskPatternEqual(banmask, s), "%r did not match %r" % (s, banmask))
     s = "[email protected]"
     self.failUnless(ircutils.hostmaskPatternEqual(s, s))
     s = "jamessan|[email protected]." "abr-ubr1.sbo-abr.ma.cable.rcn.com"
     self.failUnless(ircutils.hostmaskPatternEqual(s, s))
Beispiel #9
0
 def testIgnored(self):
     prefix = 'foo!bar@baz'
     banmask = ircutils.banmask(prefix)
     c = ircdb.IrcChannel()
     self.assertFalse(c.checkIgnored(prefix))
     c.addIgnore(banmask)
     self.assertTrue(c.checkIgnored(prefix))
     c.removeIgnore(banmask)
     self.assertFalse(c.checkIgnored(prefix))
     c.addBan(banmask)
     self.assertTrue(c.checkIgnored(prefix))
     c.removeBan(banmask)
     self.assertFalse(c.checkIgnored(prefix))
Beispiel #10
0
 def testIgnored(self):
     prefix = 'foo!bar@baz'
     banmask = ircutils.banmask(prefix)
     c = ircdb.IrcChannel()
     self.failIf(c.checkIgnored(prefix))
     c.addIgnore(banmask)
     self.failUnless(c.checkIgnored(prefix))
     c.removeIgnore(banmask)
     self.failIf(c.checkIgnored(prefix))
     c.addBan(banmask)
     self.failUnless(c.checkIgnored(prefix))
     c.removeBan(banmask)
     self.failIf(c.checkIgnored(prefix))
Beispiel #11
0
 def testIgnored(self):
     prefix = 'foo!bar@baz'
     banmask = ircutils.banmask(prefix)
     c = ircdb.IrcChannel()
     self.failIf(c.checkIgnored(prefix))
     c.addIgnore(banmask)
     self.failUnless(c.checkIgnored(prefix))
     c.removeIgnore(banmask)
     self.failIf(c.checkIgnored(prefix))
     c.addBan(banmask)
     self.failUnless(c.checkIgnored(prefix))
     c.removeBan(banmask)
     self.failIf(c.checkIgnored(prefix))
Beispiel #12
0
 def testHostmaskPatternEqual(self):
     for msg in msgs:
         if msg.prefix and ircutils.isUserHostmask(msg.prefix):
             s = msg.prefix
             self.failUnless(ircutils.hostmaskPatternEqual(s, s),
                             '%r did not match itself.' % s)
             banmask = ircutils.banmask(s)
             self.failUnless(ircutils.hostmaskPatternEqual(banmask, s),
                             '%r did not match %r' % (s, banmask))
     s = '[email protected]'
     self.failUnless(ircutils.hostmaskPatternEqual(s, s))
     s = 'jamessan|[email protected].' \
         'abr-ubr1.sbo-abr.ma.cable.rcn.com'
     self.failUnless(ircutils.hostmaskPatternEqual(s, s))
Beispiel #13
0
 def testGetSetDelUser(self):
     self.assertRaises(KeyError, self.users.getUser, 'foo')
     self.assertRaises(KeyError, self.users.getUser,
                       '[email protected]')
     u = self.users.newUser()
     hostmask = '[email protected]'
     banmask = ircutils.banmask(hostmask)
     u.addHostmask(banmask)
     u.addHostmask(hostmask)
     u.name = 'foo'
     self.users.setUser(u)
     self.assertEqual(self.users.getUser('foo'), u)
     self.assertEqual(self.users.getUser('FOO'), u)
     self.assertEqual(self.users.getUser(hostmask), u)
     self.assertEqual(self.users.getUser(banmask), u)
     # The UsersDictionary shouldn't allow users to be added whose hostmasks
     # match another user's already in the database.
     u2 = self.users.newUser()
     u2.addHostmask('*[email protected]?m')
     self.assertRaises(ValueError, self.users.setUser, u2)
Beispiel #14
0
 def testGetSetDelUser(self):
     self.assertRaises(KeyError, self.users.getUser, 'foo')
     self.assertRaises(KeyError,
                       self.users.getUser, '[email protected]')
     u = self.users.newUser()
     hostmask = '[email protected]'
     banmask = ircutils.banmask(hostmask)
     u.addHostmask(banmask)
     u.addHostmask(hostmask)
     u.name = 'foo'
     self.users.setUser(u)
     self.assertEqual(self.users.getUser('foo'), u)
     self.assertEqual(self.users.getUser('FOO'), u)
     self.assertEqual(self.users.getUser(hostmask), u)
     self.assertEqual(self.users.getUser(banmask), u)
     # The UsersDictionary shouldn't allow users to be added whose hostmasks
     # match another user's already in the database.
     u2 = self.users.newUser()
     u2.addHostmask('*[email protected]?m')
     self.assertRaises(ValueError, self.users.setUser, u2)