Skip to content

Commit

Permalink
authentication: Added function parameters log and opts to ssh.auth.pa…
Browse files Browse the repository at this point in the history
…ssword

- Some tests need to assert the ssh stdout that is silenced by expect
- Adding the ability to specify custom options to ssh auth
  • Loading branch information
Dan Lavu committed Jan 21, 2024
1 parent 379e63c commit ffee221
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions sssd_test_framework/utils/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,13 @@ def password(self, username: str, password: str) -> bool:
"""
Call ``su - $username`` and authenticate the user with password.
:param name: User name.
:type name: str
:param username: Username.
:type username: str
:param password: User password.
:type password: str
:return: True if authentication was successful, False otherwise.
:rtype: bool
"""

result = self.host.ssh.expect_nobody(
rf"""
# It takes some time to get authentication failure
Expand Down Expand Up @@ -236,8 +235,8 @@ def password_expired(self, username: str, password: str, new_password: str) -> b
Call ``su - $username`` and authenticate the user with password, expect
that the password is expired and change it to the new password.
:param username: User name.
:type name: str
:param username: Username.
:type username: str
:param password: Old, expired user password.
:type password: str
:param new_password: New user password.
Expand Down Expand Up @@ -305,7 +304,7 @@ def passkey(self, username: str, *, pin: str | int, device: str, ioctl: str, scr
"""
Call ``su - $username`` and authenticate the user with passkey.
:param username: User name
:param username: Username
:type username: str
:param pin: Passkey PIN.
:type pin: str | int
Expand Down Expand Up @@ -413,23 +412,30 @@ 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(self, username: str, password: str, log: str = "0", opts: str | None = None) -> bool:
"""
SSH to the remote host and authenticate the user with password.
:param name: User name.
:type name: str
:param username: Username.
:type username: str
:param password: User password.
:type password: str
:param log: Logs SSH session to stdout.
:type log: str, defaults to "0" no logging, "1" to log
:param opts: SSH client options.
:type opts: str | None, defaults to None
:return: True if authentication was successful, False otherwise.
:rtype: bool
"""
if opts is not None:
self.opts = f"{self.opts} + {opts}"

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 = {log}
spawn ssh {self.opts} \
-o PreferredAuthentications=password \
Expand Down Expand Up @@ -465,8 +471,8 @@ def password_expired(self, username: str, password: str, new_password: str) -> b
SSH to the remote host and authenticate the user with password, expect
that the password is expired and change it to the new password.
:param username: User name.
:type name: str
:param username: Username.
:type username: str
:param password: Old, expired user password.
:type password: str
:param new_password: New user password.
Expand Down

0 comments on commit ffee221

Please sign in to comment.