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

NAS-130433 / 24.10 / Audit user password reset #14135

Merged
merged 3 commits into from
Aug 5, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/middlewared/middlewared/plugins/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ def update_sshpubkey(self, homedir, user, group):
Str('username', required=True),
Password('old_password', default=None),
Password('new_password', required=True),
))
), audit='Set account password', audit_extended=lambda data: data['username'])
@pass_app(require=True)
async def set_password(self, app, data):
"""
Expand Down
19 changes: 16 additions & 3 deletions tests/api2/test_password_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from middlewared.test.integration.assets.account import user
from middlewared.test.integration.assets.account import unprivileged_user
from middlewared.test.integration.utils import call, client
from middlewared.test.integration.utils.audit import expect_audit_method_calls


TEST_USERNAME = 'testpasswduser'
Expand All @@ -17,6 +18,7 @@
TEST_PASSWORD_2 = ''.join(secrets.choice(string.ascii_letters + string.digits) for i in range(10))
TEST_PASSWORD2 = ''.join(secrets.choice(string.ascii_letters + string.digits) for i in range(10))
TEST_PASSWORD2_2 = ''.join(secrets.choice(string.ascii_letters + string.digits) for i in range(10))
REDACTED = '********'


def test_restricted_user_set_password():
Expand All @@ -29,12 +31,23 @@ def test_restricted_user_set_password():
roles=['READONLY_ADMIN']
) as acct:
with client(auth=(acct.username, acct.password)) as c:
# Password reset using existing password and current user should work
c.call('user.set_password', {
payload = {
'username': acct.username,
'old_password': acct.password,
'new_password': TEST_PASSWORD
})
}

# Password reset using existing password and current user should work
with expect_audit_method_calls([{
'method': 'user.set_password',
'params': [{
'username': acct.username,
'old_password': REDACTED,
'new_password': REDACTED
}],
'description': f'Set account password {acct.username}',
}]):
c.call('user.set_password', payload)

# Should be able to create new client session with new password
with client(auth=(acct.username, TEST_PASSWORD)) as c2:
Expand Down
Loading