fix not clear cause for invalid username

- add a message saying the reason for the value error exception
 - add a unit test to validate the expected message

Change-Id: I1d6cc0faa3a43852c46089e509d48cc3ee9f9cf8
Closes-Bug: #1911811
This commit is contained in:
Tiago Primini 2021-04-21 17:39:53 -03:00 committed by Tim Burke
parent c9b5d44e9e
commit 717d21ccbd
2 changed files with 13 additions and 1 deletions

View File

@ -232,7 +232,11 @@ class TempAuth(object):
self.users = {}
for conf_key in conf:
if conf_key.startswith(('user_', 'user64_')):
account, username = conf_key.split('_', 1)[1].split('_')
try:
account, username = conf_key.split('_', 1)[1].split('_')
except ValueError:
raise ValueError("key %s was provided in an "
"invalid format" % conf_key)
if conf_key.startswith('user64_'):
# Because trailing equal signs would screw up config file
# parsing, we auto-pad with '=' chars.

View File

@ -1246,6 +1246,14 @@ class TestParseUserCreation(unittest.TestCase):
'user_admin_admin': 'admin .admin .reseller_admin',
}), FakeApp())
def test_account_with_no_user(self):
expected_msg = 'key user_testtester was provided in an invalid format'
with self.assertRaises(ValueError) as ctx:
auth.filter_factory({
'user_testtester': 'testing',
})(FakeApp())
self.assertEqual(str(ctx.exception), expected_msg)
class TestAccountAcls(unittest.TestCase):
"""