mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-06 14:34:59 -04:00
Performance improvements and refactor of Ratelimiter (#7595)
While working on https://github.com/matrix-org/synapse/issues/5665 I found myself digging into the `Ratelimiter` class and seeing that it was both: * Rather undocumented, and * causing a *lot* of config checks This PR attempts to refactor and comment the `Ratelimiter` class, as well as encourage config file accesses to only be done at instantiation. Best to be reviewed commit-by-commit.
This commit is contained in:
parent
c389bfb6ea
commit
f4e6495b5d
19 changed files with 325 additions and 233 deletions
|
@ -29,7 +29,6 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
]
|
||||
|
||||
def make_homeserver(self, reactor, clock):
|
||||
|
||||
self.hs = self.setup_test_homeserver()
|
||||
self.hs.config.enable_registration = True
|
||||
self.hs.config.registrations_require_3pid = []
|
||||
|
@ -38,10 +37,20 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
return self.hs
|
||||
|
||||
@override_config(
|
||||
{
|
||||
"rc_login": {
|
||||
"address": {"per_second": 0.17, "burst_count": 5},
|
||||
# Prevent the account login ratelimiter from raising first
|
||||
#
|
||||
# This is normally covered by the default test homeserver config
|
||||
# which sets these values to 10000, but as we're overriding the entire
|
||||
# rc_login dict here, we need to set this manually as well
|
||||
"account": {"per_second": 10000, "burst_count": 10000},
|
||||
}
|
||||
}
|
||||
)
|
||||
def test_POST_ratelimiting_per_address(self):
|
||||
self.hs.config.rc_login_address.burst_count = 5
|
||||
self.hs.config.rc_login_address.per_second = 0.17
|
||||
|
||||
# Create different users so we're sure not to be bothered by the per-user
|
||||
# ratelimiter.
|
||||
for i in range(0, 6):
|
||||
|
@ -80,10 +89,20 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||
|
||||
@override_config(
|
||||
{
|
||||
"rc_login": {
|
||||
"account": {"per_second": 0.17, "burst_count": 5},
|
||||
# Prevent the address login ratelimiter from raising first
|
||||
#
|
||||
# This is normally covered by the default test homeserver config
|
||||
# which sets these values to 10000, but as we're overriding the entire
|
||||
# rc_login dict here, we need to set this manually as well
|
||||
"address": {"per_second": 10000, "burst_count": 10000},
|
||||
}
|
||||
}
|
||||
)
|
||||
def test_POST_ratelimiting_per_account(self):
|
||||
self.hs.config.rc_login_account.burst_count = 5
|
||||
self.hs.config.rc_login_account.per_second = 0.17
|
||||
|
||||
self.register_user("kermit", "monkey")
|
||||
|
||||
for i in range(0, 6):
|
||||
|
@ -119,10 +138,20 @@ class LoginRestServletTestCase(unittest.HomeserverTestCase):
|
|||
|
||||
self.assertEquals(channel.result["code"], b"200", channel.result)
|
||||
|
||||
@override_config(
|
||||
{
|
||||
"rc_login": {
|
||||
# Prevent the address login ratelimiter from raising first
|
||||
#
|
||||
# This is normally covered by the default test homeserver config
|
||||
# which sets these values to 10000, but as we're overriding the entire
|
||||
# rc_login dict here, we need to set this manually as well
|
||||
"address": {"per_second": 10000, "burst_count": 10000},
|
||||
"failed_attempts": {"per_second": 0.17, "burst_count": 5},
|
||||
}
|
||||
}
|
||||
)
|
||||
def test_POST_ratelimiting_per_account_failed_attempts(self):
|
||||
self.hs.config.rc_login_failed_attempts.burst_count = 5
|
||||
self.hs.config.rc_login_failed_attempts.per_second = 0.17
|
||||
|
||||
self.register_user("kermit", "monkey")
|
||||
|
||||
for i in range(0, 6):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue