def test_throttle(self): ips = ('94.100.176.153', '45.56.148.77', '5.196.1.129') kwargs = {'limit': 5, 'timeout': 15 * 60} throttle = Throttle(**kwargs) for ip in ips: # Throttle should not be engaged by default self.assertFalse(throttle.check(ip)) # Pretend to fail a bunch of events for x in range(50): obj = throttle.update(ip) self.assertFalse(obj) # Next ones should be blocked self.assertTrue(throttle.check(ip)) for x in range(throttle.cache_size * 2): obj = throttle.update(ip) self.assertFalse(obj) # Should still be blocked self.assertTrue(throttle.check(ip)) # Number of values should be limited by cache size self.assertEqual(throttle.cache_size, len(throttle.get(ip))) cache = throttle.get() # Make sure there are entries for each IP self.assertEqual(len(ips), len(cache.keys())) # There should only be (cache_size * num_ips) total in the Throttle cache self.assertEqual(sum([len(cache[x]) for x in cache.keys()]), throttle.cache_size * len(ips))
def test_throttle(self): ips = ('94.100.176.153', '45.56.148.77', '5.196.1.129') kwargs = { 'limit': 5, 'timeout': 15 * 60 } throttle = Throttle(**kwargs) for ip in ips: # Throttle should not be engaged by default self.assertFalse(throttle.check(ip)) # Pretend to fail a bunch of events for x in range(50): obj = throttle.update(ip) self.assertFalse(obj) # Next ones should be blocked self.assertTrue(throttle.check(ip)) for x in range(throttle.cache_size * 2): obj = throttle.update(ip) self.assertFalse(obj) # Should still be blocked self.assertTrue(throttle.check(ip)) # Number of values should be limited by cache size self.assertEqual(throttle.cache_size, len(throttle.get(ip))) cache = throttle.get() # Make sure there are entries for each IP self.assertEqual(len(ips), len(cache.keys())) # There should only be (cache_size * num_ips) total in the Throttle cache self.assertEqual(sum([len(cache[x]) for x in cache.keys()]), throttle.cache_size * len(ips))
from evennia.server.sessionhandler import SESSIONS from evennia.utils import create, logger, utils, gametime from evennia.commands.cmdhandler import CMD_LOGINSTART COMMAND_DEFAULT_CLASS = utils.class_from_module(settings.COMMAND_DEFAULT_CLASS) # limit symbol import for API __all__ = ("CmdUnconnectedConnect", "CmdUnconnectedCreate", "CmdUnconnectedQuit", "CmdUnconnectedLook", "CmdUnconnectedHelp") MULTISESSION_MODE = settings.MULTISESSION_MODE CONNECTION_SCREEN_MODULE = settings.CONNECTION_SCREEN_MODULE # Create throttles for too many connections, account-creations and login attempts CONNECTION_THROTTLE = Throttle(limit=5, timeout=1 * 60) CREATION_THROTTLE = Throttle(limit=2, timeout=10 * 60) LOGIN_THROTTLE = Throttle(limit=5, timeout=5 * 60) def create_guest_account(session): """ Creates a guest account/character for this session, if one is available. Args: session (Session): the session which will use the guest account/character. Returns: GUEST_ENABLED (boolean), account (Account): the boolean is whether guest accounts are enabled at all. the Account which was created from an available guest name.