Skip to content

Commit

Permalink
Merge pull request #1471 from dmach/Password.encode
Browse files Browse the repository at this point in the history
Fix Password.encode() on python < 3.8
  • Loading branch information
dmach authored Jan 23, 2024
2 parents 3d7f79b + 0413179 commit 0e6117a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions osc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ def __format__(self, format_spec):
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])

Expand Down
17 changes: 17 additions & 0 deletions tests/test_credentials.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 0e6117a

Please sign in to comment.