Skip to content

Commit 8894050

Browse files
authored
chat: Fix parsing of 409/410 responses to sendMultiRecipientMessage
1 parent 89e3d4d commit 8894050

File tree

5 files changed

+51
-20
lines changed

5 files changed

+51
-20
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
v0.86.5
22

3+
- chat: Fixed parsing of 409/410 responses for sendMultiRecipientMessage.

java/client/src/test/java/org/signal/libsignal/net/UnauthMessagesServiceTest.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ class UnauthMessagesServiceTest {
123123
[
124124
{
125125
"uuid": "$uuid",
126-
"missingDevices": [4, 5],
127-
"extraDevices": [40, 50]
126+
"devices": {
127+
"missingDevices": [4, 5],
128+
"extraDevices": [40, 50]
129+
}
128130
}
129131
]
130132
""".trimIndent()
@@ -171,7 +173,9 @@ class UnauthMessagesServiceTest {
171173
[
172174
{
173175
"uuid": "$uuid",
174-
"staleDevices": [4, 5]
176+
"devices": {
177+
"staleDevices": [4, 5]
178+
}
175179
}
176180
]
177181
""".trimIndent()

node/ts/test/chat/UnauthMessagesServiceTest.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ describe('UnauthMessagesService', () => {
124124
JSON.stringify([
125125
{
126126
uuid,
127-
missingDevices: [4, 5],
128-
extraDevices: [40, 50],
127+
devices: {
128+
missingDevices: [4, 5],
129+
extraDevices: [40, 50],
130+
},
129131
},
130132
])
131133
),
@@ -165,7 +167,9 @@ describe('UnauthMessagesService', () => {
165167
JSON.stringify([
166168
{
167169
uuid,
168-
staleDevices: [4, 5],
170+
devices: {
171+
staleDevices: [4, 5],
172+
},
169173
},
170174
])
171175
),

rust/net/chat/src/ws/messages.rs

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

swift/Tests/LibSignalClientTests/ChatServices/UnauthMessagesServiceTests.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ class UnauthMessagesServiceTests: UnauthChatServiceTestBase<any UnauthMessagesSe
8686
[
8787
{
8888
"uuid": "\(uuid)",
89-
"missingDevices": [4, 5],
90-
"extraDevices": [40, 50]
89+
"devices": {
90+
"missingDevices": [4, 5],
91+
"extraDevices": [40, 50]
92+
}
9193
}
9294
]
9395
""".utf8
@@ -118,7 +120,9 @@ class UnauthMessagesServiceTests: UnauthChatServiceTestBase<any UnauthMessagesSe
118120
[
119121
{
120122
"uuid": "\(uuid)",
121-
"staleDevices": [4, 5]
123+
"devices": {
124+
"staleDevices": [4, 5]
125+
}
122126
}
123127
]
124128
""".utf8

0 commit comments

Comments
 (0)