mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Check for all non-word when calling secure_password
This commit is contained in:
parent
bd02ea6c94
commit
09ff8679b9
@ -54,7 +54,7 @@ def secure_password(length=20, use_random=True):
|
|||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
continue
|
continue
|
||||||
pw += re.sub(
|
pw += re.sub(
|
||||||
salt.utils.stringutils.to_str(r'\W'),
|
salt.utils.stringutils.to_str(r'[\W_]'),
|
||||||
str(), # future lint: disable=blacklisted-function
|
str(), # future lint: disable=blacklisted-function
|
||||||
char
|
char
|
||||||
)
|
)
|
||||||
|
43
tests/unit/utils/test_pycrypto.py
Normal file
43
tests/unit/utils/test_pycrypto.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Import python libs
|
||||||
|
from __future__ import absolute_import, print_function, unicode_literals
|
||||||
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
|
# Import Salt Libs
|
||||||
|
import salt.utils.pycrypto
|
||||||
|
|
||||||
|
# Import Salt Testing Libs
|
||||||
|
from tests.support.unit import TestCase
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class PycryptoTestCase(TestCase):
|
||||||
|
'''
|
||||||
|
TestCase for salt.utils.pycrypto module
|
||||||
|
'''
|
||||||
|
|
||||||
|
def test_gen_hash(self):
|
||||||
|
'''
|
||||||
|
Test gen_hash
|
||||||
|
'''
|
||||||
|
passwd = 'test_password'
|
||||||
|
ret = salt.utils.pycrypto.gen_hash(password=passwd)
|
||||||
|
self.assertTrue(ret.startswith('$6$'))
|
||||||
|
|
||||||
|
ret = salt.utils.pycrypto.gen_hash(password=passwd, algorithm='md5')
|
||||||
|
self.assertTrue(ret.startswith('$1$'))
|
||||||
|
|
||||||
|
ret = salt.utils.pycrypto.gen_hash(password=passwd, algorithm='sha256')
|
||||||
|
self.assertTrue(ret.startswith('$5$'))
|
||||||
|
|
||||||
|
def test_secure_password(self):
|
||||||
|
'''
|
||||||
|
test secure_password
|
||||||
|
'''
|
||||||
|
ret = salt.utils.pycrypto.secure_password()
|
||||||
|
check = re.compile(r'[!@#$%^&*()_=+]')
|
||||||
|
assert check.search(ret) is None
|
||||||
|
assert ret
|
Loading…
Reference in New Issue
Block a user