mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Friskies pl0x?
This commit is contained in:
parent
6512bbf70c
commit
ae73e94c3e
2 changed files with 8 additions and 13 deletions
src
|
@ -37,6 +37,10 @@ class Authenticator(BaseAuthenticator):
|
||||||
os.system("systemctl restart slapd")
|
os.system("systemctl restart slapd")
|
||||||
time.sleep(10) # waits 10 secondes so we are sure that slapd has restarted
|
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:
|
try:
|
||||||
admins = _get_ldap_interface().search(ADMIN_GROUP, attrs=["memberUid"])[0].get("memberUid", [])
|
admins = _get_ldap_interface().search(ADMIN_GROUP, attrs=["memberUid"])[0].get("memberUid", [])
|
||||||
except ldap.SERVER_DOWN:
|
except ldap.SERVER_DOWN:
|
||||||
|
|
|
@ -2,7 +2,6 @@ import pytest
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from yunohost.authenticators.ldap_admin import Authenticator as LDAPAuth
|
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.user import user_create, user_list, user_update, user_delete
|
||||||
from yunohost.domain import _get_maindomain
|
from yunohost.domain import _get_maindomain
|
||||||
|
|
||||||
|
@ -17,7 +16,7 @@ def setup_function(function):
|
||||||
|
|
||||||
maindomain = _get_maindomain()
|
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")
|
os.system("systemctl start slapd && sleep 3")
|
||||||
|
|
||||||
user_create("alice", "Alice", "White", maindomain, "Yunohost", admin=True)
|
user_create("alice", "Alice", "White", maindomain, "Yunohost", admin=True)
|
||||||
|
@ -26,7 +25,7 @@ def setup_function(function):
|
||||||
|
|
||||||
def teardown_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"]:
|
for u in user_list()["users"]:
|
||||||
user_delete(u, purge=True)
|
user_delete(u, purge=True)
|
||||||
|
@ -67,20 +66,14 @@ def test_authenticate_with_wrong_password():
|
||||||
def test_authenticate_server_down(mocker):
|
def test_authenticate_server_down(mocker):
|
||||||
os.system("systemctl stop slapd && sleep 5")
|
os.system("systemctl stop slapd && sleep 5")
|
||||||
|
|
||||||
# Now if slapd is down, moulinette tries to restart it
|
LDAPAuth().authenticate_credentials(credentials="alice:Yunohost")
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
def test_authenticate_change_password():
|
def test_authenticate_change_password():
|
||||||
|
|
||||||
LDAPAuth().authenticate_credentials(credentials="alice:Yunohost")
|
LDAPAuth().authenticate_credentials(credentials="alice:Yunohost")
|
||||||
|
|
||||||
tools_rootpw("plopette", check_strength=False)
|
user_update("alice", change_password="plopette")
|
||||||
|
|
||||||
with pytest.raises(MoulinetteError) as exception:
|
with pytest.raises(MoulinetteError) as exception:
|
||||||
LDAPAuth().authenticate_credentials(credentials="alice:Yunohost")
|
LDAPAuth().authenticate_credentials(credentials="alice:Yunohost")
|
||||||
|
@ -89,6 +82,4 @@ def test_authenticate_change_password():
|
||||||
expected_msg = translation.format()
|
expected_msg = translation.format()
|
||||||
assert expected_msg in str(exception)
|
assert expected_msg in str(exception)
|
||||||
|
|
||||||
user_update("alice", password="plopette")
|
|
||||||
|
|
||||||
LDAPAuth().authenticate_credentials(credentials="alice:plopette")
|
LDAPAuth().authenticate_credentials(credentials="alice:plopette")
|
||||||
|
|
Loading…
Add table
Reference in a new issue