Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Allow reactivate a user without password #16739

Closed
Closed
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions changelog.d/16739.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow reactivate user without password with Admin API in some edge cases.
9 changes: 0 additions & 9 deletions synapse/rest/admin/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,6 @@ async def on_PUT(
target_user.to_string(), False, requester, by_admin=True
)
elif not deactivate and user["deactivated"]:
if (
"password" not in body
and self.auth_handler.can_change_password()
):
raise SynapseError(
HTTPStatus.BAD_REQUEST,
"Must provide a password to re-activate an account.",
)

await self.deactivate_account_handler.activate_account(
target_user.to_string()
)
Expand Down
31 changes: 23 additions & 8 deletions tests/rest/admin/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2741,29 +2741,44 @@ def test_change_name_deactivate_user_user_directory(self) -> None:
profile = self.get_success(self.store._get_user_in_directory(self.other_user))
self.assertIsNone(profile)

def test_reactivate_user(self) -> None:
def test_reactivate_user_with_password(self) -> None:
"""
Test reactivating another user.
"""

# Deactivate the user.
self._deactivate_user("@user:test")

# Attempt to reactivate the user (without a password).
# Reactivate the user with password.
channel = self.make_request(
"PUT",
self.url_other_user,
access_token=self.admin_user_tok,
content={"deactivated": False},
content={"deactivated": False, "password": "foo"},
)
self.assertEqual(400, channel.code, msg=channel.json_body)
self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual("@user:test", channel.json_body["name"])
self.assertFalse(channel.json_body["deactivated"])
self._is_erased("@user:test", False)

# This key was removed intentionally. Ensure it is not accidentally re-included.
self.assertNotIn("password_hash", channel.json_body)

# Reactivate the user.
def test_reactivate_user_without_password(self) -> None:
"""
Test reactivating another user without a password.
This can be using some local users and some user with SSO (password = `null`).
"""

# Deactivate the user.
self._deactivate_user("@user:test")

# Reactivate the user without a password.
channel = self.make_request(
"PUT",
self.url_other_user,
access_token=self.admin_user_tok,
content={"deactivated": False, "password": "foo"},
content={"deactivated": False},
)
self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual("@user:test", channel.json_body["name"])
Expand All @@ -2782,7 +2797,7 @@ def test_reactivate_user_localdb_disabled(self) -> None:
# Deactivate the user.
self._deactivate_user("@user:test")

# Reactivate the user with a password
# Reactivate the user with a password.
channel = self.make_request(
"PUT",
self.url_other_user,
Expand Down Expand Up @@ -2816,7 +2831,7 @@ def test_reactivate_user_password_disabled(self) -> None:
# Deactivate the user.
self._deactivate_user("@user:test")

# Reactivate the user with a password
# Reactivate the user with a password.
channel = self.make_request(
"PUT",
self.url_other_user,
Expand Down
Loading