Skip to content

Commit 48d04f2

Browse files
committed
Ensure duplicate batch ID insertion events can't be sent
Synapse changes in matrix-org/synapse#10877 Part of MSC2716: matrix-org/matrix-spec-proposals#2716
1 parent 97183bf commit 48d04f2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/msc2716_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,34 @@ func TestBackfillingHistory(t *testing.T) {
378378
)
379379
})
380380

381+
t.Run("Duplicate next_batch_id on insertion event will be rejected", func(t *testing.T) {
382+
t.Parallel()
383+
384+
// Alice created the room and is the room creator/admin to be able to send historical events.
385+
// We're using Alice over the application service so we can easily use SendEventSynced (application services can't use /sync)
386+
roomID := alice.CreateRoom(t, createPublicRoomOpts)
387+
388+
alice.SendEventSynced(t, roomID, b.Event{
389+
Type: insertionEventType,
390+
Content: map[string]interface{}{
391+
nextBatchIDContentField: "same",
392+
historicalContentField: true,
393+
},
394+
})
395+
396+
txnId := getTxnID("duplicateinsertion-txn")
397+
res := alice.DoFunc(t, "PUT", []string{"_matrix", "client", "r0", "rooms", roomID, "send", insertionEventType, txnId}, map[string]interface{}{
398+
nextBatchIDContentField: "same",
399+
historicalContentField: true,
400+
})
401+
402+
// We expect the send request for the duplicate insertion event to fail
403+
expectedStatus := 400
404+
if res.StatusCode != expectedStatus {
405+
t.Fatalf("Expected HTTP Status to be %s but received %s", expectedStatus, res.StatusCode)
406+
}
407+
})
408+
381409
t.Run("Normal users aren't allowed to backfill messages", func(t *testing.T) {
382410
t.Parallel()
383411

0 commit comments

Comments
 (0)