test_server.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 The Matrix.org Foundation C.I.C.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from twisted.internet import defer
  16. from synapse.config.ratelimiting import FederationRateLimitConfig
  17. from synapse.federation.transport import server
  18. from synapse.util.ratelimitutils import FederationRateLimiter
  19. from tests import unittest
  20. from tests.unittest import override_config
  21. class RoomDirectoryFederationTests(unittest.HomeserverTestCase):
  22. def prepare(self, reactor, clock, homeserver):
  23. class Authenticator(object):
  24. def authenticate_request(self, request, content):
  25. return defer.succeed("otherserver.nottld")
  26. ratelimiter = FederationRateLimiter(clock, FederationRateLimitConfig())
  27. server.register_servlets(
  28. homeserver, self.resource, Authenticator(), ratelimiter
  29. )
  30. @override_config({"allow_public_rooms_over_federation": False})
  31. def test_blocked_public_room_list_over_federation(self):
  32. request, channel = self.make_request(
  33. "GET", "/_matrix/federation/v1/publicRooms"
  34. )
  35. self.render(request)
  36. self.assertEquals(403, channel.code)
  37. @override_config({"allow_public_rooms_over_federation": True})
  38. def test_open_public_room_list_over_federation(self):
  39. request, channel = self.make_request(
  40. "GET", "/_matrix/federation/v1/publicRooms"
  41. )
  42. self.render(request)
  43. self.assertEquals(200, channel.code)