@@ -121,10 +121,16 @@ fn parse_multi_recipient_mismatched_devices_response(
121121 debug_assert_matches ! ( response. status. as_u16( ) , 409 | 410 ) ;
122122
123123 #[ derive( serde:: Deserialize ) ]
124- #[ serde( rename_all = "camelCase" ) ]
125124 struct ParsedMismatchedDevicesEntry {
126125 #[ serde( rename = "uuid" ) ]
127126 service_id : String ,
127+ devices : ParsedMismatchedDevices ,
128+ }
129+
130+ // Note: this can be shared with the 1:1 mismatched devices response.
131+ #[ derive( serde:: Deserialize , Default , PartialEq , Eq ) ]
132+ #[ serde( rename_all = "camelCase" ) ]
133+ struct ParsedMismatchedDevices {
128134 // 409 fields
129135 #[ serde( default ) ]
130136 missing_devices : Vec < u8 > ,
@@ -158,10 +164,19 @@ fn parse_multi_recipient_mismatched_devices_response(
158164 . map ( |entry| {
159165 let ParsedMismatchedDevicesEntry {
160166 service_id,
167+ devices,
168+ } = entry;
169+ if devices == Default :: default ( ) {
170+ return Err ( CustomError :: Unexpected {
171+ log_safe : "no devices listed in mismatched device response" . to_owned ( ) ,
172+ } ) ;
173+ }
174+ let ParsedMismatchedDevices {
161175 missing_devices,
162176 extra_devices,
163177 stale_devices,
164- } = entry;
178+ } = devices;
179+
165180 Ok ( MismatchedDeviceError {
166181 account : ServiceId :: parse_from_service_id_string ( & service_id) . ok_or_else ( || {
167182 CustomError :: Unexpected {
@@ -224,8 +239,8 @@ mod test {
224239 #[ test_case( empty( 409 ) => matches Err ( RequestError :: Unexpected { .. } ) ) ]
225240 #[ test_case( json(
226241 409 , format!( r#"[
227- {{"uuid":"{ACI_UUID}","missingDevices":[50,60]}},
228- {{"uuid":"PNI:{PNI_UUID}","missingDevices":[],"extraDevices":[4,5]}}
242+ {{"uuid":"{ACI_UUID}","devices":{{" missingDevices":[50,60]}} }},
243+ {{"uuid":"PNI:{PNI_UUID}","devices":{{" missingDevices":[],"extraDevices":[4,5]}} }}
229244 ]"# )
230245 ) => matches Err ( RequestError :: Other ( MrFailure :: MismatchedDevices ( errors) ) ) if errors == [
231246 MismatchedDeviceError {
@@ -243,8 +258,8 @@ mod test {
243258 ] ) ]
244259 #[ test_case( json(
245260 410 , format!( r#"[
246- {{"uuid":"{ACI_UUID}","staleDevices":[4,5]}},
247- {{"uuid":"PNI:{PNI_UUID}","staleDevices":[] }}
261+ {{"uuid":"{ACI_UUID}","devices":{{" staleDevices":[4,5]}} }},
262+ {{"uuid":"PNI:{PNI_UUID}","devices":{{" staleDevices":[1]}} }}
248263 ]"# )
249264 ) => matches Err ( RequestError :: Other ( MrFailure :: MismatchedDevices ( errors) ) ) if errors == [
250265 MismatchedDeviceError {
@@ -257,23 +272,26 @@ mod test {
257272 account: Pni :: from( Uuid :: try_parse( PNI_UUID ) . unwrap( ) ) . into( ) ,
258273 missing_devices: vec![ ] ,
259274 extra_devices: vec![ ] ,
260- stale_devices: vec![ ] ,
275+ stale_devices: vec![ DeviceId :: new ( 1 ) . unwrap ( ) ] ,
261276 } ,
262277 ] ) ]
263278 #[ test_case( json(
264279 410 , r#"["#
265280 ) => matches Err ( RequestError :: Unexpected { .. } ) ) ]
266281 #[ test_case( json(
267- 410 , format!( r#"{{"uuid":"{ACI_UUID}","staleDevices":[4,5]}}"# )
282+ 410 , format!( r#"{{"uuid":"{ACI_UUID}","devices":{{"staleDevices":[4,5]}}}}"# )
283+ ) => matches Err ( RequestError :: Unexpected { .. } ) ) ]
284+ #[ test_case( json(
285+ 410 , format!( r#"[{{"uuid":"{ACI_UUID}","devices":{{}}}}]"# )
268286 ) => matches Err ( RequestError :: Unexpected { .. } ) ) ]
269287 #[ test_case( json(
270- 410 , r#"[{"uuid":"garbage","staleDevices":[4,5]}]"#
288+ 410 , r#"[{"uuid":"garbage","devices":{{" staleDevices":[4,5]}} }]"#
271289 ) => matches Err ( RequestError :: Unexpected { .. } ) ) ]
272290 #[ test_case( json(
273- 410 , format!( r#"{{"uuid":"{ACI_UUID}","staleDevices":[200]}}"# )
291+ 410 , format!( r#"[ {{"uuid":"{ACI_UUID}","devices":{{" staleDevices":[200]}}}}] "# )
274292 ) => matches Err ( RequestError :: Unexpected { .. } ) ) ]
275293 #[ test_case( json(
276- 410 , format!( r#"{{"uuid":"{ACI_UUID}","staleDevices":["4"]}}"# )
294+ 410 , format!( r#"[ {{"uuid":"{ACI_UUID}","devices":{{" staleDevices":["4"]}}}}] "# )
277295 ) => matches Err ( RequestError :: Unexpected { .. } ) ) ]
278296 fn test_story (
279297 response : Response ,
0 commit comments