Skip to content

Commit 343f4f0

Browse files
author
David Robertson
authored
Use stable identifiers for faster joins (#583)
* Use stable identifiers for faster joins * Pull in corresponding GMSL changes ``` $ go get -u github.com/matrix-org/gomatrixserverlib@dmr/msc-3706-stable-identifiers go: downloading github.com/matrix-org/gomatrixserverlib v0.0.0-20230112185427-4f65e88d2a5b go: downloading golang.org/x/crypto v0.5.0 go: downloading github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530 go: downloading github.com/matrix-org/util v0.0.0-20221111132719-399730281e66 go: downloading github.com/tidwall/gjson v1.14.4 go: downloading golang.org/x/sys v0.4.0 go: downloading github.com/tidwall/pretty v1.2.1 go: downloading golang.org/x/text v0.6.0 go: downloading golang.org/x/net v0.5.0 go: downloading golang.org/x/tools v0.1.12 go: downloading github.com/miekg/dns v1.1.50 go: downloading gopkg.in/h2non/gock.v1 v1.1.2 go: downloading github.com/stretchr/testify v1.8.0 go: upgraded github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16 => v0.0.0-20220926102614-ceba4d9f7530 go: upgraded github.com/matrix-org/gomatrixserverlib v0.0.0-20220830164018-c71e518537a2 => v0.0.0-20230112185427-4f65e88d2a5b go: upgraded github.com/matrix-org/util v0.0.0-20200807132607-55161520e1d4 => v0.0.0-20221111132719-399730281e66 go: upgraded github.com/tidwall/gjson v1.14.3 => v1.14.4 go: upgraded github.com/tidwall/pretty v1.2.0 => v1.2.1 go: upgraded golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 => v0.5.0 go: upgraded golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 => v0.5.0 go: upgraded golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 => v0.4.0 go: upgraded golang.org/x/tools v0.1.9 => v0.1.12 go: upgraded gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b => v3.0.1 ``` * Adapt to GMSL secondary server names change See matrix-org/gomatrixserverlib#344 AFAICS passing nil means that the server isn't going to accept any vhosting shenanigans. * GMSL signing identity changes matrix-org/gomatrixserverlib@900369e * More `origin` arguments there's probably a neater way to not write `gomatrixserverlib.ServerName` but idk what the best thing to do is here. * And some more that I missed due to build tags * Need to call ServerName() after Listen() * Update to GMSL PR changes * And another one I missed * And another one I missed missed this one because struct fields are optional(?) * Use main branch of GMSL * Fix bad git hygiene
1 parent 83bb180 commit 343f4f0

10 files changed

+126
-46
lines changed

go.mod

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,24 @@ require (
1111
github.com/docker/go-units v0.4.0 // indirect
1212
github.com/gogo/protobuf v1.3.2 // indirect
1313
github.com/gorilla/mux v1.8.0
14-
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16
15-
github.com/matrix-org/gomatrixserverlib v0.0.0-20220830164018-c71e518537a2
16-
github.com/matrix-org/util v0.0.0-20200807132607-55161520e1d4
14+
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
15+
github.com/matrix-org/gomatrix v0.0.0-20220926102614-ceba4d9f7530
16+
github.com/matrix-org/gomatrixserverlib v0.0.0-20230113181222-67e060196d05
17+
github.com/matrix-org/util v0.0.0-20221111132719-399730281e66
1718
github.com/moby/term v0.0.0-20210610120745-9d4ed1856297 // indirect
1819
github.com/morikuni/aec v1.0.0 // indirect
1920
github.com/opencontainers/go-digest v1.0.0 // indirect
2021
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
2122
github.com/sirupsen/logrus v1.9.0
22-
github.com/tidwall/gjson v1.14.3
23+
github.com/tidwall/gjson v1.14.4
24+
github.com/tidwall/pretty v1.2.1 // indirect
2325
github.com/tidwall/sjson v1.2.5
24-
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
26+
golang.org/x/crypto v0.5.0 // indirect
2527
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6 // indirect
2628
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 // indirect
27-
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2 // indirect
28-
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect
2929
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
30-
golang.org/x/tools v0.1.9
30+
golang.org/x/tools v0.1.12
3131
gonum.org/v1/plot v0.11.0
32-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
3332
gotest.tools/v3 v3.0.3 // indirect
3433
maunium.net/go/mautrix v0.11.0
3534
)

go.sum

Lines changed: 64 additions & 0 deletions
Large diffs are not rendered by default.

internal/federation/handle.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
func MakeJoinRequestsHandler(s *Server, w http.ResponseWriter, req *http.Request) {
1919
// Check federation signature
2020
fedReq, errResp := gomatrixserverlib.VerifyHTTPRequest(
21-
req, time.Now(), gomatrixserverlib.ServerName(s.serverName), s.keyRing,
21+
req, time.Now(), gomatrixserverlib.ServerName(s.serverName), nil, s.keyRing,
2222
)
2323
if fedReq == nil {
2424
w.WriteHeader(errResp.Code)
@@ -125,7 +125,7 @@ func MakeRespMakeKnock(s *Server, room *ServerRoom, userID string) (resp gomatri
125125
// the current server is returned to the joining server.
126126
func SendJoinRequestsHandler(s *Server, w http.ResponseWriter, req *http.Request, expectPartialState bool, omitServersInRoom bool) {
127127
fedReq, errResp := gomatrixserverlib.VerifyHTTPRequest(
128-
req, time.Now(), gomatrixserverlib.ServerName(s.serverName), s.keyRing,
128+
req, time.Now(), gomatrixserverlib.ServerName(s.serverName), nil, s.keyRing,
129129
)
130130
if fedReq == nil {
131131
w.WriteHeader(errResp.Code)
@@ -136,7 +136,7 @@ func SendJoinRequestsHandler(s *Server, w http.ResponseWriter, req *http.Request
136136

137137
// if we expect a partial-state join, the request should have a "partial_state" flag
138138
queryParams := req.URL.Query()
139-
partialState := queryParams.Get("org.matrix.msc3706.partial_state")
139+
partialState := queryParams.Get("omit_members")
140140
if expectPartialState && partialState != "true" {
141141
log.Printf("Not a partial-state request: got %v, want %s",
142142
partialState, "true")
@@ -187,11 +187,11 @@ func SendJoinRequestsHandler(s *Server, w http.ResponseWriter, req *http.Request
187187

188188
// return state and auth chain
189189
b, err := json.Marshal(gomatrixserverlib.RespSendJoin{
190-
Origin: gomatrixserverlib.ServerName(s.serverName),
191-
AuthEvents: gomatrixserverlib.NewEventJSONsFromEvents(authEvents),
192-
StateEvents: gomatrixserverlib.NewEventJSONsFromEvents(stateEvents),
193-
PartialState: expectPartialState,
194-
ServersInRoom: serversInRoom,
190+
Origin: gomatrixserverlib.ServerName(s.serverName),
191+
AuthEvents: gomatrixserverlib.NewEventJSONsFromEvents(authEvents),
192+
StateEvents: gomatrixserverlib.NewEventJSONsFromEvents(stateEvents),
193+
MembersOmitted: expectPartialState,
194+
ServersInRoom: serversInRoom,
195195
})
196196
if err != nil {
197197
w.WriteHeader(500)
@@ -238,7 +238,7 @@ func HandleInviteRequests(inviteCallback func(*gomatrixserverlib.Event)) func(*S
238238
// https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v2-invite-roomid-eventid
239239
s.mux.Handle("/_matrix/federation/v2/invite/{roomID}/{eventID}", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
240240
fedReq, errResp := gomatrixserverlib.VerifyHTTPRequest(
241-
req, time.Now(), gomatrixserverlib.ServerName(s.serverName), s.keyRing,
241+
req, time.Now(), gomatrixserverlib.ServerName(s.serverName), nil, s.keyRing,
242242
)
243243
if fedReq == nil {
244244
w.WriteHeader(errResp.Code)
@@ -491,7 +491,7 @@ func HandleTransactionRequests(pduCallback func(*gomatrixserverlib.Event), eduCa
491491

492492
// Check federation signature
493493
fedReq, errResp := gomatrixserverlib.VerifyHTTPRequest(
494-
req, time.Now(), gomatrixserverlib.ServerName(srv.serverName), srv.keyRing,
494+
req, time.Now(), gomatrixserverlib.ServerName(srv.serverName), nil, srv.keyRing,
495495
)
496496
if fedReq == nil {
497497
log.Printf(

internal/federation/server.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,13 @@ func (s *Server) FederationClient(deployment *docker.Deployment) *gomatrixserver
186186
if !s.listening {
187187
s.t.Fatalf("FederationClient() called before Listen() - this is not supported because Listen() chooses a high-numbered port and thus changes the server name and thus changes the way federation requests are signed. Ensure you Listen() first!")
188188
}
189+
identity := gomatrixserverlib.SigningIdentity{
190+
ServerName: gomatrixserverlib.ServerName(s.ServerName()),
191+
KeyID: s.KeyID,
192+
PrivateKey: s.Priv,
193+
}
189194
f := gomatrixserverlib.NewFederationClient(
190-
gomatrixserverlib.ServerName(s.serverName), s.KeyID, s.Priv,
195+
[]*gomatrixserverlib.SigningIdentity{&identity},
191196
gomatrixserverlib.WithTransport(&docker.RoundTripper{Deployment: deployment}),
192197
)
193198
return f
@@ -336,17 +341,18 @@ func (s *Server) MustCreateEvent(t *testing.T, room *ServerRoom, ev b.Event) *go
336341
// It returns the resultant room.
337342
func (s *Server) MustJoinRoom(t *testing.T, deployment *docker.Deployment, remoteServer gomatrixserverlib.ServerName, roomID string, userID string) *ServerRoom {
338343
t.Helper()
344+
origin := gomatrixserverlib.ServerName(s.serverName)
339345
fedClient := s.FederationClient(deployment)
340-
makeJoinResp, err := fedClient.MakeJoin(context.Background(), remoteServer, roomID, userID, SupportedRoomVersions())
346+
makeJoinResp, err := fedClient.MakeJoin(context.Background(), origin, remoteServer, roomID, userID, SupportedRoomVersions())
341347
if err != nil {
342348
t.Fatalf("MustJoinRoom: make_join failed: %v", err)
343349
}
344350
roomVer := makeJoinResp.RoomVersion
345-
joinEvent, err := makeJoinResp.JoinEvent.Build(time.Now(), gomatrixserverlib.ServerName(s.serverName), s.KeyID, s.Priv, roomVer)
351+
joinEvent, err := makeJoinResp.JoinEvent.Build(time.Now(), origin, s.KeyID, s.Priv, roomVer)
346352
if err != nil {
347353
t.Fatalf("MustJoinRoom: failed to sign event: %v", err)
348354
}
349-
sendJoinResp, err := fedClient.SendJoin(context.Background(), gomatrixserverlib.ServerName(remoteServer), joinEvent)
355+
sendJoinResp, err := fedClient.SendJoin(context.Background(), origin, remoteServer, joinEvent)
350356
if err != nil {
351357
t.Fatalf("MustJoinRoom: send_join failed: %v", err)
352358
}
@@ -366,17 +372,18 @@ func (s *Server) MustJoinRoom(t *testing.T, deployment *docker.Deployment, remot
366372
// Leaves a room. If this is rejecting an invite then a make_leave request is made first, before send_leave.
367373
func (s *Server) MustLeaveRoom(t *testing.T, deployment *docker.Deployment, remoteServer gomatrixserverlib.ServerName, roomID string, userID string) {
368374
t.Helper()
375+
origin := gomatrixserverlib.ServerName(s.serverName)
369376
fedClient := s.FederationClient(deployment)
370377
var leaveEvent *gomatrixserverlib.Event
371378
room := s.rooms[roomID]
372379
if room == nil {
373380
// e.g rejecting an invite
374-
makeLeaveResp, err := fedClient.MakeLeave(context.Background(), remoteServer, roomID, userID)
381+
makeLeaveResp, err := fedClient.MakeLeave(context.Background(), origin, remoteServer, roomID, userID)
375382
if err != nil {
376383
t.Fatalf("MustLeaveRoom: (rejecting invite) make_leave failed: %v", err)
377384
}
378385
roomVer := makeLeaveResp.RoomVersion
379-
leaveEvent, err = makeLeaveResp.LeaveEvent.Build(time.Now(), gomatrixserverlib.ServerName(s.serverName), s.KeyID, s.Priv, roomVer)
386+
leaveEvent, err = makeLeaveResp.LeaveEvent.Build(time.Now(), origin, s.KeyID, s.Priv, roomVer)
380387
if err != nil {
381388
t.Fatalf("MustLeaveRoom: (rejecting invite) failed to sign event: %v", err)
382389
}
@@ -391,7 +398,7 @@ func (s *Server) MustLeaveRoom(t *testing.T, deployment *docker.Deployment, remo
391398
},
392399
})
393400
}
394-
err := fedClient.SendLeave(context.Background(), gomatrixserverlib.ServerName(remoteServer), leaveEvent)
401+
err := fedClient.SendLeave(context.Background(), origin, remoteServer, leaveEvent)
395402
if err != nil {
396403
t.Fatalf("MustLeaveRoom: send_leave failed: %v", err)
397404
}
@@ -407,7 +414,7 @@ func (s *Server) ValidFederationRequest(t *testing.T, handler func(fr *gomatrixs
407414
return func(w http.ResponseWriter, req *http.Request) {
408415
// Check federation signature
409416
fedReq, errResp := gomatrixserverlib.VerifyHTTPRequest(
410-
req, time.Now(), gomatrixserverlib.ServerName(s.serverName), s.keyRing,
417+
req, time.Now(), gomatrixserverlib.ServerName(s.serverName), nil, s.keyRing,
411418
)
412419
if fedReq == nil {
413420
t.Errorf(

tests/direct_messaging_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func TestIsDirectFlagFederation(t *testing.T) {
138138
t.Fatalf("failed to make invite request: %s", err)
139139
}
140140
_, since := alice.MustSync(t, client.SyncReq{})
141-
_, err = srv.FederationClient(deployment).SendInviteV2(context.Background(), "hs1", inviteReq)
141+
_, err = srv.FederationClient(deployment).SendInviteV2(context.Background(), gomatrixserverlib.ServerName(srv.ServerName()), "hs1", inviteReq)
142142
if err != nil {
143143
t.Fatalf("failed to send invite v2: %s", err)
144144
}

tests/federation_event_auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestEventAuth(t *testing.T) {
7777
getEventAuth := func(t *testing.T, eventID string, wantAuthEventIDs []string) {
7878
t.Helper()
7979
t.Logf("/event_auth for %s - want %v", eventID, wantAuthEventIDs)
80-
eventAuthResp, err := srv.FederationClient(deployment).GetEventAuth(context.Background(), "hs1", room.Version, roomID, eventID)
80+
eventAuthResp, err := srv.FederationClient(deployment).GetEventAuth(context.Background(), gomatrixserverlib.ServerName(srv.ServerName()), "hs1", room.Version, roomID, eventID)
8181
must.NotError(t, "failed to /event_auth", err)
8282
if len(eventAuthResp.AuthEvents) == 0 {
8383
t.Fatalf("/event_auth returned 0 auth events")

tests/federation_query_profile_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ func TestInboundFederationProfile(t *testing.T) {
7979
)
8080
cancel := srv.Listen()
8181
defer cancel()
82+
origin := gomatrixserverlib.ServerName(srv.ServerName())
8283

8384
// sytest: Non-numeric ports in server names are rejected
8485
t.Run("Non-numeric ports in server names are rejected", func(t *testing.T) {
8586
fedReq := gomatrixserverlib.NewFederationRequest(
8687
"GET",
88+
origin,
8789
"hs1",
8890
"/_matrix/federation/v1/query/profile"+
8991
"?user_id=@user1:localhost:http"+
@@ -114,6 +116,7 @@ func TestInboundFederationProfile(t *testing.T) {
114116

115117
fedReq := gomatrixserverlib.NewFederationRequest(
116118
"GET",
119+
origin,
117120
"hs1",
118121
"/_matrix/federation/v1/query/profile"+
119122
"?user_id=@alice:hs1"+

tests/federation_room_get_missing_events_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ func TestOutboundFederationIgnoresMissingEventWithBadJSONForRoomVersion6(t *test
261261
fedClient := srv.FederationClient(deployment)
262262
resp, err := fedClient.SendTransaction(context.Background(), gomatrixserverlib.Transaction{
263263
TransactionID: "wut",
264+
Origin: gomatrixserverlib.ServerName(srv.ServerName()),
264265
Destination: gomatrixserverlib.ServerName("hs1"),
265266
PDUs: []json.RawMessage{
266267
sentEvent.JSON(),
@@ -306,6 +307,7 @@ func TestOutboundFederationIgnoresMissingEventWithBadJSONForRoomVersion6(t *test
306307

307308
resp, err = fedClient.SendTransaction(context.Background(), gomatrixserverlib.Transaction{
308309
TransactionID: "t2",
310+
Origin: gomatrixserverlib.ServerName(srv.ServerName()),
309311
Destination: gomatrixserverlib.ServerName("hs1"),
310312
PDUs: []json.RawMessage{
311313
message3.JSON(),
@@ -367,7 +369,10 @@ func TestInboundCanReturnMissingEvents(t *testing.T) {
367369
room := srv.MustJoinRoom(t, deployment, "hs1", roomID, charlie)
368370
alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(charlie, roomID))
369371

370-
req := gomatrixserverlib.NewFederationRequest("POST", "hs1",
372+
req := gomatrixserverlib.NewFederationRequest(
373+
"POST",
374+
gomatrixserverlib.ServerName(srv.ServerName()),
375+
"hs1",
371376
fmt.Sprintf("/_matrix/federation/v1/get_missing_events/%s", roomID),
372377
)
373378

tests/federation_room_join_partial_state_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,7 @@ func TestPartialStateJoin(t *testing.T) {
15601560
fedClient2 := testServer2.FederationClient(deployment)
15611561

15621562
// charlie sends a make_join
1563-
_, err := fedClient2.MakeJoin(context.Background(), "hs1", roomID, testServer2.UserID("charlie"), federation.SupportedRoomVersions())
1563+
_, err := fedClient2.MakeJoin(context.Background(), gomatrixserverlib.ServerName(testServer2.ServerName()), "hs1", roomID, testServer2.UserID("charlie"), federation.SupportedRoomVersions())
15641564

15651565
if err == nil {
15661566
t.Errorf("MakeJoin returned 200, want 404")
@@ -1627,7 +1627,7 @@ func TestPartialStateJoin(t *testing.T) {
16271627

16281628
// SendJoin should return a 404 because the homeserver under test has not
16291629
// finished its partial join.
1630-
_, err = fedClient2.SendJoin(context.Background(), "hs1", joinEvent)
1630+
_, err = fedClient2.SendJoin(context.Background(), gomatrixserverlib.ServerName(testServer2.ServerName()), "hs1", joinEvent)
16311631
if err == nil {
16321632
t.Errorf("SendJoin returned 200, want 404")
16331633
} else if httpError, ok := err.(gomatrix.HTTPError); ok {
@@ -1733,7 +1733,7 @@ func TestPartialStateJoin(t *testing.T) {
17331733
fedClient2 := testServer2.FederationClient(deployment)
17341734

17351735
// charlie sends a make_knock
1736-
_, err := fedClient2.MakeKnock(context.Background(), "hs1", roomID, testServer2.UserID("charlie"), federation.SupportedRoomVersions())
1736+
_, err := fedClient2.MakeKnock(context.Background(), gomatrixserverlib.ServerName(testServer2.ServerName()), "hs1", roomID, testServer2.UserID("charlie"), federation.SupportedRoomVersions())
17371737

17381738
if err == nil {
17391739
t.Errorf("MakeKnock returned 200, want 404")
@@ -1800,7 +1800,7 @@ func TestPartialStateJoin(t *testing.T) {
18001800

18011801
// SendKnock should return a 404 because the homeserver under test has not
18021802
// finished its partial join.
1803-
_, err = fedClient2.SendKnock(context.Background(), "hs1", knockEvent)
1803+
_, err = fedClient2.SendKnock(context.Background(), gomatrixserverlib.ServerName(testServer2.ServerName()), "hs1", knockEvent)
18041804
if err == nil {
18051805
t.Errorf("SendKnock returned 200, want 404")
18061806
} else if httpError, ok := err.(gomatrix.HTTPError); ok {
@@ -3323,7 +3323,7 @@ func testReceiveEventDuringPartialStateJoin(
33233323
// is resolved. For now, we use this to check whether Synapse has calculated the partial state
33243324
// flag for the last event correctly.
33253325

3326-
stateReq := gomatrixserverlib.NewFederationRequest("GET", "hs1",
3326+
stateReq := gomatrixserverlib.NewFederationRequest("GET", gomatrixserverlib.ServerName(psjResult.Server.ServerName()), "hs1",
33273327
fmt.Sprintf("/_matrix/federation/v1/state_ids/%s?event_id=%s",
33283328
url.PathEscape(psjResult.ServerRoom.RoomID),
33293329
url.QueryEscape(event.EventID()),
@@ -3367,7 +3367,7 @@ func testReceiveEventDuringPartialStateJoin(
33673367
)
33683368

33693369
// check the server's idea of the state at the event. We do this by making a `state_ids` request over federation
3370-
stateReq = gomatrixserverlib.NewFederationRequest("GET", "hs1",
3370+
stateReq = gomatrixserverlib.NewFederationRequest("GET", gomatrixserverlib.ServerName(psjResult.Server.ServerName()), "hs1",
33713371
fmt.Sprintf("/_matrix/federation/v1/state_ids/%s?event_id=%s",
33723372
url.PathEscape(psjResult.ServerRoom.RoomID),
33733373
url.QueryEscape(event.EventID()),

tests/federation_room_join_test.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ func TestBannedUserCannotSendJoin(t *testing.T) {
267267
federation.HandleTransactionRequests(nil, nil),
268268
)
269269
cancel := srv.Listen()
270+
origin := gomatrixserverlib.ServerName(srv.ServerName())
270271
defer cancel()
271272

272273
fedClient := srv.FederationClient(deployment)
@@ -289,7 +290,7 @@ func TestBannedUserCannotSendJoin(t *testing.T) {
289290
})
290291

291292
// charlie sends a make_join for a different user
292-
makeJoinResp, err := fedClient.MakeJoin(context.Background(), "hs1", roomID, srv.UserID("charlie2"), federation.SupportedRoomVersions())
293+
makeJoinResp, err := fedClient.MakeJoin(context.Background(), origin, "hs1", roomID, srv.UserID("charlie2"), federation.SupportedRoomVersions())
293294
must.NotError(t, "MakeJoin", err)
294295

295296
// ... and does a switcheroo to turn it into a join for himself
@@ -299,7 +300,7 @@ func TestBannedUserCannotSendJoin(t *testing.T) {
299300
must.NotError(t, "JoinEvent.Build", err)
300301

301302
// SendJoin should return a 403.
302-
_, err = fedClient.SendJoin(context.Background(), "hs1", joinEvent)
303+
_, err = fedClient.SendJoin(context.Background(), origin, "hs1", joinEvent)
303304
if err == nil {
304305
t.Errorf("SendJoin returned 200, want 403")
305306
} else if httpError, ok := err.(gomatrix.HTTPError); ok {
@@ -380,7 +381,7 @@ func testValidationForSendMembershipEndpoint(t *testing.T, baseApiPath, expected
380381
url.PathEscape(event.EventID()),
381382
)
382383
t.Logf("PUT %s", path)
383-
req := gomatrixserverlib.NewFederationRequest("PUT", "hs1", path)
384+
req := gomatrixserverlib.NewFederationRequest("PUT", gomatrixserverlib.ServerName(srv.ServerName()), "hs1", path)
384385
if err := req.SetContent(event); err != nil {
385386
t.Errorf("req.SetContent: %v", err)
386387
return
@@ -469,6 +470,7 @@ func TestSendJoinPartialStateResponse(t *testing.T) {
469470
)
470471
cancel := srv.Listen()
471472
defer cancel()
473+
origin := gomatrixserverlib.ServerName(srv.ServerName())
472474

473475
// annoyingly we can't get to the room that alice and bob already share (see https://github.com/matrix-org/complement/issues/254)
474476
// so we have to create a new one.
@@ -481,25 +483,25 @@ func TestSendJoinPartialStateResponse(t *testing.T) {
481483
// now we send a make_join...
482484
charlie := srv.UserID("charlie")
483485
fedClient := srv.FederationClient(deployment)
484-
makeJoinResp, err := fedClient.MakeJoin(context.Background(), "hs1", roomID, charlie, federation.SupportedRoomVersions())
486+
makeJoinResp, err := fedClient.MakeJoin(context.Background(), origin, "hs1", roomID, charlie, federation.SupportedRoomVersions())
485487
if err != nil {
486488
t.Fatalf("make_join failed: %v", err)
487489
}
488490

489491
// ... construct a signed join event ...
490492
roomVer := makeJoinResp.RoomVersion
491-
joinEvent, err := makeJoinResp.JoinEvent.Build(time.Now(), gomatrixserverlib.ServerName(srv.ServerName()), srv.KeyID, srv.Priv, roomVer)
493+
joinEvent, err := makeJoinResp.JoinEvent.Build(time.Now(), origin, srv.KeyID, srv.Priv, roomVer)
492494
if err != nil {
493495
t.Fatalf("failed to sign join event: %v", err)
494496
}
495497

496498
// and send_join it, with the magic param
497-
sendJoinResp, err := fedClient.SendJoinPartialState(context.Background(), "hs1", joinEvent)
499+
sendJoinResp, err := fedClient.SendJoinPartialState(context.Background(), origin, "hs1", joinEvent)
498500
if err != nil {
499501
t.Fatalf("send_join failed: %v", err)
500502
}
501503

502-
if !sendJoinResp.PartialState {
504+
if !sendJoinResp.MembersOmitted {
503505
t.Skip("Server does not support partial_state")
504506
}
505507

@@ -519,16 +521,16 @@ func TestSendJoinPartialStateResponse(t *testing.T) {
519521
})
520522

521523
// check the returned auth events match those expected.
522-
// Now that we include heroes in the partial join response,
523-
// all of the events are included under "state" and so we don't expect any
524+
// Now that we include heroes in the partial join response,
525+
// all of the events are included under "state" and so we don't expect any
524526
// extra auth_events.
525527
// TODO: add in a second e.g. power_levels event so that we add stuff to the
526528
// auth chain.
527529
var returnedAuthEventKeys []interface{}
528530
for _, ev := range sendJoinResp.AuthEvents {
529531
returnedAuthEventKeys = append(returnedAuthEventKeys, typeAndStateKeyForEvent(gjson.ParseBytes(ev)))
530532
}
531-
must.CheckOffAll(t, returnedAuthEventKeys, []interface{}{ })
533+
must.CheckOffAll(t, returnedAuthEventKeys, []interface{}{})
532534

533535
// check the server list. Only one, so we can use HaveInOrder even though the list is unordered
534536
must.HaveInOrder(t, sendJoinResp.ServersInRoom, []string{"hs1"})

0 commit comments

Comments
 (0)