test_identity.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright 2019 New Vector Ltd
  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 http import HTTPStatus
  15. from twisted.test.proto_helpers import MemoryReactor
  16. import synapse.rest.admin
  17. from synapse.rest.client import login, room
  18. from synapse.server import HomeServer
  19. from synapse.util import Clock
  20. from tests import unittest
  21. class IdentityTestCase(unittest.HomeserverTestCase):
  22. servlets = [
  23. synapse.rest.admin.register_servlets_for_client_rest_resource,
  24. room.register_servlets,
  25. login.register_servlets,
  26. ]
  27. def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
  28. config = self.default_config()
  29. config["enable_3pid_lookup"] = False
  30. self.hs = self.setup_test_homeserver(config=config)
  31. return self.hs
  32. def test_3pid_lookup_disabled(self) -> None:
  33. self.hs.config.registration.enable_3pid_lookup = False
  34. self.register_user("kermit", "monkey")
  35. tok = self.login("kermit", "monkey")
  36. channel = self.make_request(b"POST", "/createRoom", b"{}", access_token=tok)
  37. self.assertEqual(channel.code, HTTPStatus.OK, channel.result)
  38. room_id = channel.json_body["room_id"]
  39. request_data = {
  40. "id_server": "testis",
  41. "medium": "email",
  42. "address": "test@example.com",
  43. "id_access_token": tok,
  44. }
  45. request_url = ("/rooms/%s/invite" % (room_id)).encode("ascii")
  46. channel = self.make_request(
  47. b"POST", request_url, request_data, access_token=tok
  48. )
  49. self.assertEqual(channel.code, HTTPStatus.FORBIDDEN, channel.result)