test_identity.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 New Vector Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import json
  16. import synapse.rest.admin
  17. from synapse.rest.client.v1 import login, room
  18. from tests import unittest
  19. class IdentityTestCase(unittest.HomeserverTestCase):
  20. servlets = [
  21. synapse.rest.admin.register_servlets_for_client_rest_resource,
  22. room.register_servlets,
  23. login.register_servlets,
  24. ]
  25. def make_homeserver(self, reactor, clock):
  26. config = self.default_config()
  27. config["enable_3pid_lookup"] = False
  28. self.hs = self.setup_test_homeserver(config=config)
  29. return self.hs
  30. def test_3pid_lookup_disabled(self):
  31. self.hs.config.enable_3pid_lookup = False
  32. self.register_user("kermit", "monkey")
  33. tok = self.login("kermit", "monkey")
  34. channel = self.make_request(b"POST", "/createRoom", b"{}", access_token=tok)
  35. self.assertEquals(channel.result["code"], b"200", channel.result)
  36. room_id = channel.json_body["room_id"]
  37. params = {
  38. "id_server": "testis",
  39. "medium": "email",
  40. "address": "test@example.com",
  41. }
  42. request_data = json.dumps(params)
  43. request_url = ("/rooms/%s/invite" % (room_id)).encode("ascii")
  44. channel = self.make_request(
  45. b"POST", request_url, request_data, access_token=tok
  46. )
  47. self.assertEquals(channel.result["code"], b"403", channel.result)