1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-09-20 01:06:17 +02:00

Fix Password.encode() on python < 3.8

This commit is contained in:
Daniel Mach 2024-01-22 16:28:28 +01:00
parent 3d7f79b706
commit 0413179709
2 changed files with 23 additions and 0 deletions

View File

@ -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])

17
tests/test_credentials.py Normal file
View File

@ -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()