diff --git a/osc/conf.py b/osc/conf.py index 14e201a8..4cbfd9ea 100644 --- a/osc/conf.py +++ b/osc/conf.py @@ -119,6 +119,12 @@ class Password(collections.UserString): return f"{self.__str__():{format_spec}}" return super().__format__(format_spec) + def encode(self, *args, **kwargs): + if sys.version_info < (3, 8): + # avoid returning the Password object on python < 3.8 + return str(self).encode(*args, **kwargs) + return super().encode(*args, **kwargs) + HttpHeader = NewType("HttpHeader", Tuple[str, str]) diff --git a/tests/test_credentials.py b/tests/test_credentials.py new file mode 100644 index 00000000..fd5749f8 --- /dev/null +++ b/tests/test_credentials.py @@ -0,0 +1,17 @@ +import unittest + +import osc.conf +from osc.credentials import ObfuscatedConfigFileCredentialsManager + + +class TestObfuscatedConfigFileCredentialsManager(unittest.TestCase): + def test_decode_password(self): + # obfuscated "opensuse" + password_str = "QlpoOTFBWSZTWeTSblkAAAGBgAIBygAgADDACGNEHxaYXckU4UJDk0m5ZA==" + password = osc.conf.Password(password_str) + decoded = ObfuscatedConfigFileCredentialsManager.decode_password(password) + self.assertEqual(decoded, "opensuse") + + +if __name__ == "__main__": + unittest.main()