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

Commit fffb3c4

Browse files
David Robertsonclokep
andauthored
Always allow the empty string as an avatar_url. (#12261)
Hopefully this fixes #12257. Co-authored-by: Patrick Cloke <[email protected]>
1 parent 61aae18 commit fffb3c4

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

changelog.d/12261.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug introduced in Synapse 1.52 where admins could not deactivate and GDPR-erase a user if Synapse was configured with limits on avatars.

synapse/handlers/profile.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,18 @@ async def check_avatar_size_and_mime_type(self, mxc: str) -> bool:
336336
"""Check that the size and content type of the avatar at the given MXC URI are
337337
within the configured limits.
338338
339+
If the given `mxc` is empty, no checks are performed. (Users are always able to
340+
unset their avatar.)
341+
339342
Args:
340343
mxc: The MXC URI at which the avatar can be found.
341344
342345
Returns:
343346
A boolean indicating whether the file can be allowed to be set as an avatar.
344347
"""
348+
if mxc == "":
349+
return True
350+
345351
if not self.max_avatar_size and not self.allowed_avatar_mimetypes:
346352
return True
347353

tests/handlers/test_profile.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ def test_avatar_constraints_no_config(self) -> None:
267267
)
268268
self.assertTrue(res)
269269

270+
@unittest.override_config({"max_avatar_size": 50})
271+
def test_avatar_constraints_allow_empty_avatar_url(self) -> None:
272+
"""An empty avatar is always permitted."""
273+
res = self.get_success(self.handler.check_avatar_size_and_mime_type(""))
274+
self.assertTrue(res)
275+
270276
@unittest.override_config({"max_avatar_size": 50})
271277
def test_avatar_constraints_missing(self) -> None:
272278
"""Tests that an avatar isn't allowed if the file at the given MXC URI couldn't

tests/rest/admin/test_user.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,25 @@ def test_deactivate_user_erase_true(self) -> None:
10501050

10511051
self._is_erased("@user:test", True)
10521052

1053+
@override_config({"max_avatar_size": 1234})
1054+
def test_deactivate_user_erase_true_avatar_nonnull_but_empty(self) -> None:
1055+
"""Check we can erase a user whose avatar is the empty string.
1056+
1057+
Reproduces #12257.
1058+
"""
1059+
# Patch `self.other_user` to have an empty string as their avatar.
1060+
self.get_success(self.store.set_profile_avatar_url("user", ""))
1061+
1062+
# Check we can still erase them.
1063+
channel = self.make_request(
1064+
"POST",
1065+
self.url,
1066+
access_token=self.admin_user_tok,
1067+
content={"erase": True},
1068+
)
1069+
self.assertEqual(HTTPStatus.OK, channel.code, msg=channel.json_body)
1070+
self._is_erased("@user:test", True)
1071+
10531072
def test_deactivate_user_erase_false(self) -> None:
10541073
"""
10551074
Test deactivating a user and set `erase` to `false`

0 commit comments

Comments
 (0)