Skip to content

Commit

Permalink
Ensure duplicate batch ID insertion events can't be sent
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods committed Sep 24, 2021
1 parent 97183bf commit 48d04f2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/msc2716_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,34 @@ func TestBackfillingHistory(t *testing.T) {
)
})

t.Run("Duplicate next_batch_id on insertion event will be rejected", func(t *testing.T) {
t.Parallel()

// Alice created the room and is the room creator/admin to be able to send historical events.
// We're using Alice over the application service so we can easily use SendEventSynced (application services can't use /sync)
roomID := alice.CreateRoom(t, createPublicRoomOpts)

alice.SendEventSynced(t, roomID, b.Event{
Type: insertionEventType,
Content: map[string]interface{}{
nextBatchIDContentField: "same",
historicalContentField: true,
},
})

txnId := getTxnID("duplicateinsertion-txn")
res := alice.DoFunc(t, "PUT", []string{"_matrix", "client", "r0", "rooms", roomID, "send", insertionEventType, txnId}, map[string]interface{}{
nextBatchIDContentField: "same",
historicalContentField: true,
})

// We expect the send request for the duplicate insertion event to fail
expectedStatus := 400
if res.StatusCode != expectedStatus {
t.Fatalf("Expected HTTP Status to be %s but received %s", expectedStatus, res.StatusCode)
}
})

t.Run("Normal users aren't allowed to backfill messages", func(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 48d04f2

Please sign in to comment.