test_federation.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 The Matrix.org Foundation C.I.C.
  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. from synapse.api.constants import EventTypes
  16. from synapse.api.errors import AuthError, Codes
  17. from synapse.rest import admin
  18. from synapse.rest.client.v1 import login, room
  19. from tests import unittest
  20. class FederationTestCase(unittest.HomeserverTestCase):
  21. servlets = [
  22. admin.register_servlets,
  23. login.register_servlets,
  24. room.register_servlets,
  25. ]
  26. def make_homeserver(self, reactor, clock):
  27. hs = self.setup_test_homeserver(http_client=None)
  28. self.handler = hs.get_handlers().federation_handler
  29. self.store = hs.get_datastore()
  30. return hs
  31. def test_exchange_revoked_invite(self):
  32. user_id = self.register_user("kermit", "test")
  33. tok = self.login("kermit", "test")
  34. room_id = self.helper.create_room_as(room_creator=user_id, tok=tok)
  35. # Send a 3PID invite event with an empty body so it's considered as a revoked one.
  36. invite_token = "sometoken"
  37. self.helper.send_state(
  38. room_id=room_id,
  39. event_type=EventTypes.ThirdPartyInvite,
  40. state_key=invite_token,
  41. body={},
  42. tok=tok,
  43. )
  44. d = self.handler.on_exchange_third_party_invite_request(
  45. room_id=room_id,
  46. event_dict={
  47. "type": EventTypes.Member,
  48. "room_id": room_id,
  49. "sender": user_id,
  50. "state_key": "@someone:example.org",
  51. "content": {
  52. "membership": "invite",
  53. "third_party_invite": {
  54. "display_name": "alice",
  55. "signed": {
  56. "mxid": "@alice:localhost",
  57. "token": invite_token,
  58. "signatures": {
  59. "magic.forest": {
  60. "ed25519:3": "fQpGIW1Snz+pwLZu6sTy2aHy/DYWWTspTJRPyNp0PKkymfIsNffysMl6ObMMFdIJhk6g6pwlIqZ54rxo8SLmAg"
  61. }
  62. },
  63. },
  64. },
  65. },
  66. },
  67. )
  68. failure = self.get_failure(d, AuthError).value
  69. self.assertEqual(failure.code, 403, failure)
  70. self.assertEqual(failure.errcode, Codes.FORBIDDEN, failure)
  71. self.assertEqual(failure.msg, "You are not invited to this room.")