Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4721 from matrix-org/erikj/msc_1866
Browse files Browse the repository at this point in the history
MSC 1866 - Use M_UNSUPPORTED_ROOM_VERSION for invite API
  • Loading branch information
erikjohnston authored Feb 25, 2019
2 parents 16c7afa + 71304bf commit b1a90da
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog.d/4721.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Return correct error code when inviting a remote user to a room whose homeserver does not support the room version.
18 changes: 17 additions & 1 deletion synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
)
from synapse.api.errors import (
CodeMessageException,
Codes,
FederationDeniedError,
HttpResponseException,
SynapseError,
Expand Down Expand Up @@ -792,10 +793,25 @@ def _do_send_invite(self, destination, pdu, room_version):
defer.returnValue(content)
except HttpResponseException as e:
if e.code in [400, 404]:
err = e.to_synapse_error()

# If we receive an error response that isn't a generic error, we
# assume that the remote understands the v2 invite API and this
# is a legitimate error.
if err.errcode != Codes.UNKNOWN:
raise err

# Otherwise, we assume that the remote server doesn't understand
# the v2 invite API.

if room_version in (RoomVersions.V1, RoomVersions.V2):
pass # We'll fall through
else:
raise Exception("Remote server is too old")
raise SynapseError(
400,
"User's homeserver does not support this room version",
Codes.UNSUPPORTED_ROOM_VERSION,
)
elif e.code == 403:
raise e.to_synapse_error()
else:
Expand Down
10 changes: 9 additions & 1 deletion synapse/federation/federation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
from twisted.internet.abstract import isIPAddress
from twisted.python import failure

from synapse.api.constants import EventTypes, Membership
from synapse.api.constants import KNOWN_ROOM_VERSIONS, EventTypes, Membership
from synapse.api.errors import (
AuthError,
Codes,
FederationError,
IncompatibleRoomVersionError,
NotFoundError,
Expand Down Expand Up @@ -386,6 +387,13 @@ def on_make_join_request(self, origin, room_id, user_id, supported_versions):

@defer.inlineCallbacks
def on_invite_request(self, origin, content, room_version):
if room_version not in KNOWN_ROOM_VERSIONS:
raise SynapseError(
400,
"Homeserver does not support this room version",
Codes.UNSUPPORTED_ROOM_VERSION,
)

format_ver = room_version_to_event_format(room_version)

pdu = event_from_pdu_json(content, format_ver)
Expand Down

0 comments on commit b1a90da

Please sign in to comment.