This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Implementation of HTTP 307 response for MSC3886 POST endpoint #14018
Merged
reivilibre
merged 30 commits into
matrix-org:develop
from
hughns:hughns/msc3886-redirect
Oct 18, 2022
+257
−45
Merged
Changes from 13 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
73dace0
Implementation of HTTP 307 endpoint for MSC3886
hughns 4294327
Linting
hughns 923bcbd
Merge remote-tracking branch 'upstream/develop' into hughns/msc3886-r…
hughns f330b0f
Changelog
hughns 81ff46d
Lint fixes
hughns b5eb427
Fix docs
hughns e190693
Merge branch 'develop' into hughns/msc3886-redirect
hughns 21e9d50
Merge branch 'matrix-org:develop' into hughns/msc3886-redirect
hughns 4656642
FIx passing of experimental_cors_msc3886 around site
hughns f0218a6
Lint fix
hughns c838182
Merge branch 'matrix-org:develop' into hughns/msc3886-redirect
hughns 8a81b3c
Actually test for correct response code
hughns 7e9b07d
Merge branch 'develop' into hughns/msc3886-redirect
hughns d8f927e
Merge branch 'matrix-org:develop' into hughns/msc3886-redirect
hughns 2ea6295
Expand reference to MSC3886
hughns 68887e7
Remove unnecessary usage of getattr
hughns e3fcdea
Document param
hughns 261d098
Document function args
hughns 208b598
Make handling of "" endpoint explicit
hughns 81fb879
Fix and improve docs
hughns 61e417e
Linting
hughns 441c299
Merge branch 'matrix-org:develop' into hughns/msc3886-redirect
hughns a6ddd03
Make typing of set_cors_headers explicit
hughns 08aaafc
Fixup more references to SynapseRequest
hughns fc67315
Satisfy linter
hughns 50ce7e3
Add experimental_cors_msc3886 to FakeSite
hughns 05a516b
Linting
hughns ae5fd0d
Include experimental_cors_msc3886 in mock site
hughns 26f2804
Update synapse/config/server.py
hughns ba87974
Merge branch 'develop' of github.com:matrix-org/synapse into hughns/m…
anoadragon453 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Support for redirecting to an implementation of [MSC3886](https://github.com/matrix-org/matrix-spec-proposals/pull/3886). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # Copyright 2022 The Matrix.org Foundation C.I.C. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import logging | ||
| from http.client import TEMPORARY_REDIRECT | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from synapse.http.server import HttpServer, respond_with_redirect | ||
| from synapse.http.servlet import RestServlet | ||
| from synapse.http.site import SynapseRequest | ||
| from synapse.rest.client._base import client_patterns | ||
|
|
||
| if TYPE_CHECKING: | ||
| from synapse.server import HomeServer | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class RendezvousServlet(RestServlet): | ||
| """ | ||
| Get a token that can be used with `m.login.token` to log in a second device. | ||
| This implementation is a stub that redirects to another configured endpoint. | ||
|
|
||
| Request: | ||
|
|
||
| POST /rendezvous HTTP/1.1 | ||
| Content-Type: ... | ||
|
|
||
| ... | ||
|
|
||
| Response: | ||
|
|
||
| HTTP/1.1 307 | ||
| Location: <configured endpoint> | ||
| """ | ||
|
|
||
| PATTERNS = client_patterns( | ||
| "/org.matrix.msc3886/rendezvous$", releases=[], v1=False, unstable=True | ||
| ) | ||
|
|
||
| def __init__(self, hs: "HomeServer"): | ||
| super().__init__() | ||
| redirection_target: str = hs.config.experimental.msc3886_endpoint or "" | ||
| self.endpoint = redirection_target.encode("utf-8") | ||
|
|
||
| async def on_POST(self, request: SynapseRequest) -> None: | ||
|
hughns marked this conversation as resolved.
|
||
| respond_with_redirect( | ||
| request, self.endpoint, statusCode=TEMPORARY_REDIRECT, cors=True | ||
| ) | ||
|
hughns marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def register_servlets(hs: "HomeServer", http_server: HttpServer) -> None: | ||
| if hs.config.experimental.msc3886_endpoint is not None: | ||
| RendezvousServlet(hs).register(http_server) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # Copyright 2022 The Matrix.org Foundation C.I.C. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from twisted.test.proto_helpers import MemoryReactor | ||
|
|
||
| from synapse.rest.client import rendezvous | ||
| from synapse.server import HomeServer | ||
| from synapse.util import Clock | ||
|
|
||
| from tests import unittest | ||
| from tests.unittest import override_config | ||
|
|
||
| endpoint = "/_matrix/client/unstable/org.matrix.msc3886/rendezvous" | ||
|
|
||
|
|
||
| class RendezvousServletTestCase(unittest.HomeserverTestCase): | ||
|
|
||
| servlets = [ | ||
| rendezvous.register_servlets, | ||
| ] | ||
|
|
||
| def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer: | ||
| self.hs = self.setup_test_homeserver() | ||
| return self.hs | ||
|
|
||
| def test_disabled(self) -> None: | ||
| channel = self.make_request("POST", endpoint, {}, access_token=None) | ||
| self.assertEqual(channel.code, 400) | ||
|
|
||
| @override_config({"experimental_features": {"msc3886_endpoint": "/asd"}}) | ||
| def test_redirect(self) -> None: | ||
| channel = self.make_request("POST", endpoint, {}, access_token=None) | ||
| self.assertEqual(channel.code, 307) | ||
| self.assertEqual(channel.headers.getRawHeaders("Location"), ["/asd"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.