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

authentication: password change take retyped argument #49

Merged
merged 1 commit into from
Oct 2, 2023
Merged
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
17 changes: 13 additions & 4 deletions sssd_test_framework/utils/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,19 +940,27 @@ class PasswdUtils(MultihostUtility[MultihostHost]):
def __init__(self, host: MultihostHost):
super().__init__(host)

def password(self, user: str, password: str, new_password: str) -> bool:
def password(self, user: str, password: str, new_password: str, retyped: str | None = None) -> bool:
"""
Changing password as a given user.
@retyped is only used if the test needs to fail because the passwords don't match, otherwise it is redundant
:param user: Username.
:type name: str
:param password: Current password of user.
:type password: str
:param new_password: New password of user.
:type new_password: str
:param retyped: Retyped new password of user.
:type retyped: str | None, optional
:raises ExpectScriptError: If EOF or timeout occured.
:return: True if password change was successful, False otherwise.
:rtype: bool
"""
if retyped is None:
retyped = new_password

result = self.host.ssh.expect(
rf"""
set timeout {DEFAULT_AUTHENTICATION_TIMEOUT}
Expand All @@ -968,19 +976,21 @@ def password(self, user: str, password: str, new_password: str) -> bool:
expect {{
-nocase "New password:" {{send "{new_password}\n"}}
"Password change failed. Server message: Old password not accepted." {{exit 1}}
timeout {{puts "expect result: Unexpected output"; exit 201}}
eof {{puts "expect result: Unexpected end of file"; exit 202}}
}}
expect {{
-nocase "Retype new password:" {{send "{new_password}\n"}}
-nocase "Retype new password:" {{send "{retyped}\n"}}
timeout {{puts "expect result: Unexpected output"; exit 201}}
eof {{puts "expect result: Unexpected end of file"; exit 202}}
}}
expect {{
"passwd: all authentication tokens updated successfully." {{exit 0}}
"Password change failed." {{exit 200}}
"Sorry, passwords do not match." {{exit 1}}
"Password change failed." {{exit 1}}
timeout {{puts "expect result: Unexpected output"; exit 201}}
eof {{puts "expect result: Unexpected end of file"; exit 202}}
}}
Expand All @@ -991,7 +1001,6 @@ def password(self, user: str, password: str, new_password: str) -> bool:
)

if result.rc > 200:
assert result.stderr == result.stdout
raise ExpectScriptError(result.rc)

return result.rc == 0