mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 12:26:02 -04:00
Ratelimit 3PID /requestToken API (#9238)
This commit is contained in:
parent
54a6afeee3
commit
4b73488e81
11 changed files with 159 additions and 14 deletions
|
@ -47,6 +47,7 @@ class FakeChannel:
|
|||
site = attr.ib(type=Site)
|
||||
_reactor = attr.ib()
|
||||
result = attr.ib(type=dict, default=attr.Factory(dict))
|
||||
_ip = attr.ib(type=str, default="127.0.0.1")
|
||||
_producer = None
|
||||
|
||||
@property
|
||||
|
@ -120,7 +121,7 @@ class FakeChannel:
|
|||
def getPeer(self):
|
||||
# We give an address so that getClientIP returns a non null entry,
|
||||
# causing us to record the MAU
|
||||
return address.IPv4Address("TCP", "127.0.0.1", 3423)
|
||||
return address.IPv4Address("TCP", self._ip, 3423)
|
||||
|
||||
def getHost(self):
|
||||
return None
|
||||
|
@ -196,6 +197,7 @@ def make_request(
|
|||
custom_headers: Optional[
|
||||
Iterable[Tuple[Union[bytes, str], Union[bytes, str]]]
|
||||
] = None,
|
||||
client_ip: str = "127.0.0.1",
|
||||
) -> FakeChannel:
|
||||
"""
|
||||
Make a web request using the given method, path and content, and render it
|
||||
|
@ -223,6 +225,9 @@ def make_request(
|
|||
will pump the reactor until the the renderer tells the channel the request
|
||||
is finished.
|
||||
|
||||
client_ip: The IP to use as the requesting IP. Useful for testing
|
||||
ratelimiting.
|
||||
|
||||
Returns:
|
||||
channel
|
||||
"""
|
||||
|
@ -250,7 +255,7 @@ def make_request(
|
|||
if isinstance(content, str):
|
||||
content = content.encode("utf8")
|
||||
|
||||
channel = FakeChannel(site, reactor)
|
||||
channel = FakeChannel(site, reactor, ip=client_ip)
|
||||
|
||||
req = request(channel)
|
||||
req.content = BytesIO(content)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue