-
Notifications
You must be signed in to change notification settings - Fork 48
/
federation_room_join_test.go
76 lines (65 loc) · 2.87 KB
/
federation_room_join_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package tests
import (
"net/http"
"net/url"
"testing"
"github.com/matrix-org/complement/internal/b"
"github.com/matrix-org/complement/internal/federation"
"github.com/matrix-org/complement/internal/match"
"github.com/matrix-org/complement/internal/must"
"github.com/matrix-org/gomatrixserverlib"
)
// This tests that joining a room with ?server_name= works correctly.
// It does this by creating a room on the Complement server and joining HS1 to it.
// The Complement server then begins to refuse make/send_join requests and HS2 is
// asked to join the room ID with the ?server_name=HS1. We need to make sure that
// the HS is not just extracting the domain from the room ID and joining via that,
// hence the refusal for make/send_join on the Complement server.
// We can't use a bogus room ID domain either as auth checks on the
// m.room.create event would pick that up. We also can't tear down the Complement
// server because otherwise signing key lookups will fail.
func TestJoinViaRoomIDAndServerName(t *testing.T) {
deployment := Deploy(t, "federation_room_join", b.BlueprintFederationOneToOneRoom)
defer deployment.Destroy(t)
acceptMakeSendJoinRequests := true
srv := federation.NewServer(t, deployment,
federation.HandleKeyRequests(),
)
srv.UnexpectedRequestsAreErrors = false // we will be sent transactions but that's okay
cancel := srv.Listen()
defer cancel()
srv.Mux().Handle("/_matrix/federation/v1/make_join/{roomID}/{userID}", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if !acceptMakeSendJoinRequests {
w.WriteHeader(502)
return
}
federation.MakeJoinRequestsHandler(srv, w, req)
})).Methods("GET")
srv.Mux().Handle("/_matrix/federation/v2/send_join/{roomID}/{eventID}", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if !acceptMakeSendJoinRequests {
w.WriteHeader(502)
return
}
federation.SendJoinRequestsHandler(srv, w, req)
})).Methods("PUT")
ver := gomatrixserverlib.RoomVersionV5
charlie := srv.UserID("charlie")
serverRoom := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, charlie))
// join the room by room ID alone - the server will need to extract the domain for this to work.
alice := deployment.Client(t, "hs1", "@alice:hs1")
alice.JoinRoom(t, serverRoom.RoomID)
// remove the make/send join paths from the Complement server to force HS2 to join via HS1
acceptMakeSendJoinRequests = false
// join the room using ?server_name on HS2
bob := deployment.Client(t, "hs2", "@bob:hs2")
queryParams := url.Values{}
queryParams.Set("server_name", "hs1")
res, err := bob.DoWithAuthRaw(t, "POST", []string{"_matrix", "client", "r0", "join", serverRoom.RoomID}, nil, "application/json", queryParams)
must.NotError(t, "failed to join room", err)
must.MatchResponse(t, res, match.HTTPResponse{
StatusCode: 200,
JSON: []match.JSON{
match.JSONKeyEqual("room_id", serverRoom.RoomID),
},
})
}