Mercurial > p > roundup > code
comparison test/test_hypothesis.py @ 7901:9ff94a2e8c82
test: update to handle crypt not available
crypt is not supported in 3.13 and newer. Update test using
crypt to work.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 20 Apr 2024 16:41:08 -0400 |
| parents | ce740d9a7d8d |
| children | 2c6d66819475 |
comparison
equal
deleted
inserted
replaced
| 7900:011941fcb598 | 7901:9ff94a2e8c82 |
|---|---|
| 10 | 10 |
| 11 from roundup.anypy.strings import b2s, s2b, s2u, u2s | 11 from roundup.anypy.strings import b2s, s2b, s2u, u2s |
| 12 # ruff: noqa: I001 - yes I know I am using \ to continue the line... | 12 # ruff: noqa: I001 - yes I know I am using \ to continue the line... |
| 13 from roundup.password import PasswordValueError, encodePassword, \ | 13 from roundup.password import PasswordValueError, encodePassword, \ |
| 14 h64decode, h64encode | 14 h64decode, h64encode |
| 15 | 15 from roundup.password import crypt as crypt_method |
| 16 | 16 |
| 17 def Identity(x): | 17 def Identity(x): |
| 18 return x | 18 return x |
| 19 | 19 |
| 20 | 20 |
| 55 "zot"))) | 55 "zot"))) |
| 56 @example("asd\x00df", "crypt") | 56 @example("asd\x00df", "crypt") |
| 57 @settings(max_examples=_max_examples) | 57 @settings(max_examples=_max_examples) |
| 58 def test_encodePassword(self, password, scheme): | 58 def test_encodePassword(self, password, scheme): |
| 59 | 59 |
| 60 if scheme == "crypt" and password and "\x00" in password: | 60 if scheme == "crypt" and password and "\x00" in password: |
| 61 with self.assertRaises(ValueError) as e: | 61 with self.assertRaises(ValueError) as e: |
| 62 encodePassword(password, scheme) | 62 encodePassword(password, scheme) |
| 63 self.assertEqual(e.exception.args[0], | 63 if crypt_method: |
| 64 "embedded null character") | 64 self.assertEqual(e.exception.args[0], |
| 65 "embedded null character") | |
| 66 else: | |
| 67 self.assertEqual(e.exception.args[0], | |
| 68 "Unsupported encryption scheme 'crypt'") | |
| 65 elif scheme == "plaintext": | 69 elif scheme == "plaintext": |
| 66 if password is not None: | 70 if password is not None: |
| 67 self.assertEqual(encodePassword(password, scheme), password) | 71 self.assertEqual(encodePassword(password, scheme), password) |
| 68 else: | 72 else: |
| 69 self.assertEqual(encodePassword(password, scheme), "") | 73 self.assertEqual(encodePassword(password, scheme), "") |
| 88 self.assertRegex(pw, r"^[a-z0-9]{40}$") | 92 self.assertRegex(pw, r"^[a-z0-9]{40}$") |
| 89 elif scheme == "MD5": | 93 elif scheme == "MD5": |
| 90 # d41d8cd98f00b204e9800998ecf8427e' | 94 # d41d8cd98f00b204e9800998ecf8427e' |
| 91 self.assertRegex(pw, r"^[a-z0-9]{32}$") | 95 self.assertRegex(pw, r"^[a-z0-9]{32}$") |
| 92 elif scheme == "crypt": | 96 elif scheme == "crypt": |
| 93 # WqzFDzhi8MmoU | 97 # crypt_method is None if crypt is unknown |
| 94 self.assertRegex(pw, r"^[A-Za-z0-9./]{13}$") | 98 if crypt_method: |
| 99 # WqzFDzhi8MmoU | |
| 100 self.assertRegex(pw, r"^[A-Za-z0-9./]{13}$") | |
| 95 else: | 101 else: |
| 96 self.assertFalse("Unknown scheme: %s, val: %s" % (scheme, pw)) | 102 self.assertFalse("Unknown scheme: %s, val: %s" % (scheme, pw)) |
