Skip to content

Commit

Permalink
lint fixes, adding encoding to bytes calls, who camel cases in python?
Browse files Browse the repository at this point in the history
  • Loading branch information
byteskeptical committed Oct 27, 2024
1 parent e50cf79 commit f476eff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions sftpretty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def get_hostkey(self, host, port=22, salt=None):
raise an SSHException.
:param str host: *Required* - The Hostname or IP of the remote machine.
:param int port: *Default: 22* - SFTP server port of the remote machine.
:param int port: *Default: 22* - SFTP server port of remote machine.
:param str|None salt: *Default: None* - Salt to use when hashing
(must be 20 bytes long).
Expand All @@ -161,8 +161,8 @@ def get_hostkey(self, host, port=22, salt=None):
hashed_host = self.hostkeys.hash_host(host, salt=salt)
hashed_host_port = self.hostkeys.hash_host(host_port, salt=salt)
kval = (
self.hostkeys.lookup(hashed_host)
or self.hostkeys.lookup(hashed_host_port)
self.hostkeys.lookup(hashed_host) or
self.hostkeys.lookup(hashed_host_port)
)
if kval is None:
raise SSHException(f'No hostkey for host [{host}] found.')
Expand Down
12 changes: 6 additions & 6 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,38 +73,38 @@ def test_connection_with_known_host_entry(sftpserver):
knownhosts = Path('~/.ssh/known_hosts').expanduser()
knownhosts.parent.mkdir(exist_ok=True, mode=0o700)
knownhosts.touch(exist_ok=True, mode=0o644)
knownhosts.write_bytes(bytes(hostkey))
knownhosts.write_bytes(bytes(hostkey, 'utf-8'))
with sftpserver.serve_content(VFS):
with Connection(**conn(sftpserver)) as sftp:
assert sftp.listdir() == ['pub', 'read.me']


def test_connection_with_hashed_host(sftpserver):
'''connect to a public sftp server with hashed host entry'''
hashed_host = hostkeys.Hostkeys().hash_host(sftpserver.host)
hashed_host = hostkeys.HostKeys().hash_host(sftpserver.host)
hostkey = (f'{hashed_host} '
'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB0g3SG/bbyysJ7f0kqdoWMXh'
'HxxFR7aLJYNIHO/MtsD')
knownhosts = Path('~/.ssh/known_hosts').expanduser()
knownhosts.parent.mkdir(exist_ok=True, mode=0o700)
knownhosts.touch(exist_ok=True, mode=0o644)
knownhosts.write_bytes(bytes(hostkey))
knownhosts.write_bytes(bytes(hostkey, 'utf-8'))
with sftpserver.serve_content(VFS):
with Connection(**conn(sftpserver)) as sftp:
assert sftp.listdir() == ['pub', 'read.me']


def test_connection_with_hashed_host_non_default_port(ndp_sftpserver):
'''connect to a public sftp server with hashed host entry on non-default port'''
'''connect to a public sftp server on non-default port with hashed host'''
host_port = f'[{ndp_sftpserver.host}]:{ndp_sftpserver.port}'
hashed_host_port = hostkeys.Hostkeys().hash_host(host_port)
hashed_host_port = hostkeys.HostKeys().hash_host(host_port)
hostkey = (f'{hashed_host_port} '
'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIB0g3SG/bbyysJ7f0kqdoWMXh'
'HxxFR7aLJYNIHO/MtsD')
knownhosts = Path('~/.ssh/known_hosts').expanduser()
knownhosts.parent.mkdir(exist_ok=True, mode=0o700)
knownhosts.touch(exist_ok=True, mode=0o644)
knownhosts.write_bytes(bytes(hostkey))
knownhosts.write_bytes(bytes(hostkey, 'utf-8'))
with ndp_sftpserver.serve_content(VFS):
non_conn = conn(ndp_sftpserver)
non_conn['port'] = ndp_sftpserver.port
Expand Down

0 comments on commit f476eff

Please sign in to comment.