Skip to content

Commit 2aa90bb

Browse files
Ensure duplicate batch ID insertion events can't be sent (#207)
Synapse changes in matrix-org/synapse#10877 Part of MSC2716: matrix-org/matrix-spec-proposals#2716
1 parent 050afc5 commit 2aa90bb

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/msc2716_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,37 @@ func TestImportHistoricalMessages(t *testing.T) {
380380
)
381381
})
382382

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

0 commit comments

Comments
 (0)