fix failing unittests
This commit is contained in:
parent
fb82d56307
commit
a4707ddc54
|
@ -1,6 +1,7 @@
|
|||
"""passbook core policy engine"""
|
||||
from logging import getLogger
|
||||
|
||||
from ipware import get_client_ip
|
||||
from celery import group
|
||||
from django.http import HttpRequest
|
||||
|
||||
|
@ -9,15 +10,6 @@ from passbook.core.models import Policy, User
|
|||
|
||||
LOGGER = getLogger(__name__)
|
||||
|
||||
|
||||
def get_remote_ip(request: HttpRequest) -> str:
|
||||
"""Return the remote's IP"""
|
||||
if not request:
|
||||
return '0.0.0.0' # nosec
|
||||
if request.META.get('HTTP_X_FORWARDED_FOR'):
|
||||
return request.META.get('HTTP_X_FORWARDED_FOR')
|
||||
return request.META.get('REMOTE_ADDR')
|
||||
|
||||
@CELERY_APP.task()
|
||||
def _policy_engine_task(user_pk, policy_pk, **kwargs):
|
||||
"""Task wrapper to run policy checking"""
|
||||
|
@ -66,8 +58,11 @@ class PolicyEngine:
|
|||
signatures = []
|
||||
kwargs = {
|
||||
'__password__': getattr(self._user, '__password__', None),
|
||||
'remote_ip': get_remote_ip(self._request)
|
||||
}
|
||||
if self._request:
|
||||
kwargs['remote_ip'], _ = get_client_ip(self._request)
|
||||
if not kwargs['remote_ip']:
|
||||
kwargs['remote_ip'] = '255.255.255.255',
|
||||
for policy in self.policies:
|
||||
signatures.append(_policy_engine_task.s(self._user.pk, policy.pk.hex, **kwargs))
|
||||
self._group = group(signatures)()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
django>=2.0
|
||||
django-model-utils
|
||||
django-ipware
|
||||
djangorestframework
|
||||
PyYAML
|
||||
raven
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
django-ipware
|
|
@ -13,7 +13,9 @@ LOGGER = getLogger(__name__)
|
|||
|
||||
def update_score(request, username, amount):
|
||||
"""Update score for IP and User"""
|
||||
remote_ip = get_client_ip(request)
|
||||
remote_ip, _ = get_client_ip(request)
|
||||
if not remote_ip:
|
||||
remote_ip = '255.255.255.255'
|
||||
ip_score, _ = IPScore.objects.update_or_create(ip=remote_ip)
|
||||
ip_score.score += amount
|
||||
ip_score.save()
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
-r passbook/saml_idp/requirements.txt
|
||||
-r passbook/otp/requirements.txt
|
||||
-r passbook/oauth_provider/requirements.txt
|
||||
-r passbook/suspicious_policy/requirements.txt
|
||||
-r passbook/captcha_factor/requirements.txt
|
||||
-r passbook/admin/requirements.txt
|
||||
-r passbook/api/requirements.txt
|
||||
|
|
Reference in New Issue