1
0

test_server.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 synapse.api.constants import EduTypes
  15. from tests import unittest
  16. from tests.unittest import DEBUG, override_config
  17. class RoomDirectoryFederationTests(unittest.FederatingHomeserverTestCase):
  18. @override_config({"allow_public_rooms_over_federation": False})
  19. def test_blocked_public_room_list_over_federation(self) -> None:
  20. """Test that unauthenticated requests to the public rooms directory 403 when
  21. allow_public_rooms_over_federation is False.
  22. """
  23. channel = self.make_signed_federation_request(
  24. "GET",
  25. "/_matrix/federation/v1/publicRooms",
  26. )
  27. self.assertEqual(403, channel.code)
  28. @override_config({"allow_public_rooms_over_federation": True})
  29. def test_open_public_room_list_over_federation(self) -> None:
  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_signed_federation_request(
  34. "GET",
  35. "/_matrix/federation/v1/publicRooms",
  36. )
  37. self.assertEqual(200, channel.code)
  38. @DEBUG
  39. def test_edu_debugging_doesnt_explode(self) -> None:
  40. """Sanity check incoming federation succeeds with `synapse.debug_8631` enabled.
  41. Remove this when we strip out issue_8631_logger.
  42. """
  43. channel = self.make_signed_federation_request(
  44. "PUT",
  45. "/_matrix/federation/v1/send/txn_id_1234/",
  46. content={
  47. "edus": [
  48. {"edu_type": EduTypes.DEVICE_LIST_UPDATE, "content": {"foo": "bar"}}
  49. ],
  50. "pdus": [],
  51. },
  52. )
  53. self.assertEqual(200, channel.code)