Skip to content

Commit

Permalink
Ensure duplicate batch ID insertion events can't be sent (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods committed Oct 25, 2021
1 parent 050afc5 commit 2aa90bb
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/msc2716_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,37 @@ func TestImportHistoricalMessages(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 since 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 batch send historical messages", func(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 2aa90bb

Please sign in to comment.