Skip to content

Commit 091cbf5

Browse files
Verify that ephemeral events down /sync don't have a room_id field (#807)
1 parent 89b911f commit 091cbf5

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

tests/csapi/apidoc_room_receipts_test.go

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ func createRoomForReadReceipts(t *testing.T, c *client.CSAPI) (string, string) {
1717

1818
c.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(c.UserID, roomID))
1919

20-
eventID := c.SendEventSynced(t, roomID, b.Event{
20+
eventID := sendMessageIntoRoom(t, c, roomID)
21+
22+
return roomID, eventID
23+
}
24+
25+
func sendMessageIntoRoom(t *testing.T, c *client.CSAPI, roomID string) string {
26+
return c.SendEventSynced(t, roomID, b.Event{
2127
Type: "m.room.message",
2228
Content: map[string]interface{}{
2329
"msgtype": "m.text",
2430
"body": "Hello world!",
2531
},
2632
})
27-
28-
return roomID, eventID
2933
}
3034

3135
func syncHasReadReceipt(roomID, userID, eventID string) client.SyncCheckOpt {
@@ -45,7 +49,41 @@ func TestRoomReceipts(t *testing.T) {
4549
alice.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "receipt", "m.read", eventID}, client.WithJSONBody(t, struct{}{}))
4650

4751
// Make sure the read receipt shows up in sync.
48-
alice.MustSyncUntil(t, client.SyncReq{}, syncHasReadReceipt(roomID, alice.UserID, eventID))
52+
sinceToken := alice.MustSyncUntil(t, client.SyncReq{}, syncHasReadReceipt(roomID, alice.UserID, eventID))
53+
54+
// Receipt events include a `room_id` field over federation, but they should
55+
// not do so down `/sync` to clients. Ensure homeservers strip that field out.
56+
t.Run("Receipts DO NOT include a `room_id` field", func(t *testing.T) {
57+
// Send another event to read.
58+
eventID2 := sendMessageIntoRoom(t, alice, roomID)
59+
60+
// Send a read receipt for the event.
61+
alice.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "receipt", "m.read", eventID2}, client.WithJSONBody(t, struct{}{}))
62+
63+
alice.MustSyncUntil(
64+
t,
65+
client.SyncReq{Since: sinceToken},
66+
client.SyncEphemeralHas(roomID, func(r gjson.Result) bool {
67+
// Check that this is a m.receipt ephemeral event.
68+
if r.Get("type").Str != "m.receipt" {
69+
return false
70+
}
71+
72+
// Check that the receipt type is "m.read".
73+
if !r.Get(`content.*.m\.read`).Exists() {
74+
t.Fatalf("Receipt was not of type 'm.read'")
75+
}
76+
77+
// Ensure that the `room_id` field does NOT exist.
78+
if r.Get("room_id").Exists() {
79+
t.Fatalf("Read receipt should not contain 'room_id' field when syncing but saw: %s", r.Raw)
80+
}
81+
82+
// Exit the /sync loop.
83+
return true;
84+
}),
85+
)
86+
})
4987
}
5088

5189
// sytest: POST /rooms/:room_id/read_markers can create read marker

tests/csapi/room_typing_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/matrix-org/complement"
77
"github.com/matrix-org/complement/client"
88
"github.com/matrix-org/complement/helpers"
9+
"github.com/tidwall/gjson"
910
)
1011

1112
// sytest: PUT /rooms/:room_id/typing/:user_id sets typing notification
@@ -33,6 +34,30 @@ func TestTyping(t *testing.T) {
3334
alice.SendTyping(t, roomID, false, 0)
3435
bob.MustSyncUntil(t, client.SyncReq{Since: token}, client.SyncUsersTyping(roomID, []string{}))
3536
})
37+
38+
// Typing events include a `room_id` field over federation, but they should
39+
// not do so down `/sync` to clients. Ensure homeservers strip that field out.
40+
t.Run("Typing events DO NOT include a `room_id` field", func(t *testing.T) {
41+
alice.SendTyping(t, roomID, true, 0)
42+
43+
bob.MustSyncUntil(
44+
t,
45+
client.SyncReq{Since: token},
46+
client.SyncEphemeralHas(roomID, func(r gjson.Result) bool {
47+
if r.Get("type").Str != "m.typing" {
48+
return false
49+
}
50+
51+
// Ensure that the `room_id` field does NOT exist.
52+
if r.Get("room_id").Exists() {
53+
t.Fatalf("Typing event should not contain `room_id` field when syncing but saw: %s", r.Raw)
54+
}
55+
56+
// Exit the /sync loop.
57+
return true;
58+
}),
59+
)
60+
})
3661
}
3762

3863
// sytest: Typing notifications don't leak

0 commit comments

Comments
 (0)