diff --git a/tests/handlers/test_oauth_delegation.py b/tests/handlers/test_oauth_delegation.py
index 503277cdff..a72ecfdc97 100644
--- a/tests/handlers/test_oauth_delegation.py
+++ b/tests/handlers/test_oauth_delegation.py
@@ -14,7 +14,7 @@
from http import HTTPStatus
from typing import Any, Dict, Union
-from unittest.mock import ANY, Mock
+from unittest.mock import ANY, AsyncMock, Mock
from urllib.parse import parse_qs
from signedjson.key import (
@@ -39,7 +39,7 @@ from synapse.server import HomeServer
from synapse.types import JsonDict
from synapse.util import Clock
-from tests.test_utils import FakeResponse, get_awaitable_result, simple_async_mock
+from tests.test_utils import FakeResponse, get_awaitable_result
from tests.unittest import HomeserverTestCase, skip_unless
from tests.utils import mock_getRawHeaders
@@ -148,7 +148,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
def test_inactive_token(self) -> None:
"""The handler should return a 403 where the token is inactive."""
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse.json(
code=200,
payload={"active": False},
@@ -167,7 +167,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
def test_active_no_scope(self) -> None:
"""The handler should return a 403 where no scope is given."""
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse.json(
code=200,
payload={"active": True},
@@ -186,7 +186,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
def test_active_user_no_subject(self) -> None:
"""The handler should return a 500 when no subject is present."""
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse.json(
code=200,
payload={"active": True, "scope": " ".join([MATRIX_USER_SCOPE])},
@@ -205,7 +205,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
def test_active_no_user_scope(self) -> None:
"""The handler should return a 500 when no subject is present."""
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse.json(
code=200,
payload={
@@ -228,7 +228,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
def test_active_admin_not_user(self) -> None:
"""The handler should raise when the scope has admin right but not user."""
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse.json(
code=200,
payload={
@@ -252,7 +252,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
def test_active_admin(self) -> None:
"""The handler should return a requester with admin rights."""
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse.json(
code=200,
payload={
@@ -282,7 +282,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
def test_active_admin_highest_privilege(self) -> None:
"""The handler should resolve to the most permissive scope."""
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse.json(
code=200,
payload={
@@ -314,7 +314,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
def test_active_user(self) -> None:
"""The handler should return a requester with normal user rights."""
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse.json(
code=200,
payload={
@@ -344,7 +344,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
def test_active_user_with_device(self) -> None:
"""The handler should return a requester with normal user rights and a device ID."""
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse.json(
code=200,
payload={
@@ -374,7 +374,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
def test_multiple_devices(self) -> None:
"""The handler should raise an error if multiple devices are found in the scope."""
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse.json(
code=200,
payload={
@@ -399,7 +399,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
def test_active_guest_not_allowed(self) -> None:
"""The handler should return an insufficient scope error."""
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse.json(
code=200,
payload={
@@ -429,7 +429,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
def test_active_guest_allowed(self) -> None:
"""The handler should return a requester with guest user rights and a device ID."""
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse.json(
code=200,
payload={
@@ -465,19 +465,19 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
request.requestHeaders.getRawHeaders = mock_getRawHeaders()
# The introspection endpoint is returning an error.
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse(code=500, body=b"Internal Server Error")
)
error = self.get_failure(self.auth.get_user_by_req(request), SynapseError)
self.assertEqual(error.value.code, 503)
# The introspection endpoint request fails.
- self.http_client.request = simple_async_mock(raises=Exception())
+ self.http_client.request = AsyncMock(side_effect=Exception())
error = self.get_failure(self.auth.get_user_by_req(request), SynapseError)
self.assertEqual(error.value.code, 503)
# The introspection endpoint does not return a JSON object.
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse.json(
code=200, payload=["this is an array", "not an object"]
)
@@ -486,7 +486,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
self.assertEqual(error.value.code, 503)
# The introspection endpoint does not return valid JSON.
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse(code=200, body=b"this is not valid JSON")
)
error = self.get_failure(self.auth.get_user_by_req(request), SynapseError)
@@ -512,7 +512,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
def test_cross_signing(self) -> None:
"""Try uploading device keys with OAuth delegation enabled."""
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse.json(
code=200,
payload={
@@ -666,7 +666,7 @@ class MSC3861OAuthDelegation(HomeserverTestCase):
def test_admin_token(self) -> None:
"""The handler should return a requester with admin rights when admin_token is used."""
- self.http_client.request = simple_async_mock(
+ self.http_client.request = AsyncMock(
return_value=FakeResponse.json(code=200, payload={"active": False}),
)
|