Skip to content

Commit 5c13563

Browse files
authored
Use server's default room version to create new rooms (#269)
When we are creating a test room on the Complement server, use the same version as the server defaults to.
1 parent 34c9561 commit 5c13563

File tree

6 files changed

+43
-13
lines changed

6 files changed

+43
-13
lines changed

internal/client/client.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15+
"github.com/matrix-org/gomatrixserverlib"
1516
"github.com/tidwall/gjson"
1617

1718
"github.com/matrix-org/complement/internal/b"
@@ -243,6 +244,30 @@ func (c *CSAPI) RegisterUser(t *testing.T, localpart, password string) (userID,
243244
return userID, accessToken
244245
}
245246

247+
// GetCapbabilities queries the server's capabilities
248+
func (c *CSAPI) GetCapabilities(t *testing.T) []byte {
249+
t.Helper()
250+
res := c.MustDoFunc(t, "GET", []string{"_matrix", "client", "r0", "capabilities"})
251+
body, err := ioutil.ReadAll(res.Body)
252+
if err != nil {
253+
t.Fatalf("unable to read response body: %v", err)
254+
}
255+
return body
256+
}
257+
258+
// GetDefaultRoomVersion returns the server's default room version
259+
func (c *CSAPI) GetDefaultRoomVersion(t *testing.T) gomatrixserverlib.RoomVersion {
260+
t.Helper()
261+
capabilities := c.GetCapabilities(t)
262+
defaultVersion := gjson.GetBytes(capabilities, `capabilities.m\.room_versions.default`)
263+
if !defaultVersion.Exists() {
264+
// spec says use RoomV1 in this case
265+
return gomatrixserverlib.RoomVersionV1
266+
}
267+
268+
return gomatrixserverlib.RoomVersion(defaultVersion.Str)
269+
}
270+
246271
// MustDo will do the HTTP request and fail the test if the response is not 2xx
247272
//
248273
// Deprecated: Prefer MustDoFunc. MustDo is the older format which doesn't allow for vargs

internal/federation/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func (s *Server) MakeAliasMapping(aliasLocalpart, roomID string) string {
133133
// The `events` will be added to this room. Returns the created room.
134134
func (s *Server) MustMakeRoom(t *testing.T, roomVer gomatrixserverlib.RoomVersion, events []b.Event) *ServerRoom {
135135
roomID := fmt.Sprintf("!%d:%s", len(s.rooms), s.ServerName)
136+
t.Logf("Creating room %s with version %s", roomID, roomVer)
136137
room := newRoom(roomVer, roomID)
137138

138139
// sign all these events

tests/federation_room_get_missing_events_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ import (
3636
func TestOutboundFederationIgnoresMissingEventWithBadJSONForRoomVersion6(t *testing.T) {
3737
deployment := Deploy(t, b.BlueprintAlice)
3838
defer deployment.Destroy(t)
39+
40+
alice := deployment.Client(t, "hs1", "@alice:hs1")
41+
3942
srv := federation.NewServer(t, deployment,
4043
federation.HandleKeyRequests(),
4144
federation.HandleMakeSendJoinRequests(),
@@ -52,12 +55,11 @@ func TestOutboundFederationIgnoresMissingEventWithBadJSONForRoomVersion6(t *test
5255
onGetMissingEvents(w, req)
5356
}).Methods("POST")
5457

55-
ver := gomatrixserverlib.RoomVersionV6
58+
ver := alice.GetDefaultRoomVersion(t)
5659
charlie := srv.UserID("charlie")
5760
room := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, charlie))
5861
roomAlias := srv.MakeAliasMapping("flibble", room.RoomID)
5962
// join the room
60-
alice := deployment.Client(t, "hs1", "@alice:hs1")
6163
alice.JoinRoom(t, roomAlias, nil)
6264

6365
latestEvent := room.Timeline[len(room.Timeline)-1]

tests/federation_room_join_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func TestJoinViaRoomIDAndServerName(t *testing.T) {
3636
deployment := Deploy(t, b.BlueprintFederationOneToOneRoom)
3737
defer deployment.Destroy(t)
3838

39+
alice := deployment.Client(t, "hs1", "@alice:hs1")
40+
3941
acceptMakeSendJoinRequests := true
4042

4143
srv := federation.NewServer(t, deployment,
@@ -60,12 +62,11 @@ func TestJoinViaRoomIDAndServerName(t *testing.T) {
6062
federation.SendJoinRequestsHandler(srv, w, req)
6163
})).Methods("PUT")
6264

63-
ver := gomatrixserverlib.RoomVersionV5
65+
ver := alice.GetDefaultRoomVersion(t)
6466
charlie := srv.UserID("charlie")
6567
serverRoom := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, charlie))
6668

6769
// join the room by room ID, providing the serverName to join via
68-
alice := deployment.Client(t, "hs1", "@alice:hs1")
6970
alice.JoinRoom(t, serverRoom.RoomID, []string{srv.ServerName})
7071

