Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure duplicate batch ID insertion events can't be sent (MSC2716) #207

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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