test_identity.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. request, channel = self.make_request(
  35. b"POST", "/createRoom", b"{}", access_token=tok
  36. )
  37. self.render(request)
  38. self.assertEquals(channel.result["code"], b"200", 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. request, channel = self.make_request(
  48. b"POST", request_url, request_data, access_token=tok
  49. )
  50. self.render(request)
  51. self.assertEquals(channel.result["code"], b"403", channel.result)