From 52920cc52f777143875a3435e9d46a36d514db05 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Mon, 14 Jun 2021 17:31:08 +0200 Subject: [PATCH] password -> credentials, pave the way to multi-admins --- src/yunohost/authenticators/ldap_admin.py | 8 ++++++-- src/yunohost/tests/test_ldap.py | 12 ++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/yunohost/authenticators/ldap_admin.py b/src/yunohost/authenticators/ldap_admin.py index 47efe5bf9..808497b31 100644 --- a/src/yunohost/authenticators/ldap_admin.py +++ b/src/yunohost/authenticators/ldap_admin.py @@ -21,12 +21,16 @@ class Authenticator(BaseAuthenticator): self.basedn = "dc=yunohost,dc=org" self.admindn = "cn=admin,dc=yunohost,dc=org" - def authenticate(self, password=None): + def authenticate(self, credentials=None): + + # TODO : change authentication format + # to support another dn to support multi-admins + def _reconnect(): con = ldap.ldapobject.ReconnectLDAPObject( self.uri, retry_max=10, retry_delay=0.5 ) - con.simple_bind_s(self.admindn, password) + con.simple_bind_s(self.admindn, credentials) return con try: diff --git a/src/yunohost/tests/test_ldap.py b/src/yunohost/tests/test_ldap.py index b3a5efc09..0ad8366c9 100644 --- a/src/yunohost/tests/test_ldap.py +++ b/src/yunohost/tests/test_ldap.py @@ -16,12 +16,12 @@ def setup_function(function): def test_authenticate(): - LDAPAuth().authenticate(password="yunohost") + LDAPAuth().authenticate(credentials="yunohost") def test_authenticate_with_wrong_password(): with pytest.raises(MoulinetteError) as exception: - LDAPAuth().authenticate(password="bad_password_lul") + LDAPAuth().authenticate(credentials="bad_password_lul") translation = m18n.g("invalid_password") expected_msg = translation.format() @@ -35,7 +35,7 @@ def test_authenticate_server_down(mocker): mocker.patch("os.system") mocker.patch("time.sleep") with pytest.raises(MoulinetteError) as exception: - LDAPAuth().authenticate(password="yunohost") + LDAPAuth().authenticate(credentials="yunohost") translation = m18n.n("ldap_server_down") expected_msg = translation.format() @@ -44,15 +44,15 @@ def test_authenticate_server_down(mocker): def test_authenticate_change_password(): - LDAPAuth().authenticate(password="yunohost") + LDAPAuth().authenticate(credentials="yunohost") tools_adminpw("plopette", check_strength=False) with pytest.raises(MoulinetteError) as exception: - LDAPAuth().authenticate(password="yunohost") + LDAPAuth().authenticate(credentials="yunohost") translation = m18n.g("invalid_password") expected_msg = translation.format() assert expected_msg in str(exception) - LDAPAuth().authenticate(password="plopette") + LDAPAuth().authenticate(credentials="plopette")