test_server.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright 2020 The Matrix.org Foundation C.I.C.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from tests import unittest
  15. from tests.unittest import override_config
  16. class RoomDirectoryFederationTests(unittest.FederatingHomeserverTestCase):
  17. @override_config({"allow_public_rooms_over_federation": False})
  18. def test_blocked_public_room_list_over_federation(self):
  19. """Test that unauthenticated requests to the public rooms directory 403 when
  20. allow_public_rooms_over_federation is False.
  21. """
  22. channel = self.make_request(
  23. "GET",
  24. "/_matrix/federation/v1/publicRooms",
  25. federation_auth_origin=b"example.com",
  26. )
  27. self.assertEquals(403, channel.code)
  28. @override_config({"allow_public_rooms_over_federation": True})
  29. def test_open_public_room_list_over_federation(self):
  30. """Test that unauthenticated requests to the public rooms directory 200 when
  31. allow_public_rooms_over_federation is True.
  32. """
  33. channel = self.make_request(
  34. "GET",
  35. "/_matrix/federation/v1/publicRooms",
  36. federation_auth_origin=b"example.com",
  37. )
  38. self.assertEquals(200, channel.code)