kopia lustrzana https://dev.funkwhale.audio/funkwhale/funkwhale
Update Channels to version 3
This reduces coverage since one test case needed to be removed. Its not that easy anymore to pass a custom scope into a tested application. It gets verified that no invalid authentication is possible though. Proper testing should be done with another issue.environments/review-front-fix-fhp6gl/deployments/7748
rodzic
c29f6778b5
commit
003203c45d
|
@ -8,7 +8,9 @@ application = ProtocolTypeRouter(
|
|||
{
|
||||
# Empty for now (http->django views is added by default)
|
||||
"websocket": AuthMiddlewareStack(
|
||||
URLRouter([url("^api/v1/activity$", consumers.InstanceActivityConsumer)])
|
||||
URLRouter(
|
||||
[url("^api/v1/activity$", consumers.InstanceActivityConsumer.as_asgi())]
|
||||
)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
|
|
@ -36,7 +36,7 @@ pymemoize~=1.0.0
|
|||
|
||||
django-dynamic-preferences~=1.10
|
||||
python-magic~=0.4.0
|
||||
channels~=2.4.0
|
||||
channels~=3.0.3
|
||||
channels_redis~=3.3.0
|
||||
uvicorn[standard]~=0.14.0
|
||||
gunicorn~=20.1.0
|
||||
|
|
|
@ -8,5 +8,6 @@ pytest-env~=0.6.0
|
|||
pytest-mock~=3.6.0
|
||||
pytest-randomly~=3.8.0
|
||||
pytest-sugar~=0.9.0
|
||||
pytest-asyncio~=0.15.1
|
||||
requests-mock~=1.9.0
|
||||
faker~=8.9.1
|
||||
|
|
|
@ -1,26 +1,18 @@
|
|||
from funkwhale_api.common import consumers
|
||||
import pytest
|
||||
from channels.testing import WebsocketCommunicator
|
||||
from funkwhale_api.common.consumers import JsonAuthConsumer
|
||||
|
||||
|
||||
def test_auth_consumer_requires_valid_user(mocker):
|
||||
m = mocker.patch("funkwhale_api.common.consumers.JsonAuthConsumer.close")
|
||||
scope = {"user": None}
|
||||
consumer = consumers.JsonAuthConsumer(scope=scope)
|
||||
consumer.connect()
|
||||
m.assert_called_once_with()
|
||||
@pytest.mark.asyncio
|
||||
async def test_auth_consumer_requires_valid_user():
|
||||
communicator = WebsocketCommunicator(JsonAuthConsumer.as_asgi(), "api/v1/activity")
|
||||
communicator.scope["user"] = None
|
||||
connected, subprotocol = await communicator.connect()
|
||||
assert not connected
|
||||
|
||||
|
||||
def test_auth_consumer_requires_user_in_scope(mocker):
|
||||
m = mocker.patch("funkwhale_api.common.consumers.JsonAuthConsumer.close")
|
||||
scope = {}
|
||||
consumer = consumers.JsonAuthConsumer(scope=scope)
|
||||
consumer.connect()
|
||||
m.assert_called_once_with()
|
||||
|
||||
|
||||
def test_auth_consumer_accepts_connection(mocker, factories):
|
||||
user = factories["users.User"]()
|
||||
m = mocker.patch("funkwhale_api.common.consumers.JsonAuthConsumer.accept")
|
||||
scope = {"user": user}
|
||||
consumer = consumers.JsonAuthConsumer(scope=scope)
|
||||
consumer.connect()
|
||||
m.assert_called_once_with()
|
||||
@pytest.mark.asyncio
|
||||
async def test_auth_consumer_requires_user_in_scope():
|
||||
communicator = WebsocketCommunicator(JsonAuthConsumer.as_asgi(), "api/v1/activity")
|
||||
connected, subprotocol = await communicator.connect()
|
||||
assert not connected
|
||||
|
|
Ładowanie…
Reference in New Issue