diff --git a/moulinette/authenticators/ldap.py b/moulinette/authenticators/ldap.py index e0b0dfac..0320d375 100644 --- a/moulinette/authenticators/ldap.py +++ b/moulinette/authenticators/ldap.py @@ -117,7 +117,7 @@ class Authenticator(BaseAuthenticator): # we aren't using sha-512 but something else that is weaker, proceed to upgrade if not hashed_password["userPassword"][0].startswith("{CRYPT}$6$"): - self.update("cn=admin", {"userPassword": _hash_user_password(password),}) + self.update("cn=admin", {"userPassword": _hash_user_password(password)}) # Additional LDAP methods # TODO: Review these methods diff --git a/moulinette/utils/log.py b/moulinette/utils/log.py index 58d27d11..16a3fc23 100644 --- a/moulinette/utils/log.py +++ b/moulinette/utils/log.py @@ -16,6 +16,16 @@ from logging import ( CRITICAL, ) +__all__ = [ + "NOTSET", # noqa + "DEBUG", + "INFO", + "WARNING", + "ERROR", + "CRITICAL", + "SUCCESS", +] + # Global configuration and functions ----------------------------------- @@ -35,7 +45,7 @@ DEFAULT_LOGGING = { "stream": "ext://sys.stdout", }, }, - "loggers": {"moulinette": {"level": "DEBUG", "handlers": ["console"],},}, + "loggers": {"moulinette": {"level": "DEBUG", "handlers": ["console"]}}, } diff --git a/test/conftest.py b/test/conftest.py index 23c4523c..68968cae 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -55,7 +55,7 @@ def patch_logging(moulinette): "format": "%(asctime)-15s %(levelname)-8s %(name)s %(funcName)s - %(fmessage)s" # noqa }, }, - "filters": {"action": {"()": "moulinette.utils.log.ActionFilter",},}, + "filters": {"action": {"()": "moulinette.utils.log.ActionFilter"}}, "handlers": { "api": { "level": level, @@ -68,14 +68,14 @@ def patch_logging(moulinette): }, }, "loggers": { - "moulinette": {"level": level, "handlers": [], "propagate": True,}, + "moulinette": {"level": level, "handlers": [], "propagate": True}, "moulinette.interface": { "level": level, "handlers": handlers, "propagate": False, }, }, - "root": {"level": level, "handlers": root_handlers,}, + "root": {"level": level, "handlers": root_handlers}, } diff --git a/test/test_actionsmap.py b/test/test_actionsmap.py index a7d94cc8..89f12cdb 100644 --- a/test/test_actionsmap.py +++ b/test/test_actionsmap.py @@ -284,4 +284,4 @@ def test_actions_map_cli(): assert 'testauth' in amap.parser._subparsers.choices assert 'none' in amap.parser._subparsers.choices['testauth']._actions[1].choices assert 'subcat' in amap.parser._subparsers.choices['testauth']._actions[1].choices - assert 'default' in amap.parser._subparsers.choices['testauth']._actions[1].choices['subcat']._actions[1].choices \ No newline at end of file + assert 'default' in amap.parser._subparsers.choices['testauth']._actions[1].choices['subcat']._actions[1].choices diff --git a/test/test_auth.py b/test/test_auth.py index c6054003..01235db8 100644 --- a/test/test_auth.py +++ b/test/test_auth.py @@ -1,6 +1,5 @@ import os import pytest -import json from moulinette import MoulinetteError from moulinette import m18n @@ -79,7 +78,6 @@ class TestAuthAPI: assert "session.id" not in moulinette_webapi.cookies assert "session.tokens" not in moulinette_webapi.cookies - def test_login_csrf_attempt(self, moulinette_webapi): # C.f. # https://security.stackexchange.com/a/58308 diff --git a/test/test_filesystem.py b/test/test_filesystem.py index 545574d0..12ccbc3b 100644 --- a/test/test_filesystem.py +++ b/test/test_filesystem.py @@ -4,8 +4,6 @@ import pytest import pwd import grp -from stat import * - from moulinette import m18n from moulinette.core import MoulinetteError from moulinette.utils.filesystem import ( @@ -158,6 +156,7 @@ def test_read_ldif_cannot_exception(test_ldif, mocker): expected_msg = translation.format(file=str(test_ldif), error=error) assert expected_msg in str(exception) + def test_write_to_existing_file(test_file): write_to_file(str(test_file), "yolo\nswag") assert read_file(str(test_file)) == "yolo\nswag" diff --git a/test/test_process.py b/test/test_process.py index 93034d80..a687debe 100644 --- a/test/test_process.py +++ b/test/test_process.py @@ -25,6 +25,7 @@ def test_run_shell_bad_cmd_with_callback(): assert isinstance(b, str) assert isinstance(c, str) return True + assert run_commands(["yolo swag", "yolo swag", "yolo swag"], callback=callback) == 3 def callback(a, b, c): @@ -32,6 +33,7 @@ def test_run_shell_bad_cmd_with_callback(): assert isinstance(b, str) assert isinstance(c, str) return False + assert run_commands(["yolo swag", "yolo swag"], callback=callback) == 1 def callback(a, b, c): @@ -39,6 +41,7 @@ def test_run_shell_bad_cmd_with_callback(): assert isinstance(b, str) assert isinstance(c, tuple) return True + run_commands(["yolo swag"], separate_stderr=True, callback=callback) @@ -62,9 +65,9 @@ def test_run_shell_kwargs(): def test_call_async_output(test_file): - def callback(a): assert a == "foo\n" or a == "bar\n" + call_async_output(["cat", str(test_file)], callback) with pytest.raises(ValueError): @@ -72,8 +75,10 @@ def test_call_async_output(test_file): def callbackA(a): assert a == "foo\n" or a == "bar\n" + def callbackB(a): pass + callback = (callbackA, callbackB) call_async_output(["cat", str(test_file)], callback) @@ -91,8 +96,10 @@ def test_call_async_output_kwargs(test_file, mocker): def callbackA(a): assert a == "foo\n" or a == "bar\n" + def callbackB(a): pass + def callbackC(a): pass