From ba487253bb91f42b6385c0194ee2ccc387d3c499 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 17 Apr 2023 12:56:37 -0400 Subject: password lookup, handle ident properly when saved (#80251) (#80310) * password lookup, handle ident properly when saved (#80251) * password lookup, handle ident properly when saved Currently we format and save ident when present but we didn't account for this when reading the saved file Also added some more robust error handling. (cherry picked from commit 0fd88717c953b92ed8a50495d55e630eb5d59166) * fix try block indent# https://chris.beams.io/posts/git-commit/ * clog (cherry picked from commit 97c8da77838e93b416c5e700abafa89a8383e950) * fix bad merge indentation --- test/units/plugins/lookup/test_password.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'test/units/plugins/lookup/test_password.py') diff --git a/test/units/plugins/lookup/test_password.py b/test/units/plugins/lookup/test_password.py index 15207b2f39..318bc10ba6 100644 --- a/test/units/plugins/lookup/test_password.py +++ b/test/units/plugins/lookup/test_password.py @@ -330,23 +330,34 @@ class TestRandomPassword(unittest.TestCase): class TestParseContent(unittest.TestCase): def test_empty_password_file(self): - plaintext_password, salt = password._parse_content(u'') + plaintext_password, salt, ident = password._parse_content(u'') self.assertEqual(plaintext_password, u'') self.assertEqual(salt, None) + self.assertEqual(ident, None) def test(self): expected_content = u'12345678' file_content = expected_content - plaintext_password, salt = password._parse_content(file_content) + plaintext_password, salt, ident = password._parse_content(file_content) self.assertEqual(plaintext_password, expected_content) self.assertEqual(salt, None) + self.assertEqual(ident, None) def test_with_salt(self): expected_content = u'12345678 salt=87654321' file_content = expected_content - plaintext_password, salt = password._parse_content(file_content) + plaintext_password, salt, ident = password._parse_content(file_content) self.assertEqual(plaintext_password, u'12345678') self.assertEqual(salt, u'87654321') + self.assertEqual(ident, None) + + def test_with_salt_and_ident(self): + expected_content = u'12345678 salt=87654321 ident=2a' + file_content = expected_content + plaintext_password, salt, ident = password._parse_content(file_content) + self.assertEqual(plaintext_password, u'12345678') + self.assertEqual(salt, u'87654321') + self.assertEqual(ident, u'2a') class TestFormatContent(unittest.TestCase): -- cgit v1.2.1