From b2d4cc24446c12191384ff67bbc978fa8000765f Mon Sep 17 00:00:00 2001 From: Simandan Andrei Cristian Date: Fri, 5 Oct 2018 14:26:00 +0300 Subject: [PATCH 1/6] Fix for #261 --- atest/login.robot | 9 +++++++-- src/SSHLibrary/abstractclient.py | 8 ++++---- src/SSHLibrary/javaclient.py | 4 ++-- src/SSHLibrary/pythonclient.py | 4 ++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/atest/login.robot b/atest/login.robot index b3bfdfdd8..2930adfe7 100644 --- a/atest/login.robot +++ b/atest/login.robot @@ -11,6 +11,7 @@ ${KEY} ${KEY DIR}${/}id_rsa ${INVALID USERNAME} invalidusername ${INVALID PASSWORD} invalidpassword ${INVALID KEY} ${KEY DIR}${/}id_rsa_invalid +${PASSPHRASE} ${EMPTY} *** Test Cases *** Login With Valid Username And Password @@ -21,17 +22,21 @@ Login With Invalid Username Or Password Run Keyword And Expect Error Authentication failed for user '${INVALID USERNAME}'. ... Login ${INVALID USERNAME} ${PASSWORD} -Login With Public Key When Valid Username And Key +Login With Public Key When No Passphrase Provided [Setup] Open Connection ${HOST} prompt=${PROMPT} Login With Public Key ${KEY USERNAME} ${KEY} +Login With Public Key When Valid Credentials + [Setup] Open Connection ${HOST} prompt=${PROMPT} + Login With Public Key ${KEY USERNAME} ${KEY} ${PASSPHRASE} + Login With Public Key When Invalid Username Run Keyword And Expect Error Login with public key failed for user '${INVALID USERNAME}'. ... Login With Public Key ${INVALID USERNAME} ${KEY} Login With Public Key When Invalid Key Run Keyword And Expect Error Login with public key failed for user '${KEY USERNAME}'. - ... Login With Public Key ${KEY USERNAME} ${INVALID KEY} + ... Login With Public Key ${KEY USERNAME} ${INVALID KEY} ${PASSPHRASE} Login With Public Key When Non-Existing Key Run Keyword And Expect Error Given key file 'not_existing_key' does not exist. diff --git a/src/SSHLibrary/abstractclient.py b/src/SSHLibrary/abstractclient.py index 484bce41c..aca0415bb 100644 --- a/src/SSHLibrary/abstractclient.py +++ b/src/SSHLibrary/abstractclient.py @@ -170,7 +170,7 @@ def _read_login_output(self, delay): return self.read_until_regexp(self.config.prompt[7:]) return self.read_until_prompt() - def login_with_public_key(self, username, keyfile, password, allow_agent=False, + def login_with_public_key(self, username, keyfile, passphrase, allow_agent=False, look_for_keys=False, delay=None): """Logs into the remote host using the public key authentication. @@ -184,7 +184,7 @@ def login_with_public_key(self, username, keyfile, password, allow_agent=False, :param str keyfile: Path to the valid OpenSSH private key file. - :param str password: Password (if needed) for unlocking the `keyfile`. + :param str passphrase: Password (if needed) for unlocking the `keyfile`. :param boolean allow_agent: enables the connection to the SSH agent. This option does not work when using Jython. @@ -204,7 +204,7 @@ def login_with_public_key(self, username, keyfile, password, allow_agent=False, username = self._encode(username) self._verify_key_file(keyfile) try: - self._login_with_public_key(username, keyfile, password, + self._login_with_public_key(username, keyfile, passphrase, allow_agent, look_for_keys) except SSHClientException: raise SSHClientException("Login with public key failed for user " @@ -220,7 +220,7 @@ def _verify_key_file(self, keyfile): except IOError: raise SSHClientException("Could not read key file '%s'." % keyfile) - def _login_with_public_key(self, username, keyfile, password, + def _login_with_public_key(self, username, keyfile, passphrase, allow_agent, look_for_keys): raise NotImplementedError diff --git a/src/SSHLibrary/javaclient.py b/src/SSHLibrary/javaclient.py index 7ba41021f..2af8924d2 100644 --- a/src/SSHLibrary/javaclient.py +++ b/src/SSHLibrary/javaclient.py @@ -50,7 +50,7 @@ def _login(self, username, password, look_for_keys='ignored'): if not self.client.authenticateWithPassword(username, password): raise SSHClientException - def _login_with_public_key(self, username, key_file, password, + def _login_with_public_key(self, username, key_file, passphrase, allow_agent='ignored', look_for_keys='ignored'): if allow_agent or look_for_keys: raise JavaSSHClientException("Arguments 'allow_agent' and " @@ -58,7 +58,7 @@ def _login_with_public_key(self, username, key_file, password, try: success = self.client.authenticateWithPublicKey(username, File(key_file), - password) + passphrase) if not success: raise SSHClientException except IOError: diff --git a/src/SSHLibrary/pythonclient.py b/src/SSHLibrary/pythonclient.py index 2b93d4147..8dd260eaf 100644 --- a/src/SSHLibrary/pythonclient.py +++ b/src/SSHLibrary/pythonclient.py @@ -75,10 +75,10 @@ def _login(self, username, password, look_for_keys=False): except paramiko.AuthenticationException: raise SSHClientException - def _login_with_public_key(self, username, key_file, password, allow_agent, look_for_keys): + def _login_with_public_key(self, username, key_file, passphrase, allow_agent, look_for_keys): try: self.client.connect(self.config.host, self.config.port, username, - password, key_filename=key_file, + passphrase, key_filename=key_file, allow_agent=allow_agent, look_for_keys=look_for_keys, timeout=float(self.config.timeout)) From fda4b01c2ec4c685db46e79cfdabe4d73bccb5b0 Mon Sep 17 00:00:00 2001 From: Simandan Andrei Cristian Date: Mon, 8 Oct 2018 11:08:58 +0300 Subject: [PATCH 2/6] Changed parameters and error message --- atest/login.robot | 10 +++++++--- src/SSHLibrary/abstractclient.py | 2 +- src/SSHLibrary/library.py | 6 +++--- src/SSHLibrary/pythonclient.py | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/atest/login.robot b/atest/login.robot index 2930adfe7..48103f5a9 100644 --- a/atest/login.robot +++ b/atest/login.robot @@ -22,7 +22,7 @@ Login With Invalid Username Or Password Run Keyword And Expect Error Authentication failed for user '${INVALID USERNAME}'. ... Login ${INVALID USERNAME} ${PASSWORD} -Login With Public Key When No Passphrase Provided +Login With Public Key When Valid Username And Key [Setup] Open Connection ${HOST} prompt=${PROMPT} Login With Public Key ${KEY USERNAME} ${KEY} @@ -31,13 +31,17 @@ Login With Public Key When Valid Credentials Login With Public Key ${KEY USERNAME} ${KEY} ${PASSPHRASE} Login With Public Key When Invalid Username - Run Keyword And Expect Error Login with public key failed for user '${INVALID USERNAME}'. + Run Keyword And Expect Error SSHException: not a valid OPENSSH private key file ... Login With Public Key ${INVALID USERNAME} ${KEY} Login With Public Key When Invalid Key - Run Keyword And Expect Error Login with public key failed for user '${KEY USERNAME}'. + Run Keyword And Expect Error SSHException: not a valid OPENSSH private key file ... Login With Public Key ${KEY USERNAME} ${INVALID KEY} ${PASSPHRASE} +Login With Public Key When Invalid Key And Valid Password + Run Keyword And Expect Error SSHException: not a valid OPENSSH private key file + ... Login With Public Key ${USERNAME} ${INVALID KEY} ${PASSWORD} + Login With Public Key When Non-Existing Key Run Keyword And Expect Error Given key file 'not_existing_key' does not exist. ... Login With Public Key ${KEY USERNAME} not_existing_key diff --git a/src/SSHLibrary/abstractclient.py b/src/SSHLibrary/abstractclient.py index aca0415bb..0f73528b0 100644 --- a/src/SSHLibrary/abstractclient.py +++ b/src/SSHLibrary/abstractclient.py @@ -184,7 +184,7 @@ def login_with_public_key(self, username, keyfile, passphrase, allow_agent=False :param str keyfile: Path to the valid OpenSSH private key file. - :param str passphrase: Password (if needed) for unlocking the `keyfile`. + :param str passphrase: Passphrase (if needed) for unlocking the `keyfile`. :param boolean allow_agent: enables the connection to the SSH agent. This option does not work when using Jython. diff --git a/src/SSHLibrary/library.py b/src/SSHLibrary/library.py index 582d71f51..9f8c3c606 100644 --- a/src/SSHLibrary/library.py +++ b/src/SSHLibrary/library.py @@ -841,7 +841,7 @@ def login(self, username, password, delay='0.5 seconds'): """ return self._login(self.current.login, username, password, delay) - def login_with_public_key(self, username, keyfile, password='', + def login_with_public_key(self, username, keyfile, passphrase='', allow_agent=False, look_for_keys=False, delay='0.5 seconds'): """Logs into the SSH server using key-based authentication. @@ -853,7 +853,7 @@ def login_with_public_key(self, username, keyfile, password='', ``keyfile`` is a path to a valid OpenSSH private key file on the local filesystem. - ``password`` is used to unlock the ``keyfile`` if needed. + ``passphrase`` is used to unlock the ``keyfile`` if needed. This keyword reads, returns and logs the server output after logging in. If the `prompt` is set, everything until the prompt is read. @@ -881,7 +881,7 @@ def login_with_public_key(self, username, keyfile, password='', *Note:* ``allow_agent`` and ``look_for_keys`` do not work when using Jython. """ return self._login(self.current.login_with_public_key, username, - keyfile, password, is_truthy(allow_agent), + keyfile, passphrase, is_truthy(allow_agent), is_truthy(look_for_keys), delay) def _login(self, login_method, username, *args): diff --git a/src/SSHLibrary/pythonclient.py b/src/SSHLibrary/pythonclient.py index 8dd260eaf..8cd7eb6be 100644 --- a/src/SSHLibrary/pythonclient.py +++ b/src/SSHLibrary/pythonclient.py @@ -78,7 +78,7 @@ def _login(self, username, password, look_for_keys=False): def _login_with_public_key(self, username, key_file, passphrase, allow_agent, look_for_keys): try: self.client.connect(self.config.host, self.config.port, username, - passphrase, key_filename=key_file, + passphrase=passphrase, key_filename=key_file, allow_agent=allow_agent, look_for_keys=look_for_keys, timeout=float(self.config.timeout)) From c3ee58e6a3f99aac6f540d44d13fc142e78987a0 Mon Sep 17 00:00:00 2001 From: Simandan Andrei Cristian Date: Mon, 8 Oct 2018 14:29:56 +0300 Subject: [PATCH 3/6] Fixed tests and generated error messages --- atest/login.robot | 8 ++++---- src/SSHLibrary/pythonclient.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/atest/login.robot b/atest/login.robot index 48103f5a9..4f61c07dc 100644 --- a/atest/login.robot +++ b/atest/login.robot @@ -31,15 +31,15 @@ Login With Public Key When Valid Credentials Login With Public Key ${KEY USERNAME} ${KEY} ${PASSPHRASE} Login With Public Key When Invalid Username - Run Keyword And Expect Error SSHException: not a valid OPENSSH private key file + Run Keyword And Expect Error Login with public key failed for user 'invalidusername'. ... Login With Public Key ${INVALID USERNAME} ${KEY} Login With Public Key When Invalid Key - Run Keyword And Expect Error SSHException: not a valid OPENSSH private key file - ... Login With Public Key ${KEY USERNAME} ${INVALID KEY} ${PASSPHRASE} + Run Keyword And Expect Error Login with public key failed for user 'testkey'. + ... Login With Public Key ${KEY USERNAME} ${INVALID KEY} Login With Public Key When Invalid Key And Valid Password - Run Keyword And Expect Error SSHException: not a valid OPENSSH private key file + Run Keyword And Expect Error Login with public key failed for user 'test'. ... Login With Public Key ${USERNAME} ${INVALID KEY} ${PASSWORD} Login With Public Key When Non-Existing Key diff --git a/src/SSHLibrary/pythonclient.py b/src/SSHLibrary/pythonclient.py index 8cd7eb6be..81b93a88a 100644 --- a/src/SSHLibrary/pythonclient.py +++ b/src/SSHLibrary/pythonclient.py @@ -82,7 +82,7 @@ def _login_with_public_key(self, username, key_file, passphrase, allow_agent, lo allow_agent=allow_agent, look_for_keys=look_for_keys, timeout=float(self.config.timeout)) - except paramiko.AuthenticationException: + except (paramiko.AuthenticationException, paramiko.SSHException): raise SSHClientException def get_banner(self): From c99305a9dc5d8e74c56fab2b340aa639b7d9cc74 Mon Sep 17 00:00:00 2001 From: Simandan Andrei Cristian Date: Mon, 8 Oct 2018 14:32:49 +0300 Subject: [PATCH 4/6] Fixed tests name --- atest/login.robot | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/atest/login.robot b/atest/login.robot index 4f61c07dc..2774db852 100644 --- a/atest/login.robot +++ b/atest/login.robot @@ -31,15 +31,15 @@ Login With Public Key When Valid Credentials Login With Public Key ${KEY USERNAME} ${KEY} ${PASSPHRASE} Login With Public Key When Invalid Username - Run Keyword And Expect Error Login with public key failed for user 'invalidusername'. + Run Keyword And Expect Error Login with public key failed for user '${INVALID USERNAME}'. ... Login With Public Key ${INVALID USERNAME} ${KEY} Login With Public Key When Invalid Key - Run Keyword And Expect Error Login with public key failed for user 'testkey'. + Run Keyword And Expect Error Login with public key failed for user '${KEY USERNAME}'. ... Login With Public Key ${KEY USERNAME} ${INVALID KEY} Login With Public Key When Invalid Key And Valid Password - Run Keyword And Expect Error Login with public key failed for user 'test'. + Run Keyword And Expect Error Login with public key failed for user '${USERNAME}'. ... Login With Public Key ${USERNAME} ${INVALID KEY} ${PASSWORD} Login With Public Key When Non-Existing Key From 7fa1a1ccb5808b347677479ecb146c3db2a69792 Mon Sep 17 00:00:00 2001 From: Simandan Andrei Cristian Date: Tue, 9 Oct 2018 10:47:24 +0300 Subject: [PATCH 5/6] fixed wrong parameter --- src/SSHLibrary/library.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SSHLibrary/library.py b/src/SSHLibrary/library.py index 9f8c3c606..4b4253a66 100644 --- a/src/SSHLibrary/library.py +++ b/src/SSHLibrary/library.py @@ -841,7 +841,7 @@ def login(self, username, password, delay='0.5 seconds'): """ return self._login(self.current.login, username, password, delay) - def login_with_public_key(self, username, keyfile, passphrase='', + def login_with_public_key(self, username, keyfile, passphrase, allow_agent=False, look_for_keys=False, delay='0.5 seconds'): """Logs into the SSH server using key-based authentication. From 66321899979975ec7b822415de98f52d598d1fe5 Mon Sep 17 00:00:00 2001 From: Simandan Andrei Cristian Date: Tue, 9 Oct 2018 11:53:47 +0300 Subject: [PATCH 6/6] Revert "fixed wrong parameter" This reverts commit 7fa1a1ccb5808b347677479ecb146c3db2a69792. --- src/SSHLibrary/library.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SSHLibrary/library.py b/src/SSHLibrary/library.py index 4b4253a66..9f8c3c606 100644 --- a/src/SSHLibrary/library.py +++ b/src/SSHLibrary/library.py @@ -841,7 +841,7 @@ def login(self, username, password, delay='0.5 seconds'): """ return self._login(self.current.login, username, password, delay) - def login_with_public_key(self, username, keyfile, passphrase, + def login_with_public_key(self, username, keyfile, passphrase='', allow_agent=False, look_for_keys=False, delay='0.5 seconds'): """Logs into the SSH server using key-based authentication.