Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix up FederationTestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Dec 2, 2020
1 parent 5716697 commit 9e581db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion synapse/federation/transport/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ def register_servlets(hs, resource, authenticator, ratelimiter, servlet_groups=N
Args:
hs (synapse.server.HomeServer): homeserver
resource (TransportLayerServer): resource class to register to
resource (JsonResource): resource class to register to
authenticator (Authenticator): authenticator to use
ratelimiter (util.ratelimitutils.FederationRateLimiter): ratelimiter to use
servlet_groups (list[str], optional): List of servlet groups to register.
Expand Down
25 changes: 19 additions & 6 deletions tests/unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,13 +717,29 @@ class FederatingHomeserverTestCase(HomeserverTestCase):
A federating homeserver that authenticates incoming requests as `other.example.com`.
"""

def prepare(self, reactor, clock, homeserver):
def create_resource_dict(self) -> Dict[str, Resource]:
d = super().create_resource_dict()
d["/_matrix/federation"] = TestTransportLayerServer(self.hs)
return d


class TestTransportLayerServer(JsonResource):
"""A test implementation of TransportLayerServer
authenticates incoming requests as `other.example.com`.
"""

def __init__(self, hs):
super().__init__(hs)

class Authenticator:
def authenticate_request(self, request, content):
return succeed("other.example.com")

authenticator = Authenticator()

ratelimiter = FederationRateLimiter(
clock,
hs.get_clock(),
FederationRateLimitConfig(
window_size=1,
sleep_limit=1,
Expand All @@ -732,11 +748,8 @@ def authenticate_request(self, request, content):
concurrent_requests=1000,
),
)
federation_server.register_servlets(
homeserver, self.resource, Authenticator(), ratelimiter
)

return super().prepare(reactor, clock, homeserver)
federation_server.register_servlets(hs, self, authenticator, ratelimiter)


def override_config(extra_config):
Expand Down

0 comments on commit 9e581db

Please sign in to comment.