From 381c8c8f80e97e2f6e750de0b8cae01f9e5ebc59 Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Fri, 15 Apr 2022 20:28:58 -0600 Subject: [PATCH] tests: update paths for new media repo structure Signed-off-by: Sumner Evans --- tests/replication/test_multi_media_repo.py | 4 +- tests/rest/admin/test_admin.py | 4 +- tests/rest/admin/test_media.py | 12 ++-- tests/rest/admin/test_statistics.py | 2 +- tests/rest/admin/test_user.py | 4 +- tests/rest/media/v1/test_media_storage.py | 8 +-- tests/rest/media/v1/test_url_preview.py | 66 +++++++++++----------- 7 files changed, 51 insertions(+), 49 deletions(-) diff --git a/tests/replication/test_multi_media_repo.py b/tests/replication/test_multi_media_repo.py index 13aa5eb51aa5..7c4f594115d7 100644 --- a/tests/replication/test_multi_media_repo.py +++ b/tests/replication/test_multi_media_repo.py @@ -65,7 +65,9 @@ def _get_media_req( The channel for the *client* request and the *outbound* request for the media which the caller should respond to. """ - resource = hs.get_media_repository_resource().children[b"download"] + resource = ( + hs.get_media_repository_resource().children[b"r0"].children[b"download"] + ) channel = make_request( self.reactor, FakeSite(resource, self.reactor), diff --git a/tests/rest/admin/test_admin.py b/tests/rest/admin/test_admin.py index 82ac5991e6e4..f914b6d7e4d6 100644 --- a/tests/rest/admin/test_admin.py +++ b/tests/rest/admin/test_admin.py @@ -61,8 +61,8 @@ class QuarantineMediaTestCase(unittest.HomeserverTestCase): def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None: # Allow for uploading and downloading to/from the media repo self.media_repo = hs.get_media_repository_resource() - self.download_resource = self.media_repo.children[b"download"] - self.upload_resource = self.media_repo.children[b"upload"] + self.download_resource = self.media_repo.children[b"v3"].children[b"download"] + self.upload_resource = self.media_repo.children[b"v3"].children[b"upload"] def _ensure_quarantined( self, admin_user_tok: str, server_and_media_id: str diff --git a/tests/rest/admin/test_media.py b/tests/rest/admin/test_media.py index e909e444ac1b..d66931b569ff 100644 --- a/tests/rest/admin/test_media.py +++ b/tests/rest/admin/test_media.py @@ -123,8 +123,8 @@ def test_delete_media(self) -> None: Tests that delete a media is successfully """ - download_resource = self.media_repo.children[b"download"] - upload_resource = self.media_repo.children[b"upload"] + download_resource = self.media_repo.children[b"v3"].children[b"download"] + upload_resource = self.media_repo.children[b"v3"].children[b"upload"] # Upload some media into the room response = self.helper.upload_media( @@ -562,7 +562,7 @@ def _create_media(self) -> str: """ Create a media and return media_id and server_and_media_id """ - upload_resource = self.media_repo.children[b"upload"] + upload_resource = self.media_repo.children[b"v3"].children[b"upload"] # Upload some media into the room response = self.helper.upload_media( @@ -586,7 +586,7 @@ def _access_media( """ Try to access a media and check the result """ - download_resource = self.media_repo.children[b"download"] + download_resource = self.media_repo.children[b"v3"].children[b"download"] media_id = server_and_media_id.split("/")[1] local_path = self.filepaths.local_media_filepath(media_id) @@ -641,7 +641,7 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None: self.admin_user_tok = self.login("admin", "pass") # Create media - upload_resource = media_repo.children[b"upload"] + upload_resource = media_repo.children[b"v3"].children[b"upload"] # Upload some media into the room response = self.helper.upload_media( @@ -778,7 +778,7 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None: self.admin_user_tok = self.login("admin", "pass") # Create media - upload_resource = media_repo.children[b"upload"] + upload_resource = media_repo.children[b"v3"].children[b"upload"] # Upload some media into the room response = self.helper.upload_media( diff --git a/tests/rest/admin/test_statistics.py b/tests/rest/admin/test_statistics.py index 7cb8ec57bad9..497872b0c68f 100644 --- a/tests/rest/admin/test_statistics.py +++ b/tests/rest/admin/test_statistics.py @@ -511,7 +511,7 @@ def _create_media(self, user_token: str, number_media: int) -> None: user_token: Access token of the user number_media: Number of media to be created for the user """ - upload_resource = self.media_repo.children[b"upload"] + upload_resource = self.media_repo.children[b"v3"].children[b"upload"] for _ in range(number_media): # Upload some media into the room self.helper.upload_media( diff --git a/tests/rest/admin/test_user.py b/tests/rest/admin/test_user.py index 0cdf1dec4042..1349e92db062 100644 --- a/tests/rest/admin/test_user.py +++ b/tests/rest/admin/test_user.py @@ -3243,8 +3243,8 @@ def _create_media_and_access( Returns: The ID of the newly created media. """ - upload_resource = self.media_repo.children[b"upload"] - download_resource = self.media_repo.children[b"download"] + upload_resource = self.media_repo.children[b"v3"].children[b"upload"] + download_resource = self.media_repo.children[b"v3"].children[b"download"] # Upload some media into the room response = self.helper.upload_media( diff --git a/tests/rest/media/v1/test_media_storage.py b/tests/rest/media/v1/test_media_storage.py index 7204b2dfe075..952a9202727c 100644 --- a/tests/rest/media/v1/test_media_storage.py +++ b/tests/rest/media/v1/test_media_storage.py @@ -253,8 +253,8 @@ def write_to(r): def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None: media_resource = hs.get_media_repository_resource() - self.download_resource = media_resource.children[b"download"] - self.thumbnail_resource = media_resource.children[b"thumbnail"] + self.download_resource = media_resource.children[b"v3"].children[b"download"] + self.thumbnail_resource = media_resource.children[b"v3"].children[b"thumbnail"] self.store = hs.get_datastores().main self.media_repo = hs.get_media_repository() @@ -605,8 +605,8 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None: # Allow for uploading and downloading to/from the media repo self.media_repo = hs.get_media_repository_resource() - self.download_resource = self.media_repo.children[b"download"] - self.upload_resource = self.media_repo.children[b"upload"] + self.download_resource = self.media_repo.children[b"v3"].children[b"download"] + self.upload_resource = self.media_repo.children[b"v3"].children[b"upload"] load_legacy_spam_checkers(hs) diff --git a/tests/rest/media/v1/test_url_preview.py b/tests/rest/media/v1/test_url_preview.py index 3b24d0ace622..88754ef09107 100644 --- a/tests/rest/media/v1/test_url_preview.py +++ b/tests/rest/media/v1/test_url_preview.py @@ -120,7 +120,7 @@ def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer: def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None: self.media_repo = hs.get_media_repository_resource() - self.preview_url = self.media_repo.children[b"preview_url"] + self.preview_url = self.media_repo.children[b"v3"].children[b"preview_url"] self.lookups: Dict[str, Any] = {} @@ -162,7 +162,7 @@ def test_cache_returns_correct_type(self) -> None: channel = self.make_request( "GET", - "preview_url?url=http://matrix.org", + "v3/preview_url?url=http://matrix.org", shorthand=False, await_result=False, ) @@ -186,7 +186,7 @@ def test_cache_returns_correct_type(self) -> None: # Check the cache returns the correct response channel = self.make_request( - "GET", "preview_url?url=http://matrix.org", shorthand=False + "GET", "v3/preview_url?url=http://matrix.org", shorthand=False ) # Check the cache response has the same content @@ -202,7 +202,7 @@ def test_cache_returns_correct_type(self) -> None: # Check the database cache returns the correct response channel = self.make_request( - "GET", "preview_url?url=http://matrix.org", shorthand=False + "GET", "v3/preview_url?url=http://matrix.org", shorthand=False ) # Check the cache response has the same content @@ -224,7 +224,7 @@ def test_non_ascii_preview_httpequiv(self) -> None: channel = self.make_request( "GET", - "preview_url?url=http://matrix.org", + "v3/preview_url?url=http://matrix.org", shorthand=False, await_result=False, ) @@ -254,7 +254,7 @@ def test_video_rejected(self) -> None: channel = self.make_request( "GET", - "preview_url?url=http://matrix.org", + "v3/preview_url?url=http://matrix.org", shorthand=False, await_result=False, ) @@ -290,7 +290,7 @@ def test_audio_rejected(self) -> None: channel = self.make_request( "GET", - "preview_url?url=http://matrix.org", + "v3/preview_url?url=http://matrix.org", shorthand=False, await_result=False, ) @@ -331,7 +331,7 @@ def test_non_ascii_preview_content_type(self) -> None: channel = self.make_request( "GET", - "preview_url?url=http://matrix.org", + "v3/preview_url?url=http://matrix.org", shorthand=False, await_result=False, ) @@ -366,7 +366,7 @@ def test_overlong_title(self) -> None: channel = self.make_request( "GET", - "preview_url?url=http://matrix.org", + "v3/preview_url?url=http://matrix.org", shorthand=False, await_result=False, ) @@ -399,7 +399,7 @@ def test_ipaddr(self) -> None: channel = self.make_request( "GET", - "preview_url?url=http://example.com", + "v3/preview_url?url=http://example.com", shorthand=False, await_result=False, ) @@ -428,7 +428,7 @@ def test_blacklisted_ip_specific(self) -> None: self.lookups["example.com"] = [(IPv4Address, "192.168.1.1")] channel = self.make_request( - "GET", "preview_url?url=http://example.com", shorthand=False + "GET", "v3/preview_url?url=http://example.com", shorthand=False ) # No requests made. @@ -449,7 +449,7 @@ def test_blacklisted_ip_range(self) -> None: self.lookups["example.com"] = [(IPv4Address, "1.1.1.2")] channel = self.make_request( - "GET", "preview_url?url=http://example.com", shorthand=False + "GET", "v3/preview_url?url=http://example.com", shorthand=False ) self.assertEqual(channel.code, 502) @@ -466,7 +466,7 @@ def test_blacklisted_ip_specific_direct(self) -> None: Blacklisted IP addresses, accessed directly, are not spidered. """ channel = self.make_request( - "GET", "preview_url?url=http://192.168.1.1", shorthand=False + "GET", "v3/preview_url?url=http://192.168.1.1", shorthand=False ) # No requests made. @@ -485,7 +485,7 @@ def test_blacklisted_ip_range_direct(self) -> None: Blacklisted IP ranges, accessed directly, are not spidered. """ channel = self.make_request( - "GET", "preview_url?url=http://1.1.1.2", shorthand=False + "GET", "v3/preview_url?url=http://1.1.1.2", shorthand=False ) self.assertEqual(channel.code, 403) @@ -506,7 +506,7 @@ def test_blacklisted_ip_range_whitelisted_ip(self) -> None: channel = self.make_request( "GET", - "preview_url?url=http://example.com", + "v3/preview_url?url=http://example.com", shorthand=False, await_result=False, ) @@ -542,7 +542,7 @@ def test_blacklisted_ip_with_external_ip(self) -> None: ] channel = self.make_request( - "GET", "preview_url?url=http://example.com", shorthand=False + "GET", "v3/preview_url?url=http://example.com", shorthand=False ) self.assertEqual(channel.code, 502) self.assertEqual( @@ -562,7 +562,7 @@ def test_blacklisted_ipv6_specific(self) -> None: ] channel = self.make_request( - "GET", "preview_url?url=http://example.com", shorthand=False + "GET", "v3/preview_url?url=http://example.com", shorthand=False ) # No requests made. @@ -583,7 +583,7 @@ def test_blacklisted_ipv6_range(self) -> None: self.lookups["example.com"] = [(IPv6Address, "2001:800::1")] channel = self.make_request( - "GET", "preview_url?url=http://example.com", shorthand=False + "GET", "v3/preview_url?url=http://example.com", shorthand=False ) self.assertEqual(channel.code, 502) @@ -600,7 +600,7 @@ def test_OPTIONS(self) -> None: OPTIONS returns the OPTIONS. """ channel = self.make_request( - "OPTIONS", "preview_url?url=http://example.com", shorthand=False + "OPTIONS", "v3/preview_url?url=http://example.com", shorthand=False ) self.assertEqual(channel.code, 200) self.assertEqual(channel.json_body, {}) @@ -614,7 +614,7 @@ def test_accept_language_config_option(self) -> None: # Build and make a request to the server channel = self.make_request( "GET", - "preview_url?url=http://example.com", + "v3/preview_url?url=http://example.com", shorthand=False, await_result=False, ) @@ -672,7 +672,7 @@ def test_data_url(self) -> None: channel = self.make_request( "GET", - f"preview_url?{query_params}", + f"v3/preview_url?{query_params}", shorthand=False, ) self.pump() @@ -693,7 +693,7 @@ def test_inline_data_url(self) -> None: channel = self.make_request( "GET", - "preview_url?url=http://matrix.org", + "v3/preview_url?url=http://matrix.org", shorthand=False, await_result=False, ) @@ -730,7 +730,7 @@ def test_oembed_photo(self) -> None: channel = self.make_request( "GET", - "preview_url?url=http://twitter.com/matrixdotorg/status/12345", + "v3/preview_url?url=http://twitter.com/matrixdotorg/status/12345", shorthand=False, await_result=False, ) @@ -790,7 +790,7 @@ def test_oembed_rich(self) -> None: channel = self.make_request( "GET", - "preview_url?url=http://twitter.com/matrixdotorg/status/12345", + "v3/preview_url?url=http://twitter.com/matrixdotorg/status/12345", shorthand=False, await_result=False, ) @@ -834,7 +834,7 @@ def test_oembed_format(self) -> None: channel = self.make_request( "GET", - "preview_url?url=http://www.hulu.com/watch/12345", + "v3/preview_url?url=http://www.hulu.com/watch/12345", shorthand=False, await_result=False, ) @@ -892,7 +892,7 @@ def test_oembed_autodiscovery(self) -> None: channel = self.make_request( "GET", - "preview_url?url=http://www.twitter.com/matrixdotorg/status/12345", + "v3/preview_url?url=http://www.twitter.com/matrixdotorg/status/12345", shorthand=False, await_result=False, ) @@ -975,7 +975,7 @@ def _download_image(self) -> Tuple[str, str]: channel = self.make_request( "GET", - "preview_url?url=http://cdn.twitter.com/matrixdotorg", + "v3/preview_url?url=http://cdn.twitter.com/matrixdotorg", shorthand=False, await_result=False, ) @@ -1017,7 +1017,7 @@ def test_storage_providers_exclude_files(self) -> None: # Check fetching channel = self.make_request( "GET", - f"download/{host}/{media_id}", + f"v3/download/{host}/{media_id}", shorthand=False, await_result=False, ) @@ -1030,7 +1030,7 @@ def test_storage_providers_exclude_files(self) -> None: channel = self.make_request( "GET", - f"download/{host}/{media_id}", + f"v3/download/{host}/{media_id}", shorthand=False, await_result=False, ) @@ -1065,7 +1065,7 @@ def test_storage_providers_exclude_thumbnails(self) -> None: # Check fetching channel = self.make_request( "GET", - f"thumbnail/{host}/{media_id}?width=32&height=32&method=scale", + f"v3/thumbnail/{host}/{media_id}?width=32&height=32&method=scale", shorthand=False, await_result=False, ) @@ -1083,7 +1083,7 @@ def test_storage_providers_exclude_thumbnails(self) -> None: channel = self.make_request( "GET", - f"thumbnail/{host}/{media_id}?width=32&height=32&method=scale", + f"v3/thumbnail/{host}/{media_id}?width=32&height=32&method=scale", shorthand=False, await_result=False, ) @@ -1135,7 +1135,7 @@ def test_blacklist_port(self) -> None: channel = self.make_request( "GET", - "preview_url?url=" + bad_url, + "v3/preview_url?url=" + bad_url, shorthand=False, await_result=False, ) @@ -1144,7 +1144,7 @@ def test_blacklist_port(self) -> None: channel = self.make_request( "GET", - "preview_url?url=" + good_url, + "v3/preview_url?url=" + good_url, shorthand=False, await_result=False, )