Skip to content
Open
Show file tree
Hide file tree
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
26 changes: 17 additions & 9 deletions federation/server_room.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"log"
"strconv"
"sync"
"time"

Expand Down Expand Up @@ -333,15 +334,22 @@ func InitialRoomEvents(roomVer gomatrixserverlib.RoomVersion, creator string) []
Type: "m.room.create",
StateKey: b.Ptr(""),
Sender: creator,
Content: map[string]interface{}{
"creator": creator,
"room_version": roomVer,
// We have to add randomness to the create event, else if you create 2x v12+ rooms in the same millisecond
// they will get the same room ID, clobbering internal data structures and causing extremely confusing
// behaviour. By adding this entropy, we ensure that even if rooms are created in the same millisecond, their
// hashes will not be the same.
"complement_entropy": util.RandomString(18),
},
Content: func() map[string]interface{} {
content := map[string]interface{}{
"room_version": roomVer,
// We have to add randomness to the create event, else if you create 2x v12+ rooms in the same millisecond
// they will get the same room ID, clobbering internal data structures and causing extremely confusing
// behaviour. By adding this entropy, we ensure that even if rooms are created in the same millisecond, their
// hashes will not be the same.
"complement_entropy": util.RandomString(18),
}
// The creator field was removed in room version 11 (MSC4239).
n, err := strconv.Atoi(string(roomVer))
if err != nil || n < 11 {
content["creator"] = creator
}
return content
}(),
},
{
Type: "m.room.member",
Expand Down
8 changes: 7 additions & 1 deletion tests/csapi/rooms_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package csapi_tests

import (
"strconv"
"testing"
"time"

Expand All @@ -26,6 +27,8 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) {
LocalpartSuffix: "bob",
Password: "bobpassword",
})
defaultVer := alice.GetDefaultRoomVersion(t)
defaultVerN, _ := strconv.Atoi(string(defaultVer))
roomID := alice.MustCreateRoom(t, map[string]interface{}{})

t.Run("parallel", func(t *testing.T) {
Expand All @@ -38,7 +41,10 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) {
return false
}
must.Equal(t, ev.Get("sender").Str, alice.UserID, "wrong sender")
must.Equal(t, ev.Get("content").Get("creator").Str, alice.UserID, "wrong content.creator")
// The creator field was removed in room version 11 (MSC4239).
if defaultVerN < 11 {
must.Equal(t, ev.Get("content").Get("creator").Str, alice.UserID, "wrong content.creator")
}
return true
}))
})
Expand Down
17 changes: 17 additions & 0 deletions tests/federation_room_get_missing_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -497,6 +498,22 @@ func TestOutboundFederationEventSizeGetMissingEvents(t *testing.T) {
}).Methods("POST")

ver := alice.GetDefaultRoomVersion(t)
// This test crafts a "bad" event which state_key is 280 bytes but only 70
// codepoints.
//
// Room version 11 in Synapse switched from using codepoints to using
// bytes. Which means the 280-byte state_key would be rejected immediately.
// Use room version 10 in that case so the codepoint-based limit is in effect.
//
// Since upgrading a room (for example from v10 to v11) won't carry the event
// (a new room is created), we don't have to worry about v10 room events in a v11
// room.
//
// So this test is essentially skipped for any default room v11 or higher.
verNum, _ := strconv.Atoi(string(ver))
if verNum >= 11 {
ver = gomatrixserverlib.RoomVersion("10")
}
charlie := srv.UserID("charlie")
room := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, charlie))
roomAlias := srv.MakeAliasMapping("flibble", room.RoomID)
Expand Down
Loading