Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
y0urself committed Apr 26, 2023
1 parent ea862ad commit 62857d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions gvm/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class GvmConnection(XmlReader):

def __init__(self, timeout: Optional[int] = DEFAULT_TIMEOUT):
self._socket = None
self._timeout = timeout if timeout else DEFAULT_TIMEOUT
self._timeout = timeout if timeout is not None else DEFAULT_TIMEOUT

def _read(self) -> bytes:
return self._socket.recv(BUF_SIZE)
Expand Down Expand Up @@ -191,7 +191,7 @@ def __init__(
username: Optional[str] = DEFAULT_SSH_USERNAME,
password: Optional[str] = DEFAULT_SSH_PASSWORD,
known_hosts_file: Optional[str] = None,
ci: Optional[bool] = None,
auto_accept_host: Optional[bool] = None,
):
super().__init__(timeout=timeout)

Expand All @@ -208,7 +208,7 @@ def __init__(
if known_hosts_file is not None
else Path.home() / DEFAULT_KNOWN_HOSTS_FILE
)
self.ci = ci
self.auto_accept_host = auto_accept_host

def _send_all(self, data) -> int:
"""Returns the sum of sent bytes if success"""
Expand All @@ -225,7 +225,7 @@ def _send_all(self, data) -> int:
data = data[sent:]
return sent_sum

def _ci_auto_connect(
def _auto_accept_host(
self, hostkeys: paramiko.HostKeys, key: paramiko.PKey
) -> None:
if self.port == DEFAULT_SSH_PORT:
Expand Down Expand Up @@ -375,8 +375,8 @@ def _ssh_authentication(self) -> None:
# Key not found, so connect to remote and fetch the key
# with the paramiko Transport protocol
key = self._get_remote_host_key()
if self.ci:
self._ci_auto_connect(hostkeys=hostkeys, key=key)
if self.auto_accept_host:
self._auto_accept_host(hostkeys=hostkeys, key=key)
else:
self._ssh_authentication_input_loop(hostkeys=hostkeys, key=key)

Expand Down
8 changes: 4 additions & 4 deletions tests/connections/test_ssh_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def test_connect_error(self):
with self.assertRaises(GvmError, msg="SSH Connection failed"):
ssh_connection.connect()

def test_connect_error_ci(self):
def test_connect_error_auto_accept_host(self):
ssh_connection = SSHConnection(
known_hosts_file=self.known_hosts_file, ci=True
known_hosts_file=self.known_hosts_file, auto_accept_host=True
)
with self.assertRaises(GvmError, msg="SSH Connection failed"):
ssh_connection.connect()
Expand All @@ -98,12 +98,12 @@ def test_connect(self):
self.assertEqual(ssh_connection._stderr, "c")
ssh_connection.disconnect()

def test_connect_ci(self):
def test_connect_auto_accept_host(self):
with patch("paramiko.SSHClient") as SSHClientMock:
client_mock = SSHClientMock.return_value
client_mock.exec_command.return_value = ["a", "b", "c"]
ssh_connection = SSHConnection(
known_hosts_file=self.known_hosts_file, ci=True
known_hosts_file=self.known_hosts_file, auto_accept_host=True
)

ssh_connection.connect()
Expand Down

0 comments on commit 62857d7

Please sign in to comment.