Skip to content

Commit

Permalink
utils: added password_with_output to authentication.py to capture ssh…
Browse files Browse the repository at this point in the history
… output
  • Loading branch information
Dan Lavu committed Feb 15, 2024
1 parent 6e92e58 commit 89d3d82
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions sssd_test_framework/utils/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,23 +413,24 @@ def __init__(self, host: MultihostHost) -> None:
self.opts = "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
"""SSH CLI options."""

def password(self, username: str, password: str) -> bool:
def password_with_output(self, username: str, password: str) -> tuple[int, str, str]:
"""
SSH to the remote host and authenticate the user with password.
SSH to the remote host and authenticate the user with password and captures standard output and error.
:param username: Username.
:type username: str
:param password: User password.
:type password: str
:return: True if authentication was successful, False otherwise.
:rtype: bool
:return: Tuple containing [return code, standard out, standard error].
:rtype: Tuple[int, str, str]
"""

result = self.host.ssh.expect_nobody(
rf"""
# It takes some time to get authentication failure
set timeout {DEFAULT_AUTHENTICATION_TIMEOUT}
set prompt "\n.*\[#\$>\] $"
log_user 1
spawn ssh {self.opts} \
-o PreferredAuthentications=password \
Expand Down Expand Up @@ -458,7 +459,21 @@ def password(self, username: str, password: str) -> bool:
if result.rc > 200:
raise ExpectScriptError(result.rc)

return result.rc == 0
return result.rc, result.stdout, result.stderr

def password(self, username: str, password: str) -> bool:
"""
SSH to the remote host and authenticate the user with password.
:param username: Username.
:type username: str
:param password: User password.
:type password: str
:return: True if authentication was successful, False otherwise.
:rtype: bool
"""
rc, _, _ = self.password_with_output(username, password)
return rc == 0

def password_expired(self, username: str, password: str, new_password: str) -> bool:
"""
Expand Down

0 comments on commit 89d3d82

Please sign in to comment.