mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
password -> credentials, pave the way to multi-admins
This commit is contained in:
parent
075526303e
commit
52920cc52f
2 changed files with 12 additions and 8 deletions
|
@ -21,12 +21,16 @@ class Authenticator(BaseAuthenticator):
|
||||||
self.basedn = "dc=yunohost,dc=org"
|
self.basedn = "dc=yunohost,dc=org"
|
||||||
self.admindn = "cn=admin,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():
|
def _reconnect():
|
||||||
con = ldap.ldapobject.ReconnectLDAPObject(
|
con = ldap.ldapobject.ReconnectLDAPObject(
|
||||||
self.uri, retry_max=10, retry_delay=0.5
|
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
|
return con
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -16,12 +16,12 @@ def setup_function(function):
|
||||||
|
|
||||||
|
|
||||||
def test_authenticate():
|
def test_authenticate():
|
||||||
LDAPAuth().authenticate(password="yunohost")
|
LDAPAuth().authenticate(credentials="yunohost")
|
||||||
|
|
||||||
|
|
||||||
def test_authenticate_with_wrong_password():
|
def test_authenticate_with_wrong_password():
|
||||||
with pytest.raises(MoulinetteError) as exception:
|
with pytest.raises(MoulinetteError) as exception:
|
||||||
LDAPAuth().authenticate(password="bad_password_lul")
|
LDAPAuth().authenticate(credentials="bad_password_lul")
|
||||||
|
|
||||||
translation = m18n.g("invalid_password")
|
translation = m18n.g("invalid_password")
|
||||||
expected_msg = translation.format()
|
expected_msg = translation.format()
|
||||||
|
@ -35,7 +35,7 @@ def test_authenticate_server_down(mocker):
|
||||||
mocker.patch("os.system")
|
mocker.patch("os.system")
|
||||||
mocker.patch("time.sleep")
|
mocker.patch("time.sleep")
|
||||||
with pytest.raises(MoulinetteError) as exception:
|
with pytest.raises(MoulinetteError) as exception:
|
||||||
LDAPAuth().authenticate(password="yunohost")
|
LDAPAuth().authenticate(credentials="yunohost")
|
||||||
|
|
||||||
translation = m18n.n("ldap_server_down")
|
translation = m18n.n("ldap_server_down")
|
||||||
expected_msg = translation.format()
|
expected_msg = translation.format()
|
||||||
|
@ -44,15 +44,15 @@ def test_authenticate_server_down(mocker):
|
||||||
|
|
||||||
def test_authenticate_change_password():
|
def test_authenticate_change_password():
|
||||||
|
|
||||||
LDAPAuth().authenticate(password="yunohost")
|
LDAPAuth().authenticate(credentials="yunohost")
|
||||||
|
|
||||||
tools_adminpw("plopette", check_strength=False)
|
tools_adminpw("plopette", check_strength=False)
|
||||||
|
|
||||||
with pytest.raises(MoulinetteError) as exception:
|
with pytest.raises(MoulinetteError) as exception:
|
||||||
LDAPAuth().authenticate(password="yunohost")
|
LDAPAuth().authenticate(credentials="yunohost")
|
||||||
|
|
||||||
translation = m18n.g("invalid_password")
|
translation = m18n.g("invalid_password")
|
||||||
expected_msg = translation.format()
|
expected_msg = translation.format()
|
||||||
assert expected_msg in str(exception)
|
assert expected_msg in str(exception)
|
||||||
|
|
||||||
LDAPAuth().authenticate(password="plopette")
|
LDAPAuth().authenticate(credentials="plopette")
|
||||||
|
|
Loading…
Add table
Reference in a new issue