mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
commit
7da5b19320
5 changed files with 16 additions and 4 deletions
|
@ -564,6 +564,7 @@ class ActionsMap(object):
|
||||||
func = getattr(mod, func_name)
|
func = getattr(mod, func_name)
|
||||||
except (AttributeError, ImportError):
|
except (AttributeError, ImportError):
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
logger.exception("unable to load function %s.%s", namespace, func_name)
|
logger.exception("unable to load function %s.%s", namespace, func_name)
|
||||||
raise MoulinetteError("error_see_log")
|
raise MoulinetteError("error_see_log")
|
||||||
|
|
|
@ -362,6 +362,7 @@ class _CallbackAction(argparse.Action):
|
||||||
func = getattr(mod, func_name)
|
func = getattr(mod, func_name)
|
||||||
except (AttributeError, ImportError):
|
except (AttributeError, ImportError):
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
raise ValueError("unable to import method {0}".format(self.callback_method))
|
raise ValueError("unable to import method {0}".format(self.callback_method))
|
||||||
self._callback = func
|
self._callback = func
|
||||||
|
|
|
@ -175,7 +175,7 @@ def get_locale():
|
||||||
except Exception:
|
except Exception:
|
||||||
# In some edge case the locale lib fails ...
|
# In some edge case the locale lib fails ...
|
||||||
# c.f. https://forum.yunohost.org/t/error-when-trying-to-enter-user-information-in-admin-panel/11390/11
|
# c.f. https://forum.yunohost.org/t/error-when-trying-to-enter-user-information-in-admin-panel/11390/11
|
||||||
lang = os.getenv('LANG')
|
lang = os.getenv("LANG")
|
||||||
if not lang:
|
if not lang:
|
||||||
return ""
|
return ""
|
||||||
return lang[:2]
|
return lang[:2]
|
||||||
|
|
|
@ -253,11 +253,18 @@ def test_actions_map_import_error(mocker):
|
||||||
|
|
||||||
mocker.patch.object(MoulinetteLock, "_is_son_of", return_value=False)
|
mocker.patch.object(MoulinetteLock, "_is_son_of", return_value=False)
|
||||||
|
|
||||||
mocker.patch("__builtin__.__import__", side_effect=ImportError)
|
orig_import = __import__
|
||||||
|
|
||||||
|
def import_mock(name, globals={}, locals={}, fromlist=[], level=-1):
|
||||||
|
if name == "moulitest.testauth":
|
||||||
|
mocker.stopall()
|
||||||
|
raise ImportError
|
||||||
|
return orig_import(name, globals, locals, fromlist, level)
|
||||||
|
|
||||||
|
mocker.patch("__builtin__.__import__", side_effect=import_mock)
|
||||||
with pytest.raises(MoulinetteError) as exception:
|
with pytest.raises(MoulinetteError) as exception:
|
||||||
amap.process({}, timeout=30, route=("GET", "/test-auth/none"))
|
amap.process({}, timeout=30, route=("GET", "/test-auth/none"))
|
||||||
|
|
||||||
mocker.stopall()
|
|
||||||
translation = m18n.g("error_see_log")
|
translation = m18n.g("error_see_log")
|
||||||
expected_msg = translation.format()
|
expected_msg = translation.format()
|
||||||
assert expected_msg in str(exception)
|
assert expected_msg in str(exception)
|
||||||
|
|
|
@ -66,11 +66,14 @@ class TestLDAP:
|
||||||
|
|
||||||
assert ldap_interface.con
|
assert ldap_interface.con
|
||||||
|
|
||||||
def test_authenticate_server_down(self, ldap_server):
|
def test_authenticate_server_down(self, ldap_server, mocker):
|
||||||
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
|
self.ldap_conf["parameters"]["uri"] = ldap_server.uri
|
||||||
self.ldap_conf["parameters"]["user_rdn"] = "cn=admin,dc=yunohost,dc=org"
|
self.ldap_conf["parameters"]["user_rdn"] = "cn=admin,dc=yunohost,dc=org"
|
||||||
ldap_server.stop()
|
ldap_server.stop()
|
||||||
ldap_interface = m_ldap.Authenticator(**self.ldap_conf)
|
ldap_interface = m_ldap.Authenticator(**self.ldap_conf)
|
||||||
|
|
||||||
|
# Now if slapd is down, moulinette tries to restart it
|
||||||
|
mocker.patch("os.system")
|
||||||
with pytest.raises(MoulinetteError) as exception:
|
with pytest.raises(MoulinetteError) as exception:
|
||||||
ldap_interface.authenticate(password="yunohost")
|
ldap_interface.authenticate(password="yunohost")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue