mirror of
https://github.com/clearlinux/WALinuxAgent.git
synced 2026-09-04 04:41:35 +00:00
Merge pull request #537 from jinhyunr/fix_password_encoding
Fix password encrypting failure in python 2.* (#516)
This commit is contained in:
@@ -267,6 +267,9 @@ def gen_password_hash(password, crypt_id, salt_len):
|
||||
collection = string.ascii_letters + string.digits
|
||||
salt = ''.join(random.choice(collection) for _ in range(salt_len))
|
||||
salt = "${0}${1}".format(crypt_id, salt)
|
||||
if sys.version_info[0] == 2:
|
||||
# if python 2.*, encode to type 'str' to prevent Unicode Encode Error from crypt.crypt
|
||||
password = password.encode('utf-8')
|
||||
return crypt.crypt(password, salt)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
김치
|
||||
करी
|
||||
hamburger
|
||||
café
|
||||
@@ -23,12 +23,16 @@ from azurelinuxagent.common.future import ustr
|
||||
import azurelinuxagent.common.utils.textutil as textutil
|
||||
from azurelinuxagent.common.utils.textutil import Version
|
||||
|
||||
|
||||
class TestTextUtil(AgentTestCase):
|
||||
def test_get_password_hash(self):
|
||||
password_hash = textutil.gen_password_hash("asdf", 6, 10)
|
||||
self.assertNotEquals(None, password_hash)
|
||||
password_hash = textutil.gen_password_hash("asdf", 6, 0)
|
||||
self.assertNotEquals(None, password_hash)
|
||||
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_passwords.txt'), 'rb') as in_file:
|
||||
for data in in_file:
|
||||
# Remove bom on bytes data before it is converted into string.
|
||||
data = textutil.remove_bom(data)
|
||||
data = ustr(data, encoding='utf-8')
|
||||
password_hash = textutil.gen_password_hash(data, 6, 10)
|
||||
self.assertNotEquals(None, password_hash)
|
||||
|
||||
def test_remove_bom(self):
|
||||
#Test bom could be removed
|
||||
|
||||
Reference in New Issue
Block a user