From 1eb8f6ac161fbf1c773a7ddb8243d7378489fdc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Tue, 12 Aug 2025 15:44:45 +0200 Subject: [PATCH] Fix shared history test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kévin Commaille --- crates/matrix-sdk/src/test_utils/mocks/mod.rs | 25 +++++++++++++------ .../integration/encryption/shared_history.rs | 21 +++++++++++++--- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/crates/matrix-sdk/src/test_utils/mocks/mod.rs b/crates/matrix-sdk/src/test_utils/mocks/mod.rs index 1bafbf5c3..cbd5d33e3 100644 --- a/crates/matrix-sdk/src/test_utils/mocks/mod.rs +++ b/crates/matrix-sdk/src/test_utils/mocks/mod.rs @@ -1231,7 +1231,7 @@ impl MatrixMockServer { &self, ) -> MockEndpoint<'_, AuthenticatedMediaConfigEndpoint> { let mock = Mock::given(method("GET")).and(path("/_matrix/client/v1/media/config")); - self.mock_endpoint(mock, AuthenticatedMediaConfigEndpoint).expect_default_access_token() + self.mock_endpoint(mock, AuthenticatedMediaConfigEndpoint) } /// Create a prebuilt mock for the endpoint used to get the media config of @@ -1559,6 +1559,15 @@ impl<'a, T> MockEndpoint<'a, T> { self } + /// Don't expect authentication with an access token on this endpoint. + /// + /// This should be used to override the default behavior of the endpoint, + /// when the access token is unknown for example. + pub fn do_not_expect_access_token(mut self) -> Self { + self.expected_access_token = ExpectedAccessToken::None; + self + } + /// Specify how to respond to a query (viz., like /// [`MockBuilder::respond_with`] does), when other predefined responses /// aren't sufficient. @@ -3763,13 +3772,6 @@ impl<'a> MockEndpoint<'a, MediaDownloadEndpoint> { self.respond_with(ResponseTemplate::new(200).set_body_string("Hello, World!")) } - /// Returns a successful response with the given bytes. - pub fn ok_bytes(self, bytes: Vec) -> MatrixMock<'a> { - self.respond_with( - ResponseTemplate::new(200).set_body_raw(bytes, "application/octet-stream"), - ) - } - /// Returns a successful response with a fake image content. pub fn ok_image(self) -> MatrixMock<'a> { self.respond_with( @@ -3799,6 +3801,13 @@ impl<'a> MockEndpoint<'a, AuthedMediaDownloadEndpoint> { self.respond_with(ResponseTemplate::new(200).set_body_string("Hello, World!")) } + /// Returns a successful response with the given bytes. + pub fn ok_bytes(self, bytes: Vec) -> MatrixMock<'a> { + self.respond_with( + ResponseTemplate::new(200).set_body_raw(bytes, "application/octet-stream"), + ) + } + /// Returns a successful response with a fake image content. pub fn ok_image(self) -> MatrixMock<'a> { self.respond_with( diff --git a/crates/matrix-sdk/tests/integration/encryption/shared_history.rs b/crates/matrix-sdk/tests/integration/encryption/shared_history.rs index 927a5e8e9..33421d32f 100644 --- a/crates/matrix-sdk/tests/integration/encryption/shared_history.rs +++ b/crates/matrix-sdk/tests/integration/encryption/shared_history.rs @@ -72,7 +72,7 @@ async fn test_shared_history_out_of_order() { let (event_receiver, mock) = matrix_mock_server.mock_room_send().ok_with_capture(event_id, alice_user_id); - mock.mock_once().mount().await; + mock.mock_once().named("send").mount().await; matrix_mock_server .mock_get_members() @@ -87,7 +87,13 @@ async fn test_shared_history_out_of_order() { .expect("We should be able to send an initial message") .event_id; - matrix_mock_server.mock_authenticated_media_config().ok_default().mock_once().mount().await; + matrix_mock_server + .mock_authenticated_media_config() + .ok_default() + .mock_once() + .named("media_config") + .mount() + .await; let (receiver, upload_mock) = matrix_mock_server.mock_upload().ok_with_capture(mxid); upload_mock.mock_once().mount().await; @@ -118,7 +124,7 @@ async fn test_shared_history_out_of_order() { let bob_room = bob.get_room(room_id).expect("Bob should have access to the invited room"); - matrix_mock_server.mock_room_join(room_id).ok().mock_once().mount().await; + matrix_mock_server.mock_room_join(room_id).ok().mock_once().named("join").mount().await; bob_room.join().await.expect("Bob should be able to join the room"); let details = bob_room @@ -132,7 +138,14 @@ async fn test_shared_history_out_of_order() { ); let bundle_info = bundle_info.await; - matrix_mock_server.mock_media_download().ok_bytes(bundle).mock_once().mount().await; + matrix_mock_server + .mock_authed_media_download() + .do_not_expect_access_token() + .ok_bytes(bundle) + .mock_once() + .named("media_download") + .mount() + .await; let mut room_key_stream = bob .encryption()