Skip to content

Commit

Permalink
test: update to handle crypt not available
Browse files Browse the repository at this point in the history
crypt is not supported in 3.13 and newer. Update test using
crypt to work.
  • Loading branch information
rouilj committed Apr 20, 2024
1 parent b1c8e53 commit 16800af
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions test/test_hypothesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# ruff: noqa: I001 - yes I know I am using \ to continue the line...
from roundup.password import PasswordValueError, encodePassword, \
h64decode, h64encode

from roundup.password import crypt as crypt_method

def Identity(x):
return x
Expand Down Expand Up @@ -57,11 +57,15 @@ def test_h64encode_h64decode(self, s):
@settings(max_examples=_max_examples)
def test_encodePassword(self, password, scheme):

if scheme == "crypt" and password and "\x00" in password:
if scheme == "crypt" and password and "\x00" in password:
with self.assertRaises(ValueError) as e:
encodePassword(password, scheme)
self.assertEqual(e.exception.args[0],
"embedded null character")
if crypt_method:
self.assertEqual(e.exception.args[0],
"embedded null character")
else:
self.assertEqual(e.exception.args[0],
"Unsupported encryption scheme 'crypt'")
elif scheme == "plaintext":
if password is not None:
self.assertEqual(encodePassword(password, scheme), password)
Expand Down Expand Up @@ -90,7 +94,9 @@ def test_encodePassword(self, password, scheme):
# d41d8cd98f00b204e9800998ecf8427e'
self.assertRegex(pw, r"^[a-z0-9]{32}$")
elif scheme == "crypt":
# WqzFDzhi8MmoU
self.assertRegex(pw, r"^[A-Za-z0-9./]{13}$")
# crypt_method is None if crypt is unknown
if crypt_method:
# WqzFDzhi8MmoU
self.assertRegex(pw, r"^[A-Za-z0-9./]{13}$")
else:
self.assertFalse("Unknown scheme: %s, val: %s" % (scheme, pw))

0 comments on commit 16800af

Please sign in to comment.