This repository has been 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
Refactor OIDC tests to better mimic an actual OIDC provider #13910
Merged
clokep
merged 9 commits into
matrix-org:develop
from
sandhose:quenting/refactor-oidc-tests
Oct 25, 2022
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
db30e73
Refactor OIDC tests to better mimic an actual OIDC provider
sandhose 99a3929
Newsfile.
sandhose 10a423c
Merge remote-tracking branch 'upstream/develop' into quenting/refacto…
sandhose a973c91
Rename `FakeOidcProvider` -> `FakeOidcServer` + docstrings
sandhose 731c683
Comment about the token endpoint not checking auth in the FakeOidcServer
sandhose cf16d0a
Fix tests with newer authlib versions
sandhose 7c981b4
Suggestion from code review
sandhose 3233581
Apply suggestions from code review
sandhose f225a91
Rename provider -> fake_server
sandhose 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 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 @@ | ||
Refactor OIDC tests to better mimic an actual OIDC provider. |
This file contains 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 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 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 |
---|---|---|
|
@@ -12,24 +12,20 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import json | ||
from unittest import mock | ||
|
||
import twisted.web.client | ||
from twisted.internet import defer | ||
from twisted.internet.protocol import Protocol | ||
from twisted.python.failure import Failure | ||
from twisted.test.proto_helpers import MemoryReactor | ||
|
||
from synapse.api.room_versions import RoomVersions | ||
from synapse.events import EventBase | ||
from synapse.rest import admin | ||
from synapse.rest.client import login, room | ||
from synapse.server import HomeServer | ||
from synapse.types import JsonDict | ||
from synapse.util import Clock | ||
|
||
from tests.test_utils import event_injection | ||
from tests.test_utils import FakeResponse, event_injection | ||
from tests.unittest import FederatingHomeserverTestCase | ||
|
||
|
||
|
@@ -98,8 +94,8 @@ def test_get_room_state(self): | |
|
||
# mock up the response, and have the agent return it | ||
self._mock_agent.request.side_effect = lambda *args, **kwargs: defer.succeed( | ||
_mock_response( | ||
{ | ||
FakeResponse.json( | ||
payload={ | ||
"pdus": [ | ||
create_event_dict, | ||
member_event_dict, | ||
|
@@ -208,8 +204,8 @@ def _get_pdu_once(self) -> EventBase: | |
|
||
# mock up the response, and have the agent return it | ||
self._mock_agent.request.side_effect = lambda *args, **kwargs: defer.succeed( | ||
_mock_response( | ||
{ | ||
FakeResponse.json( | ||
payload={ | ||
"origin": "yet.another.server", | ||
"origin_server_ts": 900, | ||
"pdus": [ | ||
|
@@ -269,8 +265,8 @@ def test_backfill_invalid_signature_records_failed_pull_attempts( | |
|
||
# We expect an outbound request to /backfill, so stub that out | ||
self._mock_agent.request.side_effect = lambda *args, **kwargs: defer.succeed( | ||
_mock_response( | ||
{ | ||
FakeResponse.json( | ||
payload={ | ||
"origin": "yet.another.server", | ||
"origin_server_ts": 900, | ||
# Mimic the other server returning our new `pulled_event` | ||
|
@@ -305,21 +301,3 @@ def test_backfill_invalid_signature_records_failed_pull_attempts( | |
# This is 2 because it failed once from `self.OTHER_SERVER_NAME` and the | ||
# other from "yet.another.server" | ||
self.assertEqual(backfill_num_attempts, 2) | ||
|
||
|
||
def _mock_response(resp: JsonDict): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we already had a |
||
body = json.dumps(resp).encode("utf-8") | ||
|
||
def deliver_body(p: Protocol): | ||
p.dataReceived(body) | ||
p.connectionLost(Failure(twisted.web.client.ResponseDone())) | ||
|
||
response = mock.Mock( | ||
code=200, | ||
phrase=b"OK", | ||
headers=twisted.web.client.Headers({"content-Type": ["application/json"]}), | ||
length=len(body), | ||
deliverBody=deliver_body, | ||
) | ||
mock.seal(response) | ||
return response |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that was a LIE.