merge-requests/552/head
Eliot Berriot 2019-01-10 11:10:39 +01:00
rodzic d63f8f2e33
commit 4811f35eb5
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: DD6965E2476E5C27
4 zmienionych plików z 8 dodań i 10 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -1,4 +1,3 @@
from rest_framework import authentication, exceptions
from rest_framework import exceptions

Wyświetl plik

@ -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):

Wyświetl plik

@ -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)