diff options
author | Jeff Forcier <jeff@bitprophet.org> | 2023-05-24 21:53:27 -0400 |
---|---|---|
committer | Jeff Forcier <jeff@bitprophet.org> | 2023-05-24 21:54:02 -0400 |
commit | d9f8a3502f17c5aef0953466699d07cba94ce324 (patch) | |
tree | 2372a369b90e2ccc9b84d1095740f1b71e77e02f /tests | |
parent | 8127be0f8ba16e5e4532e4b8e39d393e2048378e (diff) |
Test PKey.from_path's use of expanduser
This blows up poorly when expanduser is not in use, but eh.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/pkey.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/pkey.py b/tests/pkey.py index 25202a06..3a1ee5ca 100644 --- a/tests/pkey.py +++ b/tests/pkey.py @@ -1,3 +1,6 @@ +from pathlib import Path +from unittest.mock import patch, call + from pytest import raises from cryptography.hazmat.primitives.asymmetric.ed448 import Ed448PrivateKey @@ -28,6 +31,21 @@ class PKey_: key = PKey.from_path(str(_support("rsa.key"))) assert isinstance(key, RSAKey) + @patch("paramiko.pkey.Path") + def expands_user(self, mPath): + # real key for guts that want a real key format + mykey = Path(_support("rsa.key")) + pathy = mPath.return_value.expanduser.return_value + # read_bytes for cryptography.io's loaders + pathy.read_bytes.return_value = mykey.read_bytes() + # open() for our own class loader + pathy.open.return_value = mykey.open() + # fake out exists() to avoid attempts to load cert + pathy.exists.return_value = False + PKey.from_path("whatever") # we're not testing expanduser itself + # Both key and cert paths + mPath.return_value.expanduser.assert_has_calls([call(), call()]) + def raises_UnknownKeyType_for_unknown_types(self): # I.e. a real, becomes a useful object via cryptography.io, key # class that we do NOT support. Chose Ed448 randomly as OpenSSH |