@@ -39,7 +39,7 @@ type ExecuteDelayedEventActionFn = Box<
3939 dyn Fn ( & CsApiUrl , & str , DelayEventAction , & str , & str ) -> Result < u16 , ActionError > + Send + Sync ,
4040> ;
4141type GetDelayedEventDelayFn =
42- Box < dyn Fn ( & CsApiUrl , & str , & str , & str ) -> Result < Duration , ActionError > + Send + Sync > ;
42+ Box < dyn Fn ( & CsApiUrl , & str , & str , & str , & str ) -> Result < Duration , ActionError > + Send + Sync > ;
4343type IsJoinedFn = Box < dyn Fn ( & CsApiUrl , & str , & str ) -> Result < bool , String > + Send + Sync > ;
4444type RequestGetTokenViaFederationFn = Box <
4545 dyn Fn ( & CsApiUrl , & str , & GetTokenSsRequest ) -> Result < GetTokenSsResponse , FederationTokenError >
@@ -143,10 +143,17 @@ impl Deps for HandlerTestDeps {
143143 & self ,
144144 cs_api_url : & CsApiUrl ,
145145 delay_id : & str ,
146+ room_id : & str ,
146147 identity : AppServiceIdentity < ' _ > ,
147148 ) -> Result < Duration , ActionError > {
148149 match & self . get_delayed_event_delay_fn {
149- Some ( f) => f ( cs_api_url, delay_id, identity. as_token , identity. user_id ) ,
150+ Some ( f) => f (
151+ cs_api_url,
152+ delay_id,
153+ room_id,
154+ identity. as_token ,
155+ identity. user_id ,
156+ ) ,
150157 None => panic ! ( "get_delayed_event_delay not mocked in HandlerTestDeps" ) ,
151158 }
152159 }
@@ -4182,11 +4189,12 @@ async fn test_process_delegate_delayed_leave_cs_restart_uses_identity_assertion(
41824189}
41834190
41844191/// A request without a delay timeout makes the service look the delay up on
4185- /// the homeserver, asserting the caller's identity as it does so.
4192+ /// the homeserver, asserting the caller's identity and the request's
4193+ /// `room_id` as it does so.
41864194#[ tokio:: test]
41874195async fn test_process_delegate_delayed_leave_cs_looks_up_missing_delay_timeout ( ) {
4188- /// (CS API URL, delay ID, as_token, user_id) of the recorded lookup.
4189- type Lookup = ( String , String , String , String ) ;
4196+ /// (CS API URL, delay ID, room ID, as_token, user_id) of the recorded lookup.
4197+ type Lookup = ( String , String , String , String , String ) ;
41904198 let looked_up: Arc < Mutex < Option < Lookup > > > = Arc :: new ( Mutex :: new ( None ) ) ;
41914199 let looked_up_clone = looked_up. clone ( ) ;
41924200 let deps = HandlerTestDeps {
@@ -4195,10 +4203,11 @@ async fn test_process_delegate_delayed_leave_cs_looks_up_missing_delay_timeout()
41954203 } ) ) ,
41964204 participant_exists_fn : participant_exists_block_until_cancelled ( ) ,
41974205 get_delayed_event_delay_fn : Some ( Box :: new (
4198- move |cs_api_url, delay_id, as_token, user_id| {
4206+ move |cs_api_url, delay_id, room_id , as_token, user_id| {
41994207 * looked_up_clone. lock ( ) . unwrap ( ) = Some ( (
42004208 cs_api_url. 0 . clone ( ) ,
42014209 delay_id. to_owned ( ) ,
4210+ room_id. to_owned ( ) ,
42024211 as_token. to_owned ( ) ,
42034212 user_id. to_owned ( ) ,
42044213 ) ) ;
@@ -4216,13 +4225,14 @@ async fn test_process_delegate_delayed_leave_cs_looks_up_missing_delay_timeout()
42164225 . await
42174226 . expect ( "unexpected error" ) ;
42184227
4219- let ( cs_api_url, delay_id, as_token, user_id) = looked_up
4228+ let ( cs_api_url, delay_id, room_id , as_token, user_id) = looked_up
42204229 . lock ( )
42214230 . unwrap ( )
42224231 . clone ( )
42234232 . expect ( "expected the delay to be looked up" ) ;
42244233 assert_eq ! ( cs_api_url, "https://matrix-client.example.com" ) ;
42254234 assert_eq ! ( delay_id, req. delay_id, "expected the requested delay_id" ) ;
4235+ assert_eq ! ( room_id, req. room_id, "expected the requested room_id" ) ;
42264236 assert_eq ! ( as_token, "as_token" , "expected the configured as_token" ) ;
42274237 assert_eq ! (
42284238 user_id, DELEGATE_DELAYED_LEAVE_CS_MXID ,
@@ -4245,7 +4255,7 @@ async fn test_process_delegate_delayed_leave_cs_looked_up_delay_drives_the_job()
42454255 // Confirmed absent, so the job stays in WaitingForInitialConnect until
42464256 // its timeout — which is the looked-up delay — elapses.
42474257 participant_exists_fn : Some ( Box :: new ( |_, _| Box :: pin ( async { Ok ( false ) } ) ) ) ,
4248- get_delayed_event_delay_fn : Some ( Box :: new ( |_, _, _, _| Ok ( Duration :: from_millis ( 200 ) ) ) ) ,
4258+ get_delayed_event_delay_fn : Some ( Box :: new ( |_, _, _, _, _ | Ok ( Duration :: from_millis ( 200 ) ) ) ) ,
42494259 execute_delayed_event_action_fn : Some ( Box :: new ( move |_, _, action, _, _| {
42504260 if action == DelayEventAction :: Send {
42514261 * sent_clone. lock ( ) . unwrap ( ) = true ;
@@ -4282,7 +4292,7 @@ async fn test_process_delegate_delayed_leave_cs_skips_lookup_when_delay_timeout_
42824292 Ok ( CsApiUrl ( "https://matrix-client.example.com" . into ( ) ) )
42834293 } ) ) ,
42844294 participant_exists_fn : participant_exists_block_until_cancelled ( ) ,
4285- get_delayed_event_delay_fn : Some ( Box :: new ( |_, _, _, _| {
4295+ get_delayed_event_delay_fn : Some ( Box :: new ( |_, _, _, _, _ | {
42864296 panic ! ( "the delay must not be looked up when the request carries one" )
42874297 } ) ) ,
42884298 ..Default :: default ( )
@@ -4298,14 +4308,14 @@ async fn test_process_delegate_delayed_leave_cs_skips_lookup_when_delay_timeout_
42984308 handler. close ( ) . await ;
42994309}
43004310
4301- /// An unknown delay_id surfaces as 404 M_NOT_FOUND .
4311+ /// An unknown delay_id is rejected as HTTP 400 / M_INVALID_PARAM .
43024312#[ tokio:: test]
43034313async fn test_process_delegate_delayed_leave_cs_delay_lookup_not_found ( ) {
43044314 let deps = HandlerTestDeps {
43054315 resolve_cs_api_url_fn : Some ( Box :: new ( |_| {
43064316 Ok ( CsApiUrl ( "https://matrix-client.example.com" . into ( ) ) )
43074317 } ) ) ,
4308- get_delayed_event_delay_fn : Some ( Box :: new ( |_, _, _, _| {
4318+ get_delayed_event_delay_fn : Some ( Box :: new ( |_, _, _, _, _ | {
43094319 Err ( ActionError :: DelayedEventNotFound { status : 404 } )
43104320 } ) ) ,
43114321 ..Default :: default ( )
@@ -4318,8 +4328,8 @@ async fn test_process_delegate_delayed_leave_cs_delay_lookup_not_found() {
43184328 . process_delegate_delayed_leave_cs ( & req, DELEGATE_DELAYED_LEAVE_CS_MXID )
43194329 . await
43204330 . expect_err ( "expected MatrixErrorResponse" ) ;
4321- assert_eq ! ( err. status, 404 , "expected 404 " ) ;
4322- assert_eq ! ( err. errcode, "M_NOT_FOUND " , "expected M_NOT_FOUND " ) ;
4331+ assert_eq ! ( err. status, 400 , "expected 400 " ) ;
4332+ assert_eq ! ( err. errcode, "M_INVALID_PARAM " , "expected M_INVALID_PARAM " ) ;
43234333 handler. close ( ) . await ;
43244334}
43254335
@@ -4331,7 +4341,7 @@ async fn test_process_delegate_delayed_leave_cs_delay_lookup_unavailable() {
43314341 resolve_cs_api_url_fn : Some ( Box :: new ( |_| {
43324342 Ok ( CsApiUrl ( "https://matrix-client.example.com" . into ( ) ) )
43334343 } ) ) ,
4334- get_delayed_event_delay_fn : Some ( Box :: new ( |_, _, _, _| {
4344+ get_delayed_event_delay_fn : Some ( Box :: new ( |_, _, _, _, _ | {
43354345 Err ( ActionError :: Transient {
43364346 status : 500 ,
43374347 msg : "boom" . into ( ) ,
0 commit comments