fix wrong error raised when private key is missing or invalid - #80
fix wrong error raised when private key is missing or invalid#80shashfrankenstien wants to merge 11 commits into
Conversation
…otFoundError logging
…exist, make key type parsing a bit more robust
There was a problem hiding this comment.
I appreciate the approach but I think fixing the catching of the correct error is enough here. Too much hand holding can muddy the code base without any real distinction in the outcome for a user that provides garbage inputs. Falling into the trap of checking or limiting the data types of user input is a slippery slope, at least in the python context.
…exist, make key type parsing a bit more robust
|
Ah! I was looking into your comments, but I see now you have removed the tests I added and fixed my mistake. I would recommend the below check so that paths built with pathlib will also work -
Also, I would recommend adding a connection test with PKey object since it is supported. It would have helped me catch my mistake Let me know if you'd like me to make these changes |
…ile type private key path. Adding Path to private key file resolution if block
|
Adding Path to the if block for file path resolution is fine and has been pushed. Pretty much all tests (except password specific ones) use private key authentication by default. I think the confusion is that |
…acts in the Path.home() or the user running tests that weren't been cleaned either up after. Reworking the symlink normalization test and adding one for a dangling target as well. To these means adding a remote_rmdir and new fixture function to handle remote tmp directory creation and clean-up.
I've added the required PASSWORD and PRIVATE_KEY variables to my fork. I couldn't figure this part out initially. So I ended up making a branch where I removed secret files and changed the workflow to dynamically create fresh key files and run the full CI on all platforms. If this is something that might be good to contribute, please let me know. I'd be glad to clean it up and send over a PR for your review |
I was thinking of something like this to pass an actual PKey object to def test_connection_good_pkey_obj(sftpserver):
'''attempt connection using `paramiko.pkey.PKey` object'''
copts = conn(sftpserver)
pkey = Ed25519Key(
filename=copts['private_key'],
password=copts['private_key_pass'])
del copts['private_key_pass']
copts['private_key'] = pkey
with sftpserver.serve_content(VFS):
with Connection(**copts) as sftp:
sftp.listdir() |
…import in truncate test file
|
What new code path is being tested that isn't already covered by every other non-password test? Your manually doing what happens in the |
…vate key path tests meant the private key value in copts wasn't being set correctly, doh
|
On that note could you please add the aforementioned secrets to your fork so the Linux and Windows test can properly run. |
In the
Connectionclass, if the private key file is not inkey_types, or if the file path provided doesn't exist, it raisesThis is because
key.from_private_key_fileis called in afinallyblock that will execute regardless of whether the try succeeds or fails. The correct branch to use iselse.Additionally,
self._transport.auth_publickeyandself._transport.auth_passwordwere being called even whenpasswordand/orprivate_keyinputs were not strings. This PR fixes this and raisesCredentialExceptionAdded required tests!