From 314cf43d500ec39a0eec241b24cc1623db90a316 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Wed, 1 Jul 2026 16:24:47 +0530 Subject: [PATCH] test(matrix): assert real device_id in query_keys, not just guard-skip MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hardens the salvaged #53997 tests per review: the positive-resolution and reconnect-recovery tests now assert query_keys is awaited with the REAL resolved device id ({mxid: []}) and never [None] — the [null] body the homeserver rejects (the actual bug), plus await_count==2 to prove verification genuinely re-runs after resolution rather than just the flag looking right. --- tests/gateway/test_matrix.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/gateway/test_matrix.py b/tests/gateway/test_matrix.py index 876a91c915b..dd413c9f74a 100644 --- a/tests/gateway/test_matrix.py +++ b/tests/gateway/test_matrix.py @@ -4816,6 +4816,16 @@ class TestDeviceIdNoneResolution: assert result is True assert adapter._device_id_unverified is False + # Positive path (W1 hardening, salvage of #53997): the resolution query + # must use an empty device list ({mxid: []}), and once RESOLVED_DEV is + # adopted the verification query must carry the REAL id, never [None] + # (the [null] body Synapse/Dendrite reject — the original bug). + assert mock_client.device_id == "RESOLVED_DEV" + assert mock_client.query_keys.await_count == 2 + _resolution_call, _verify_call = mock_client.query_keys.await_args_list + assert _resolution_call.args[0] == {"@bot:example.org": []} + assert _verify_call.args[0] == {"@bot:example.org": ["RESOLVED_DEV"]} + assert None not in _verify_call.args[0]["@bot:example.org"] await adapter.disconnect() @@ -5247,6 +5257,15 @@ class TestDeviceIdRecoveryOnReconnect: assert result is True assert adapter._device_id_unverified is False - mock_client2.query_keys.assert_awaited() + # Verification must genuinely re-run on the second connect — not just + # the resolution query. Two awaited query_keys calls: resolution + # ({mxid: []}) then verification ({mxid: []}). The + # verification call must carry the REAL resolved device id ("DEV2"), + # never [None] (the original bug). (W2 hardening, salvage of #53997) + assert mock_client2.query_keys.await_count == 2 + _resolution_call, _verify_call = mock_client2.query_keys.await_args_list + assert _resolution_call.args[0] == {"@bot:example.org": []} + assert _verify_call.args[0] == {"@bot:example.org": ["DEV2"]} + assert None not in _verify_call.args[0]["@bot:example.org"] await adapter.disconnect()