Skip to content
Permalink
Browse files

Fix remarks from review

  • Loading branch information...
plettich committed Aug 28, 2019
1 parent d5b19a4 commit 61743ea1deba59637d759337c73e611b41bf7843
@@ -82,7 +82,7 @@
import datetime

from privacyidea.lib import _
from privacyidea.lib.utils import to_utf8, to_unicode
from privacyidea.lib.utils import to_utf8, to_unicode, convert_column_to_unicode
from privacyidea.lib.error import privacyIDEAError
import uuid
from ldap3.utils.conv import escape_bytes
@@ -418,7 +418,7 @@ def _get_uid(entry, uidtype):
# we strip the curly braces from objectGUID values.
# If we are using ldap3 <= 2.4.1, there are no curly braces and we leave the value unchanged.
uid = uid.strip("{").strip("}")
return uid
return convert_column_to_unicode(uid)

def _trim_user_id(self, userId):
"""
@@ -570,7 +570,7 @@ def getUserId(self, LoginName):
resolve the loginname to the userid.
:param LoginName: The login name from the credentials
:type LoginName: string
:type LoginName: str
:return: UserId as found for the LoginName
:rtype: str
"""
@@ -626,7 +626,7 @@ def getUserId(self, LoginName):
LoginName))

for entry in r:
userid = str(self._get_uid(entry, self.uidtype))
userid = self._get_uid(entry, self.uidtype)

return userid

@@ -48,7 +48,7 @@
import codecs
import six

from privacyidea.lib.utils import to_bytes
from privacyidea.lib.utils import to_bytes, convert_column_to_unicode
from .UserIdResolver import UserIdResolver

log = logging.getLogger(__name__)
@@ -265,11 +265,12 @@ def getUserId(self, LoginName):
:param LoginName: the login of the user (as unicode)
:return: the userId
:rtype: str
"""
# We do not encode the LoginName anymore, as we are
# storing unicode in nameDict now.
if LoginName in self.nameDict:
return str(self.nameDict[LoginName])
return convert_column_to_unicode(self.nameDict[LoginName])
else:
return ""

@@ -45,7 +45,7 @@
import requests
import base64
from six.moves.urllib.parse import urlencode
from privacyidea.lib.utils import to_bytes, to_unicode
from privacyidea.lib.utils import to_bytes, to_unicode, convert_column_to_unicode

log = logging.getLogger(__name__)

@@ -124,6 +124,7 @@ def getUsername(self, userid):
def getUserId(self, loginName):
"""
returns the uid for a given loginname/username
:rtype: str
"""
#res = {}
#if self.access_token:
@@ -133,7 +134,7 @@ def getUserId(self, loginName):
# ("userName", loginName)})
#return res.get("Resources", [{}])[0].get("externalId")
# It seems that the userName is the userId
return str(loginName)
return convert_column_to_unicode(loginName)

def getUserList(self, searchDict=None):
"""
@@ -34,7 +34,6 @@
import yaml
import binascii
import re
import six

from privacyidea.lib.resolvers.UserIdResolver import UserIdResolver

@@ -47,7 +46,8 @@
import hashlib
from privacyidea.lib.pooling import get_engine
from privacyidea.lib.lifecycle import register_finalizer
from privacyidea.lib.utils import (is_true, censor_connect_string, to_utf8)
from privacyidea.lib.utils import (is_true, censor_connect_string,
convert_column_to_unicode)
from passlib.context import CryptContext
from base64 import b64decode, b64encode
from passlib.utils import h64
@@ -399,7 +399,7 @@ def getUserId(self, LoginName):
raise Exception("More than one user with loginname"
" %s found!" % LoginName)
user = self._get_user_from_mapped_object(r)
userid = str(user["id"])
userid = convert_column_to_unicode(user["id"])
except Exception as exx: # pragma: no cover
log.error("Could not get the userinformation: {0!r}".format(exx))

@@ -57,7 +57,7 @@
import inspect
from collections import namedtuple, Sequence, Sized
from functools import update_wrapper
from privacyidea.lib.utils import to_bytes
from privacyidea.lib.utils import to_bytes, to_unicode

DIRECTORY = "tests/testdata/tmp_directory"

@@ -357,7 +357,7 @@ def _match_equal_to(search_base, attribute, value, candidates):
regex = "^{0}$".format(regex)

for entry in candidates:
dn = entry.get("dn")
dn = to_unicode(entry.get("dn"))

if attribute not in entry.get("attributes") or not dn.endswith(search_base):
continue
@@ -663,7 +663,7 @@ def search(self, search_base=None, search_scope=None,
if isinstance(search_filter, bytes):
# We need to convert to unicode otherwise pyparsing will not
# find the u"ö"
search_filter = search_filter.decode("utf-8")
search_filter = to_unicode(search_filter)
expr = Connection._parse_filter()
s_filter = expr.parseString(search_filter).asList()[0]
except pyparsing.ParseBaseException as exx:
@@ -756,7 +756,7 @@ def _on_Connection(self, server, user, password,
if authentication == ldap3.ANONYMOUS and user == "":
correct_password = True
for entry in self.directory:
if entry.get("dn") == user:
if to_unicode(entry.get("dn")) == user:
pw = entry.get("attributes").get("userPassword")
# password can be unicode
if to_bytes(pw) == to_bytes(password):
@@ -1628,7 +1628,7 @@ def test_25_LDAP_DN_with_utf8(self):

user = u"kölbel".encode('utf8')
user_id = y.getUserId(user)
self.assertEqual(user_id, "cn=kölbel,ou=example,o=test")
self.assertEqual(user_id, u"cn=kölbel,ou=example,o=test")

rid = y.getResolverId()
self.assertTrue(rid == "035fbc6272907bc79a2c036b5bf9665ca921d558", rid)
@@ -1682,7 +1682,7 @@ def test_26_LDAP_DN_with_unicode(self):

user = u"kölbel"
user_id = y.getUserId(user)
self.assertEqual(user_id, "cn=kölbel,ou=example,o=test")
self.assertEqual(user_id, u"cn=kölbel,ou=example,o=test")

rid = y.getResolverId()
self.assertTrue(rid == "035fbc6272907bc79a2c036b5bf9665ca921d558", rid)
@@ -1735,11 +1735,11 @@ def test_27_LDAP_multiple_loginnames(self):

user = u"kölbel"
user_id = y.getUserId(user)
self.assertEqual(user_id, "cn=kölbel,ou=example,o=test")
self.assertEqual(user_id, u"cn=kölbel,ou=example,o=test")

username = "cko@o"
user_id = y.getUserId(username)
self.assertEqual(user_id, "cn=kölbel,ou=example,o=test")
self.assertEqual(user_id, u"cn=kölbel,ou=example,o=test")

@ldap3mock.activate
def test_28_LDAP_multivalues(self):
@@ -1767,7 +1767,7 @@ def test_28_LDAP_multivalues(self):

user = u"kölbel"
user_id = y.getUserId(user)
self.assertEqual(user_id, "cn=kölbel,ou=example,o=test")
self.assertEqual(user_id, u"cn=kölbel,ou=example,o=test")
info = y.getUserInfo(user_id)
self.assertTrue("value1" in info.get("piAttr"))
self.assertTrue("value2" in info.get("piAttr"))

0 comments on commit 61743ea

Please sign in to comment.
You can’t perform that action at this time.