policies/reputation: fix test
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
3b05c9cb1a
commit
5a2c367e89
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
|
|
Reference in New Issue