be able to mock ldap uri

This commit is contained in:
Kay0u 2020-01-08 01:38:36 +08:00
parent 32711aa034
commit 142081a934
No known key found for this signature in database
GPG key ID: 7FF262C033518333

View file

@ -43,7 +43,7 @@ class Authenticator(BaseAuthenticator):
"initialize authenticator '%s' with: uri='%s', " "initialize authenticator '%s' with: uri='%s', "
"base_dn='%s', user_rdn='%s'", "base_dn='%s', user_rdn='%s'",
name, name,
self.uri, self._get_uri(),
self.basedn, self.basedn,
self.userdn, self.userdn,
) )
@ -68,7 +68,7 @@ class Authenticator(BaseAuthenticator):
def authenticate(self, password=None): def authenticate(self, password=None):
try: try:
con = ldap.ldapobject.ReconnectLDAPObject( con = ldap.ldapobject.ReconnectLDAPObject(
self.uri, retry_max=10, retry_delay=0.5 self._get_uri(), retry_max=10, retry_delay=0.5
) )
if self.userdn: if self.userdn:
if "cn=external,cn=auth" in self.userdn: if "cn=external,cn=auth" in self.userdn:
@ -301,6 +301,9 @@ class Authenticator(BaseAuthenticator):
return (attr, value) return (attr, value)
return None return None
def _get_uri(self):
return self.uri
def _encode_dict(self, _dict): def _encode_dict(self, _dict):
return {k: self._encode_list(v) for k, v in _dict.items()} return {k: self._encode_list(v) for k, v in _dict.items()}