policies/reputation: fix race condition in tests
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
4de927ba5b
commit
f10bd432b3
|
@ -36,14 +36,17 @@ class ReputationPolicy(Policy):
|
|||
passing = True
|
||||
if self.check_ip:
|
||||
score = cache.get_or_set(CACHE_KEY_IP_PREFIX + remote_ip, 0)
|
||||
LOGGER.debug("Score for IP", ip=remote_ip, score=score)
|
||||
passing = passing and score <= self.threshold
|
||||
LOGGER.debug("Score for IP", ip=remote_ip, score=score, passing=passing)
|
||||
if self.check_username:
|
||||
score = cache.get_or_set(CACHE_KEY_USER_PREFIX + request.user.username, 0)
|
||||
LOGGER.debug(
|
||||
"Score for Username", username=request.user.username, score=score
|
||||
)
|
||||
passing = passing and score <= self.threshold
|
||||
LOGGER.debug(
|
||||
"Score for Username",
|
||||
username=request.user.username,
|
||||
score=score,
|
||||
passing=passing,
|
||||
)
|
||||
return PolicyResult(passing)
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -4,6 +4,7 @@ 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_IP_PREFIX,
|
||||
CACHE_KEY_USER_PREFIX,
|
||||
|
@ -24,6 +25,7 @@ class TestReputationPolicy(TestCase):
|
|||
self.test_ip = "127.0.0.1"
|
||||
self.test_username = "test"
|
||||
cache.delete(CACHE_KEY_IP_PREFIX + self.test_ip)
|
||||
cache.delete(CACHE_KEY_IP_PREFIX + DEFAULT_IP)
|
||||
cache.delete(CACHE_KEY_USER_PREFIX + self.test_username)
|
||||
# We need a user for the one-to-one in userreputation
|
||||
self.user = User.objects.create(username=self.test_username)
|
||||
|
|
|
@ -38,7 +38,7 @@ You can of course use a custom signing certificate, and adjust durations.
|
|||
|
||||
## NextCloud
|
||||
|
||||
In NextCloud, ensure that the `SSO & SAML Authentication` extension is installed. Navigate to `Settings`, then `SSO & SAML Authentication`.
|
||||
In NextCloud, ensure that the `SSO & SAML Authentication` app is installed. Navigate to `Settings`, then `SSO & SAML Authentication`.
|
||||
|
||||
Set the following values:
|
||||
|
||||
|
|
Reference in a new issue