Friskies pl0x?

This commit is contained in:
Alexandre Aubin 2022-10-04 02:00:40 +02:00
parent 6512bbf70c
commit ae73e94c3e
2 changed files with 8 additions and 13 deletions

View file

@ -37,6 +37,10 @@ class Authenticator(BaseAuthenticator):
os.system("systemctl restart slapd")
time.sleep(10) # waits 10 secondes so we are sure that slapd has restarted
# Force-reset existing LDAP interface
from yunohost.utils import ldap as ldaputils
ldaputils._ldap_interface = None
try:
admins = _get_ldap_interface().search(ADMIN_GROUP, attrs=["memberUid"])[0].get("memberUid", [])
except ldap.SERVER_DOWN:

View file

@ -2,7 +2,6 @@ import pytest
import os
from yunohost.authenticators.ldap_admin import Authenticator as LDAPAuth
from yunohost.tools import tools_rootpw
from yunohost.user import user_create, user_list, user_update, user_delete
from yunohost.domain import _get_maindomain
@ -17,7 +16,7 @@ def setup_function(function):
maindomain = _get_maindomain()
if os.system("systemctl is-active slapd") != 0:
if os.system("systemctl is-active slapd >/dev/null") != 0:
os.system("systemctl start slapd && sleep 3")
user_create("alice", "Alice", "White", maindomain, "Yunohost", admin=True)
@ -26,7 +25,7 @@ def setup_function(function):
def teardown_function():
os.system("systemctl is-active slapd || systemctl start slapd && sleep 5")
os.system("systemctl is-active slapd >/dev/null || systemctl start slapd; sleep 5")
for u in user_list()["users"]:
user_delete(u, purge=True)
@ -67,20 +66,14 @@ def test_authenticate_with_wrong_password():
def test_authenticate_server_down(mocker):
os.system("systemctl stop slapd && sleep 5")
# Now if slapd is down, moulinette tries to restart it
mocker.patch("os.system")
mocker.patch("time.sleep")
with pytest.raises(MoulinetteError) as exception:
LDAPAuth().authenticate_credentials(credentials="alice:Yunohost")
assert "Unable to reach LDAP server" in str(exception)
LDAPAuth().authenticate_credentials(credentials="alice:Yunohost")
def test_authenticate_change_password():
LDAPAuth().authenticate_credentials(credentials="alice:Yunohost")
tools_rootpw("plopette", check_strength=False)
user_update("alice", change_password="plopette")
with pytest.raises(MoulinetteError) as exception:
LDAPAuth().authenticate_credentials(credentials="alice:Yunohost")
@ -89,6 +82,4 @@ def test_authenticate_change_password():
expected_msg = translation.format()
assert expected_msg in str(exception)
user_update("alice", password="plopette")
LDAPAuth().authenticate_credentials(credentials="alice:plopette")