Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #261 #267

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions atest/login.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,6 +26,10 @@ Login With Public Key When Valid Username And Key
[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}
Expand All @@ -33,6 +38,10 @@ 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 When Invalid Key And Valid Password
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
Run Keyword And Expect Error Given key file 'not_existing_key' does not exist.
... Login With Public Key ${KEY USERNAME} not_existing_key
Expand Down
8 changes: 4 additions & 4 deletions src/SSHLibrary/abstractclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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: 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.
Expand All @@ -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 "
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/SSHLibrary/javaclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ 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 "
"'look_for_keys' do not work with Jython.")
try:
success = self.client.authenticateWithPublicKey(username,
File(key_file),
password)
passphrase)
if not success:
raise SSHClientException
except IOError:
Expand Down
6 changes: 3 additions & 3 deletions src/SSHLibrary/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions src/SSHLibrary/pythonclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ 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=passphrase, key_filename=key_file,
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):
Expand Down