kopia lustrzana https://dev.funkwhale.audio/funkwhale/funkwhale
Linting
rodzic
d63f8f2e33
commit
4811f35eb5
|
@ -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
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from rest_framework import authentication, exceptions
|
||||
from rest_framework import exceptions
|
||||
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
Ładowanie…
Reference in New Issue