test_well_known.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright 2018 New Vector
  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.web.resource import Resource
  15. from synapse.rest.well_known import well_known_resource
  16. from tests import unittest
  17. class WellKnownTests(unittest.HomeserverTestCase):
  18. def create_test_resource(self):
  19. # replace the JsonResource with a Resource wrapping the WellKnownResource
  20. res = Resource()
  21. res.putChild(b".well-known", well_known_resource(self.hs))
  22. return res
  23. @unittest.override_config(
  24. {
  25. "public_baseurl": "https://tesths",
  26. "default_identity_server": "https://testis",
  27. }
  28. )
  29. def test_client_well_known(self):
  30. channel = self.make_request(
  31. "GET", "/.well-known/matrix/client", shorthand=False
  32. )
  33. self.assertEqual(channel.code, 200)
  34. self.assertEqual(
  35. channel.json_body,
  36. {
  37. "m.homeserver": {"base_url": "https://tesths/"},
  38. "m.identity_server": {"base_url": "https://testis"},
  39. },
  40. )
  41. @unittest.override_config(
  42. {
  43. "public_baseurl": None,
  44. }
  45. )
  46. def test_client_well_known_no_public_baseurl(self):
  47. channel = self.make_request(
  48. "GET", "/.well-known/matrix/client", shorthand=False
  49. )
  50. self.assertEqual(channel.code, 404)
  51. @unittest.override_config({"serve_server_wellknown": True})
  52. def test_server_well_known(self):
  53. channel = self.make_request(
  54. "GET", "/.well-known/matrix/server", shorthand=False
  55. )
  56. self.assertEqual(channel.code, 200)
  57. self.assertEqual(
  58. channel.json_body,
  59. {"m.server": "test:443"},
  60. )
  61. def test_server_well_known_disabled(self):
  62. channel = self.make_request(
  63. "GET", "/.well-known/matrix/server", shorthand=False
  64. )
  65. self.assertEqual(channel.code, 404)