Strip whitespace from admin passwords
While admin passwords are discouraged, they are used by some users and using a file to import into the config option may include new line characters. Strip the white space from the admin password to prevent confusion for users. Change-Id: I986b10e960153daed9d0d0cbf81d9c9e918a2150 Closes-Bug: #1895004
This commit is contained in:
parent
3643aa963c
commit
7f0317313f
@ -1467,8 +1467,10 @@ def store_data(backing_file, data):
|
||||
|
||||
def get_admin_passwd(user=None):
|
||||
passwd = config("admin-password")
|
||||
if passwd and passwd.lower() != "none":
|
||||
return passwd
|
||||
if passwd:
|
||||
passwd = passwd.strip()
|
||||
if passwd.lower() != "none":
|
||||
return passwd
|
||||
|
||||
if user is None:
|
||||
user = config('admin-user')
|
||||
|
@ -1138,6 +1138,10 @@ class TestKeystoneUtils(CharmTestCase):
|
||||
def test_get_admin_passwd_pwd_set(self):
|
||||
self.test_config.set('admin-password', 'supersecret')
|
||||
self.assertEqual(utils.get_admin_passwd(), 'supersecret')
|
||||
self.test_config.set('admin-password', 'supersecret ')
|
||||
self.assertEqual(utils.get_admin_passwd(), 'supersecret')
|
||||
self.test_config.set('admin-password', 'supersecret\n')
|
||||
self.assertEqual(utils.get_admin_passwd(), 'supersecret')
|
||||
|
||||
@patch.object(utils, 'is_leader')
|
||||
@patch.object(utils, 'leader_get')
|
||||
|
Loading…
x
Reference in New Issue
Block a user