mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 05:49:16 +02:00
Support oauth token in URL
This commit is contained in:
parent
e3b0efb25f
commit
c8fcf1b0d9
4 changed files with 62 additions and 19 deletions
36
api/tests/test_auth.py
Normal file
36
api/tests/test_auth.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
from django.urls import reverse
|
||||
from rest_framework_jwt.settings import api_settings
|
||||
|
||||
jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
|
||||
jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
|
||||
|
||||
|
||||
def test_can_authenticate_using_jwt_token_param_in_url(factories, preferences, client):
|
||||
user = factories["users.User"]()
|
||||
preferences["common__api_authentication_required"] = True
|
||||
url = reverse("api:v1:tracks-list")
|
||||
response = client.get(url)
|
||||
|
||||
assert response.status_code == 401
|
||||
|
||||
payload = jwt_payload_handler(user)
|
||||
token = jwt_encode_handler(payload)
|
||||
response = client.get(url, data={"jwt": token})
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
def test_can_authenticate_using_oauth_token_param_in_url(
|
||||
factories, preferences, client, mocker
|
||||
):
|
||||
mocker.patch(
|
||||
"funkwhale_api.users.oauth.permissions.should_allow", return_value=True
|
||||
)
|
||||
token = factories["users.AccessToken"]()
|
||||
preferences["common__api_authentication_required"] = True
|
||||
url = reverse("api:v1:tracks-list")
|
||||
response = client.get(url)
|
||||
|
||||
assert response.status_code == 401
|
||||
|
||||
response = client.get(url, data={"token": token.token})
|
||||
assert response.status_code == 200
|
Loading…
Add table
Add a link
Reference in a new issue