test_rendezvous.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright 2022 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 twisted.test.proto_helpers import MemoryReactor
  15. from synapse.rest.client import rendezvous
  16. from synapse.server import HomeServer
  17. from synapse.util import Clock
  18. from tests import unittest
  19. from tests.unittest import override_config
  20. endpoint = "/_matrix/client/unstable/org.matrix.msc3886/rendezvous"
  21. class RendezvousServletTestCase(unittest.HomeserverTestCase):
  22. servlets = [
  23. rendezvous.register_servlets,
  24. ]
  25. def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
  26. self.hs = self.setup_test_homeserver()
  27. return self.hs
  28. def test_disabled(self) -> None:
  29. channel = self.make_request("POST", endpoint, {}, access_token=None)
  30. self.assertEqual(channel.code, 404)
  31. @override_config({"experimental_features": {"msc3886_endpoint": "/asd"}})
  32. def test_redirect(self) -> None:
  33. channel = self.make_request("POST", endpoint, {}, access_token=None)
  34. self.assertEqual(channel.code, 307)
  35. self.assertEqual(channel.headers.getRawHeaders("Location"), ["/asd"])