1
0

test_well_known.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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) -> Resource:
  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) -> None:
  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) -> None:
  47. channel = self.make_request(
  48. "GET", "/.well-known/matrix/client", shorthand=False
  49. )
  50. self.assertEqual(channel.code, 404)
  51. @unittest.override_config(
  52. {
  53. "public_baseurl": "https://tesths",
  54. "default_identity_server": "https://testis",
  55. "extra_well_known_client_content": {"custom": False},
  56. }
  57. )
  58. def test_client_well_known_custom(self) -> None:
  59. channel = self.make_request(
  60. "GET", "/.well-known/matrix/client", shorthand=False
  61. )
  62. self.assertEqual(channel.code, 200)
  63. self.assertEqual(
  64. channel.json_body,
  65. {
  66. "m.homeserver": {"base_url": "https://tesths/"},
  67. "m.identity_server": {"base_url": "https://testis"},
  68. "custom": False,
  69. },
  70. )
  71. @unittest.override_config({"serve_server_wellknown": True})
  72. def test_server_well_known(self) -> None:
  73. channel = self.make_request(
  74. "GET", "/.well-known/matrix/server", shorthand=False
  75. )
  76. self.assertEqual(channel.code, 200)
  77. self.assertEqual(
  78. channel.json_body,
  79. {"m.server": "test:443"},
  80. )
  81. def test_server_well_known_disabled(self) -> None:
  82. channel = self.make_request(
  83. "GET", "/.well-known/matrix/server", shorthand=False
  84. )
  85. self.assertEqual(channel.code, 404)