From 5a2c367e893922f432252c7a65d85df148eda49b Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 5 Jan 2022 21:44:15 +0100 Subject: [PATCH] policies/reputation: fix test Signed-off-by: Jens Langhammer --- authentik/policies/reputation/models.py | 7 ++++--- authentik/policies/reputation/tests.py | 1 - authentik/stages/authenticator_sms/tests.py | 5 +---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/authentik/policies/reputation/models.py b/authentik/policies/reputation/models.py index e64fa518b..37c745165 100644 --- a/authentik/policies/reputation/models.py +++ b/authentik/policies/reputation/models.py @@ -36,14 +36,15 @@ class ReputationPolicy(Policy): def passes(self, request: PolicyRequest) -> PolicyResult: remote_ip = get_client_ip(request.http_request) - passing = False query = Q() if self.check_ip: query |= Q(ip=remote_ip) if self.check_username: query |= Q(identifier=request.user.username) - score = Reputation.objects.filter(query).annotate(total_score=Sum("score")).total_score - passing += passing or score <= self.threshold + score = ( + Reputation.objects.filter(query).aggregate(total_score=Sum("score"))["total_score"] or 0 + ) + passing = score <= self.threshold LOGGER.debug( "Score for user", username=request.user.username, diff --git a/authentik/policies/reputation/tests.py b/authentik/policies/reputation/tests.py index b83384262..985e0586d 100644 --- a/authentik/policies/reputation/tests.py +++ b/authentik/policies/reputation/tests.py @@ -4,7 +4,6 @@ from django.core.cache import cache from django.test import RequestFactory, TestCase from authentik.core.models import User -from authentik.lib.utils.http import DEFAULT_IP from authentik.policies.reputation.models import CACHE_KEY_PREFIX, Reputation, ReputationPolicy from authentik.policies.reputation.tasks import save_reputation from authentik.policies.types import PolicyRequest diff --git a/authentik/stages/authenticator_sms/tests.py b/authentik/stages/authenticator_sms/tests.py index a7c56d422..5b7fe17ad 100644 --- a/authentik/stages/authenticator_sms/tests.py +++ b/authentik/stages/authenticator_sms/tests.py @@ -48,10 +48,7 @@ class AuthenticatorSMSStageTests(APITestCase): "title": "", }, "pending_user": "foo", - "pending_user_avatar": ( - "https://secure.gravatar.com/avatar/d41d8cd98f00" - "b204e9800998ecf8427e?s=158&r=g" - ), + "pending_user_avatar": "/static/dist/assets/images/user_default.png", "phone_number_required": True, "type": ChallengeTypes.NATIVE.value, },