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

fix broken avatar checks when server_name contains a port #13927

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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 changelog.d/13927.bugfix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fix a bug which prevented setting an avatar on homeservers which have an explicit port in their `server_name` and had avatar's size or image type restrictions configured. Contributed by @ashfame.
Fix a bug which prevented setting an avatar on homeservers which have an explicit port in their `server_name` and have `max_avatar_size` and/or `allowed_avatar_mimetypes` configuration. Contributed by @ashfame.
18 changes: 10 additions & 8 deletions tests/handlers/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,11 @@ def test_avatar_constraint_mime_type(self) -> None:

@unittest.override_config({"allowed_avatar_mimetypes": ["image/png"]})
def test_avatar_fetching_metadata_right_source(self) -> None:
"""Tests that local and remote file are rightly fetched for metadata
when checking for avatar size and mime type"""
"""Tests that local and remote files are correctly fetched for metadata
when checking for avatar size and mime type."""
# This test only concerns itself with correctly figuring out the host and port
# based on mxc url so that metadata can be fetched from the right place i.e.
# get_local_media() for local image & get_cached_remote_media() for remote image
remote_server = "test:8080"
store = self.hs.get_datastores().main

Expand All @@ -344,6 +347,11 @@ def test_avatar_fetching_metadata_right_source(self) -> None:
user_id=UserID.from_string("@whatever:test"),
)
)
res = self.get_success(
self.handler.check_avatar_size_and_mime_type("mxc://test/local")
)
self.assertTrue(res)

self.get_success(
store.store_cached_remote_media(
media_id="remote",
Expand All @@ -355,12 +363,6 @@ def test_avatar_fetching_metadata_right_source(self) -> None:
filesystem_id="remote",
)
)

res = self.get_success(
self.handler.check_avatar_size_and_mime_type("mxc://test/local")
)
self.assertTrue(res)

res = self.get_success(
self.handler.check_avatar_size_and_mime_type(
"mxc://" + remote_server + "/remote"
Expand Down