test_identity.py 1.9 KB

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