diff --git a/federation/server_room.go b/federation/server_room.go index 61c40ed3..fd02e720 100644 --- a/federation/server_room.go +++ b/federation/server_room.go @@ -333,15 +333,20 @@ 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), + } + if gomatrixserverlib.MustGetRoomVersion(gomatrixserverlib.RoomVersion(roomVer)).CreatorInCreateEvent() { + content["creator"] = creator + } + return content + }(), }, { Type: "m.room.member", diff --git a/tests/csapi/rooms_state_test.go b/tests/csapi/rooms_state_test.go index 2158cae1..4f2a5451 100644 --- a/tests/csapi/rooms_state_test.go +++ b/tests/csapi/rooms_state_test.go @@ -15,6 +15,7 @@ import ( "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" + "github.com/matrix-org/gomatrixserverlib" ) func TestRoomCreationReportsEventsToMyself(t *testing.T) { @@ -26,6 +27,7 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) { LocalpartSuffix: "bob", Password: "bobpassword", }) + defaultVer := alice.GetDefaultRoomVersion(t) roomID := alice.MustCreateRoom(t, map[string]interface{}{}) t.Run("parallel", func(t *testing.T) { @@ -38,7 +40,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 gomatrixserverlib.MustGetRoomVersion(defaultVer).CreatorInCreateEvent() { + must.Equal(t, ev.Get("content").Get("creator").Str, alice.UserID, "wrong content.creator") + } return true })) }) diff --git a/tests/federation_room_get_missing_events_test.go b/tests/federation_room_get_missing_events_test.go index 9899f88b..8b6ef0d8 100644 --- a/tests/federation_room_get_missing_events_test.go +++ b/tests/federation_room_get_missing_events_test.go @@ -497,6 +497,21 @@ 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. + if gomatrixserverlib.MustGetRoomVersion(ver).StrictEventByteLimits() { + ver = gomatrixserverlib.RoomVersion("10") + } charlie := srv.UserID("charlie") room := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, charlie)) roomAlias := srv.MakeAliasMapping("flibble", room.RoomID)