diff --git a/api/funkwhale_api/federation/authentication.py b/api/funkwhale_api/federation/authentication.py index 6f0fd32959d977c6e52f74f4c808eb8bc0ab0511..adfb8a18161dc91f11b0957530054ed85c33b460 100644 --- a/api/funkwhale_api/federation/authentication.py +++ b/api/funkwhale_api/federation/authentication.py @@ -2,7 +2,7 @@ import cryptography import logging from django.contrib.auth.models import AnonymousUser -from rest_framework import authentication, exceptions +from rest_framework import authentication, exceptions as rest_exceptions from funkwhale_api.moderation import models as moderation_models from . import actors, exceptions, keys, signing, utils @@ -20,12 +20,12 @@ class SignatureAuthentication(authentication.BaseAuthentication): except KeyError: return except ValueError as e: - raise exceptions.AuthenticationFailed(str(e)) + raise rest_exceptions.AuthenticationFailed(str(e)) try: actor_url = key_id.split("#")[0] except (TypeError, IndexError, AttributeError): - raise exceptions.AuthenticationFailed("Invalid key id") + raise rest_exceptions.AuthenticationFailed("Invalid key id") policies = ( moderation_models.InstancePolicy.objects.active() @@ -41,15 +41,15 @@ class SignatureAuthentication(authentication.BaseAuthentication): logger.info( "Discarding HTTP request from blocked actor/domain %s", actor_url ) - raise exceptions.AuthenticationFailed(str(e)) + raise rest_exceptions.AuthenticationFailed(str(e)) if not actor.public_key: - raise exceptions.AuthenticationFailed("No public key found") + raise rest_exceptions.AuthenticationFailed("No public key found") try: signing.verify_django(request, actor.public_key.encode("utf-8")) except cryptography.exceptions.InvalidSignature: - raise exceptions.AuthenticationFailed("Invalid signature") + raise rest_exceptions.AuthenticationFailed("Invalid signature") return actor diff --git a/api/funkwhale_api/federation/exceptions.py b/api/funkwhale_api/federation/exceptions.py index 303a0c4b3f9f157e5c62f72b6ca6bce7d96ae9dd..eb2bd2161537b1498c8905de45476bf705b70e1c 100644 --- a/api/funkwhale_api/federation/exceptions.py +++ b/api/funkwhale_api/federation/exceptions.py @@ -1,4 +1,3 @@ -from rest_framework import authentication, exceptions from rest_framework import exceptions diff --git a/api/funkwhale_api/federation/utils.py b/api/funkwhale_api/federation/utils.py index f29608a21e74266d67f39bedc28c6c8ee1bc6a9b..e49a4dd63c4f8140c8f8e52ed13cb095585927c7 100644 --- a/api/funkwhale_api/federation/utils.py +++ b/api/funkwhale_api/federation/utils.py @@ -1,7 +1,6 @@ import unicodedata import re from django.conf import settings -from django.db.models import Q from funkwhale_api.common import session from funkwhale_api.moderation import models as moderation_models @@ -64,7 +63,7 @@ def slugify_username(username): def retrieve_ap_object( fid, actor=None, serializer_class=None, queryset=None, apply_instance_policies=True ): - from . import activity, serializers + from . import activity policies = moderation_models.InstancePolicy.objects.active().filter(block_all=True) if apply_instance_policies and policies.matching_url(fid): diff --git a/api/tests/federation/test_utils.py b/api/tests/federation/test_utils.py index 761f44d37a84177fdb317fd2a6972ab3e27e075d..a8d02cdb9cc30ae7468a01bbc5b787ce1da73b2e 100644 --- a/api/tests/federation/test_utils.py +++ b/api/tests/federation/test_utils.py @@ -79,7 +79,7 @@ def test_retrieve_ap_object_honor_instance_policy_different_url_and_id( block_all=True, for_domain=True ).target_domain fid = "https://ok/test" - m = r_mock.get(fid, json={"id": "http://{}/test".format(domain.name)}) + r_mock.get(fid, json={"id": "http://{}/test".format(domain.name)}) with pytest.raises(exceptions.BlockedActorOrDomain): utils.retrieve_ap_object(fid)