1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-02-02 09:47:13 +03:00

fixed actor_v3 merge errors

This commit is contained in:
Adolfo Gómez García 2023-01-19 18:17:53 +01:00
parent 44be2f4df5
commit 5b5de7ce90
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
4 changed files with 14 additions and 14 deletions

View File

@ -4,5 +4,5 @@ python_files = tests.py test_*.py *_tests.py
# Do not look for classes (all test clasess are descendant of unittest.TestCase), some of which are named Test* but are not tests (e.g. TestProvider)
python_classes =
# If coverage is enabled, debug test will not work on vscode
#addopts = --cov --cov-report html --cov-config=coverage.ini -n 12
addopts = --cov --cov-report html --cov-config=coverage.ini -n 12
#addopts = --cov --cov-report html --cov-config=coverage.ini -n 12

View File

@ -137,7 +137,7 @@ class ActorInitializeTest(rest.test.RESTActorTestCase):
self.assertIsNone(result['os'])
self.assertIsNone(result['unique_id'])
def test_initialize_unmanaged(self):
def test_initialize_unmanaged(self) -> None:
"""
Test actor initialize v3 for unmanaged actor
"""

View File

@ -81,11 +81,11 @@ def fixIdsList(idsList: typing.List[str]) -> typing.List[str]:
def checkBlockedIp(request: 'ExtendedHttpRequest') -> None:
if GlobalConfig.BLOCK_ACTOR_FAILURES.getBool() is False:
return
fails = cache.get(ip) or 0
fails = cache.get(request.ip) or 0
if fails >= ALLOWED_FAILS:
logger.info(
'Access to actor from %s is blocked for %s seconds since last fail',
ip,
request.ip,
GlobalConfig.LOGIN_BLOCK.getInt(),
)
# Sleep a while to try to minimize brute force attacks somehow
@ -93,9 +93,9 @@ def checkBlockedIp(request: 'ExtendedHttpRequest') -> None:
raise BlockAccess()
def incFailedIp(ip: str) -> None:
fails = cache.get(ip, 0) + 1
cache.put(ip, fails, GlobalConfig.LOGIN_BLOCK.getInt())
def incFailedIp(request: 'ExtendedHttpRequest') -> None:
fails = cache.get(request.ip, 0) + 1
cache.put(request.ip, fails, GlobalConfig.LOGIN_BLOCK.getInt())
# Decorator that clears failed counter for the IP if succeeds
@ -106,14 +106,14 @@ def clearIfSuccess(func: typing.Callable) -> typing.Callable:
result = func(
*args, **kwargs
) # If raises any exception, it will be raised and we will not clear the counter
clearFailedIp(_self._request.ip)
clearFailedIp(_self._request)
return result
return wrapper
def clearFailedIp(ip: str) -> None:
cache.remove(ip)
def clearFailedIp(request: 'ExtendedHttpRequest') -> None:
cache.remove(request.ip)
class ActorV3Action(Handler):
@ -178,10 +178,10 @@ class Test(ActorV3Action):
ActorToken.objects.get(
token=self._params['token']
) # Not assigned, because only needs check
clearFailedIp(self._request.ip)
clearFailedIp(self._request)
except Exception:
# Increase failed attempts
incFailedIp(self._request.ip)
incFailedIp(self._request)
# And return test failed
return ActorV3Action.actorResult('invalid token')

View File

@ -249,7 +249,7 @@ class Auths(Handler):
path = 'auth'
authenticated = False # By default, all handlers needs authentication
def auths(self):
def auths(self) -> typing.Iterable[typing.Dict[str, typing.Any]]:
paramAll: bool = self._params.get('all', 'false') == 'true'
auth: Authenticator
for auth in Authenticator.objects.all():
@ -266,5 +266,5 @@ class Auths(Handler):
'isCustom': theType.isCustom(),
}
def get(self):
def get(self) -> typing.List[typing.Dict[str, typing.Any]]:
return list(self.auths())