From e1711a2b2cb904f7edc26cc68566e064896d4f8a Mon Sep 17 00:00:00 2001 From: Lukas Slebodnik Date: Jan 16 2017 18:11:40 +0000 Subject: intg: Use bytes with hash function Python3 expects bytes as an input for hash function. We need to convert string to bytes before hashing Traceback (most recent call last): File "src/tests/intg/test_ldap.py", line 51, in ds_inst ds_inst.setup() File "src/tests/intg/ds_openldap.py", line 200, in setup self._setup_config() File "src/tests/intg/ds_openldap.py", line 76, in _setup_config admin_pw_hash = hash_password(self.admin_pw) File "src/tests/intg/ds_openldap.py", line 41, in hash_password hash = hashlib.sha1(password) TypeError: Unicode-objects must be encoded before hashing Reviewed-by: Martin Basti --- diff --git a/src/tests/intg/ds_openldap.py b/src/tests/intg/ds_openldap.py index c6bb7f2..bbc101a 100644 --- a/src/tests/intg/ds_openldap.py +++ b/src/tests/intg/ds_openldap.py @@ -38,9 +38,10 @@ except ImportError: def hash_password(password): """Generate userPassword value for a password.""" salt = os.urandom(4) - hash = hashlib.sha1(password) + hash = hashlib.sha1(password.encode('utf-8')) hash.update(salt) - return "{SSHA}" + base64.standard_b64encode(hash.digest() + salt) + hash_base64 = base64.standard_b64encode(hash.digest() + salt) + return "{SSHA}" + hash_base64.decode('utf-8') class DSOpenLDAP(DS):