7172
// remove the make/send join paths from the Complement server to force HS2 to join via HS1
@@ -101,6 +102,8 @@ func TestJoinFederatedRoomWithUnverifiableEvents(t *testing.T) {
101102
deployment := Deploy(t, b.BlueprintAlice)
102103
defer deployment.Destroy(t)
103104

105+
alice := deployment.Client(t, "hs1", "@alice:hs1")
106+
104107
srv := federation.NewServer(t, deployment,
105108
federation.HandleKeyRequests(),
106109
federation.HandleMakeSendJoinRequests(),
@@ -110,7 +113,7 @@ func TestJoinFederatedRoomWithUnverifiableEvents(t *testing.T) {
110113
cancel := srv.Listen()
111114
defer cancel()
112115

113-
ver := gomatrixserverlib.RoomVersionV6
116+
ver := alice.GetDefaultRoomVersion(t)
114117
charlie := srv.UserID("charlie")
115118

116119
// We explicitly do not run these in parallel in order to help debugging when these
@@ -135,7 +138,6 @@ func TestJoinFederatedRoomWithUnverifiableEvents(t *testing.T) {
135138
unsignedEvent, err := gomatrixserverlib.NewEventFromTrustedJSON(raw, false, ver)
136139
must.NotError(t, "failed to make Event from unsigned event JSON", err)
137140
room.AddEvent(unsignedEvent)
138-
alice := deployment.Client(t, "hs1", "@alice:hs1")
139141
alice.JoinRoom(t, roomAlias, nil)
140142
})
141143
t.Run("/send_join response with bad signatures shouldn't block room join", func(t *testing.T) {
@@ -164,7 +166,6 @@ func TestJoinFederatedRoomWithUnverifiableEvents(t *testing.T) {
164166
unsignedEvent, err := gomatrixserverlib.NewEventFromTrustedJSON(raw, false, ver)
165167
must.NotError(t, "failed to make Event from unsigned event JSON", err)
166168
room.AddEvent(unsignedEvent)
167-
alice := deployment.Client(t, "hs1", "@alice:hs1")
168169
alice.JoinRoom(t, roomAlias, nil)
169170
})
170171
t.Run("/send_join response with unobtainable keys shouldn't block room join", func(t *testing.T) {
@@ -194,7 +195,6 @@ func TestJoinFederatedRoomWithUnverifiableEvents(t *testing.T) {
194195
unsignedEvent, err := gomatrixserverlib.NewEventFromTrustedJSON(raw, false, ver)
195196
must.NotError(t, "failed to make Event from unsigned event JSON", err)
196197
room.AddEvent(unsignedEvent)
197-
alice := deployment.Client(t, "hs1", "@alice:hs1")
198198
alice.JoinRoom(t, roomAlias, nil)
199199
})
200200
t.Run("/send_join response with state with unverifiable auth events shouldn't block room join", func(t *testing.T) {
@@ -248,7 +248,6 @@ func TestJoinFederatedRoomWithUnverifiableEvents(t *testing.T) {
248248
room.AddEvent(goodEvent)
249249
t.Logf("Created state event %s", goodEvent.EventID())
250250

251-
alice := deployment.Client(t, "hs1", "@alice:hs1")
252251
alice.JoinRoom(t, roomAlias, nil)
253252
})
254253
}

tests/federation_room_send_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ func TestOutboundFederationSend(t *testing.T) {
2222
deployment := Deploy(t, b.BlueprintAlice)
2323
defer deployment.Destroy(t)
2424

25+
alice := deployment.Client(t, "hs1", "@alice:hs1")
26+
2527
waiter := NewWaiter()
2628
wantEventType := "m.room.message"
2729

@@ -45,13 +47,12 @@ func TestOutboundFederationSend(t *testing.T) {
4547
defer cancel()
4648

4749
// the remote homeserver creates a public room
48-
ver := gomatrixserverlib.RoomVersionV5
50+
ver := alice.GetDefaultRoomVersion(t)
4951
charlie := srv.UserID("charlie")
5052
serverRoom := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, charlie))
5153
roomAlias := srv.MakeAliasMapping("flibble", serverRoom.RoomID)
5254

5355
// the local homeserver joins the room
54-
alice := deployment.Client(t, "hs1", "@alice:hs1")
5556
alice.JoinRoom(t, roomAlias, []string{docker.HostnameRunningComplement})
5657

5758
// the local homeserver sends an event into the room

tests/msc2836_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ func TestEventRelationships(t *testing.T) {
187187
func TestFederatedEventRelationships(t *testing.T) {
188188
deployment := Deploy(t, b.BlueprintAlice)
189189
defer deployment.Destroy(t)
190+
191+
alice := deployment.Client(t, "hs1", "@alice:hs1")
192+
190193
srv := federation.NewServer(t, deployment,
191194
federation.HandleKeyRequests(),
192195
federation.HandleMakeSendJoinRequests(),
@@ -195,7 +198,7 @@ func TestFederatedEventRelationships(t *testing.T) {
195198
defer cancel()
196199

197200
// create a room on Complement, add some events to walk.
198-
roomVer := gomatrixserverlib.RoomVersionV6
201+
roomVer := alice.GetDefaultRoomVersion(t)
199202
charlie := srv.UserID("charlie")
200203
room := srv.MustMakeRoom(t, roomVer, federation.InitialRoomEvents(roomVer, charlie))
201204
eventA := srv.MustCreateEvent(t, room, b.Event{
@@ -293,7 +296,6 @@ func TestFederatedEventRelationships(t *testing.T) {
293296

294297
// join the room on HS1
295298
// HS1 will not have any of these messages, only the room state.
296-
alice := deployment.Client(t, "hs1", "@alice:hs1")
297299
alice.JoinRoom(t, room.RoomID, []string{srv.ServerName})
298300

299301
// send a new child in the thread (child of D) so the HS has something to latch on to.

0 commit comments

Comments
 (0)