test_identity.py 2.1 KB

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