diff --git a/client/client.go b/client/client.go index 7f281de0..26c80807 100644 --- a/client/client.go +++ b/client/client.go @@ -18,6 +18,7 @@ import ( "time" "github.com/matrix-org/gomatrixserverlib" + "github.com/matrix-org/gomatrixserverlib/spec" "github.com/tidwall/gjson" "golang.org/x/crypto/curve25519" @@ -139,7 +140,11 @@ func (c *CSAPI) CreateRoom(t ct.TestLike, body map[string]interface{}) *http.Res } // MustJoinRoom joins the room ID or alias given, else fails the test. Returns the room ID. -func (c *CSAPI) MustJoinRoom(t ct.TestLike, roomIDOrAlias string, serverNames []string) string { +// +// Args: +// - `serverNames`: The list of servers to attempt to join the room through. +// These should be a resolvable addresses within the deployment network. +func (c *CSAPI) MustJoinRoom(t ct.TestLike, roomIDOrAlias string, serverNames []spec.ServerName) string { t.Helper() res := c.JoinRoom(t, roomIDOrAlias, serverNames) mustRespond2xx(t, res) @@ -153,12 +158,19 @@ func (c *CSAPI) MustJoinRoom(t ct.TestLike, roomIDOrAlias string, serverNames [] } // JoinRoom joins the room ID or alias given. Returns the raw http response -func (c *CSAPI) JoinRoom(t ct.TestLike, roomIDOrAlias string, serverNames []string) *http.Response { +// +// Args: +// - `serverNames`: The list of servers to attempt to join the room through. +// These should be a resolvable addresses within the deployment network. +func (c *CSAPI) JoinRoom(t ct.TestLike, roomIDOrAlias string, serverNames []spec.ServerName) *http.Response { t.Helper() // construct URL query parameters - query := make(url.Values, len(serverNames)) - for _, serverName := range serverNames { - query.Add("server_name", serverName) + serverNameStrings := make([]string, len(serverNames)) + for i, serverName := range serverNames { + serverNameStrings[i] = string(serverName) + } + query := url.Values{ + "server_name": serverNameStrings, } // join the room return c.Do( diff --git a/federation/handle.go b/federation/handle.go index 32487ff7..eaaba9b7 100644 --- a/federation/handle.go +++ b/federation/handle.go @@ -117,7 +117,7 @@ func MakeRespMakeKnock(s *Server, room *ServerRoom, userID string) (resp fclient // the current server is returned to the joining server. func SendJoinRequestsHandler(s *Server, w http.ResponseWriter, req *http.Request, expectPartialState bool, omitServersInRoom bool) { fedReq, errResp := fclient.VerifyHTTPRequest( - req, time.Now(), spec.ServerName(s.serverName), nil, s.keyRing, + req, time.Now(), s.serverName, nil, s.keyRing, ) if fedReq == nil { w.WriteHeader(errResp.Code) @@ -208,7 +208,7 @@ func HandleInviteRequests(inviteCallback func(gomatrixserverlib.PDU)) func(*Serv // https://matrix.org/docs/spec/server_server/r0.1.4#put-matrix-federation-v2-invite-roomid-eventid s.mux.Handle("/_matrix/federation/v2/invite/{roomID}/{eventID}", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { fedReq, errResp := fclient.VerifyHTTPRequest( - req, time.Now(), spec.ServerName(s.serverName), nil, s.keyRing, + req, time.Now(), s.serverName, nil, s.keyRing, ) if fedReq == nil { w.WriteHeader(errResp.Code) @@ -236,7 +236,7 @@ func HandleInviteRequests(inviteCallback func(gomatrixserverlib.PDU)) func(*Serv } // Sign the event before we send it back - signedEvent := inviteRequest.Event().Sign(s.serverName, s.KeyID, s.Priv) + signedEvent := inviteRequest.Event().Sign(string(s.serverName), s.KeyID, s.Priv) // Send the response res := map[string]interface{}{ @@ -263,7 +263,7 @@ func HandleDirectoryLookups() func(*Server) { b, err := json.Marshal(fclient.RespDirectory{ RoomID: roomID, Servers: []spec.ServerName{ - spec.ServerName(s.serverName), + s.serverName, }, }) if err != nil { @@ -432,7 +432,7 @@ func HandleMediaRequests(mediaIds map[string]func(w http.ResponseWriter)) func(* origin := vars["origin"] mediaId := vars["mediaId"] - if origin != srv.serverName { + if origin != string(srv.serverName) { w.WriteHeader(400) w.Write([]byte("complement: Invalid Origin; Expected " + srv.serverName)) return @@ -471,7 +471,7 @@ func HandleTransactionRequests(pduCallback func(gomatrixserverlib.PDU), eduCallb // Check federation signature fedReq, errResp := fclient.VerifyHTTPRequest( - req, time.Now(), spec.ServerName(srv.serverName), nil, srv.keyRing, + req, time.Now(), srv.serverName, nil, srv.keyRing, ) if fedReq == nil { log.Printf( diff --git a/federation/server.go b/federation/server.go index da1bd6e5..d8825cc1 100644 --- a/federation/server.go +++ b/federation/server.go @@ -48,9 +48,10 @@ type Server struct { // Default: true UnexpectedRequestsAreErrors bool - Priv ed25519.PrivateKey - KeyID gomatrixserverlib.KeyID - serverName string + Priv ed25519.PrivateKey + KeyID gomatrixserverlib.KeyID + // The homeserver name. This should be a resolvable address in the deployment network + serverName spec.ServerName listening bool certPath string @@ -80,7 +81,7 @@ func NewServer(t ct.TestLike, deployment FederationDeployment, opts ...func(*Ser mux: mux.NewRouter(), // The server name will be updated when the caller calls Listen() to include the port number // of the HTTP server e.g "host.docker.internal:56353" - serverName: deployment.GetConfig().HostnameRunningComplement, + serverName: spec.ServerName(deployment.GetConfig().HostnameRunningComplement), rooms: make(map[string]*ServerRoom), aliases: make(map[string]string), UnexpectedRequestsAreErrors: true, @@ -142,7 +143,7 @@ func NewServer(t ct.TestLike, deployment FederationDeployment, opts ...func(*Ser // It is not supported to call ServerName() before Listen() because Listen() modifies the server name. // Listen() will select a random OS-provided high-numbered port to listen on, which then needs to be // retrofitted into the server name so containers know how to route to it. -func (s *Server) ServerName() string { +func (s *Server) ServerName() spec.ServerName { if !s.listening { ct.Fatalf(s.t, "ServerName() called before Listen() - this is not supported because Listen() chooses a high-numbered port and thus changes the server name. Ensure you Listen() first!") } @@ -205,28 +206,31 @@ func (s *Server) FederationClient(deployment FederationDeployment) fclient.Feder ct.Fatalf(s.t, "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!") } identity := fclient.SigningIdentity{ - ServerName: spec.ServerName(s.ServerName()), + ServerName: s.ServerName(), KeyID: s.KeyID, PrivateKey: s.Priv, } - f := fclient.NewFederationClient( + fedClient := fclient.NewFederationClient( []*fclient.SigningIdentity{&identity}, fclient.WithTransport(deployment.RoundTripper()), ) - return f + return fedClient } // MustSendTransaction sends the given PDUs/EDUs to the target destination, returning an error if the /send fails or if the response contains an error // for any sent PDUs. Times out after 10 seconds. -func (s *Server) MustSendTransaction(t ct.TestLike, deployment FederationDeployment, destination string, pdus []json.RawMessage, edus []gomatrixserverlib.EDU) { +// +// Args: +// - `destination`: This should be a resolvable addresses within the deployment network. +func (s *Server) MustSendTransaction(t ct.TestLike, deployment FederationDeployment, destination spec.ServerName, pdus []json.RawMessage, edus []gomatrixserverlib.EDU) { t.Helper() - cli := s.FederationClient(deployment) + fedClient := s.FederationClient(deployment) ctx, cancel := context.WithTimeout(context.Background(), time.Second*10) defer cancel() - resp, err := cli.SendTransaction(ctx, gomatrixserverlib.Transaction{ + resp, err := fedClient.SendTransaction(ctx, gomatrixserverlib.Transaction{ TransactionID: gomatrixserverlib.TransactionID(fmt.Sprintf("complement-%d", time.Now().Nanosecond())), Origin: spec.ServerName(s.ServerName()), - Destination: spec.ServerName(destination), + Destination: destination, PDUs: pdus, EDUs: edus, }) @@ -319,6 +323,9 @@ func (s *Server) MustCreateEvent(t ct.TestLike, room *ServerRoom, ev Event) goma // MustJoinRoom will make the server send a make_join and a send_join to join a room // It returns the resultant room. +// +// Args: +// - `remoteServer`: This should be a resolvable addresses within the deployment network. func (s *Server) MustJoinRoom(t ct.TestLike, deployment FederationDeployment, remoteServer spec.ServerName, roomID string, userID string, opts ...JoinRoomOpt) *ServerRoom { t.Helper() var jr joinRoom @@ -401,6 +408,9 @@ func (s *Server) MustJoinRoom(t ct.TestLike, deployment FederationDeployment, re } // Leaves a room. If this is rejecting an invite then a make_leave request is made first, before send_leave. +// +// Args: +// - `remoteServer`: This should be a resolvable addresses within the deployment network. func (s *Server) MustLeaveRoom(t ct.TestLike, deployment FederationDeployment, remoteServer spec.ServerName, roomID string, userID string) { t.Helper() origin := spec.ServerName(s.serverName) @@ -449,7 +459,7 @@ func (s *Server) ValidFederationRequest(t ct.TestLike, handler func(fr *fclient. return func(w http.ResponseWriter, req *http.Request) { // Check federation signature fedReq, errResp := fclient.VerifyHTTPRequest( - req, time.Now(), spec.ServerName(s.serverName), nil, s.keyRing, + req, time.Now(), s.serverName, nil, s.keyRing, ) if fedReq == nil { ct.Errorf(t, @@ -495,7 +505,7 @@ func (s *Server) Listen() (cancel func()) { ct.Fatalf(s.t, "ListenFederationServer: net.Listen failed: %s", err) } port := ln.Addr().(*net.TCPAddr).Port - s.serverName += fmt.Sprintf(":%d", port) + s.serverName = spec.ServerName(fmt.Sprintf("%s:%d", s.serverName, port)) s.listening = true go func() { @@ -647,7 +657,7 @@ func (f *basicKeyFetcher) FetchKeys( ) { result := make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult, len(requests)) for req := range requests { - if string(req.ServerName) == f.srv.serverName && req.KeyID == f.srv.KeyID { + if req.ServerName == f.srv.serverName && req.KeyID == f.srv.KeyID { publicKey := f.srv.Priv.Public().(ed25519.PublicKey) result[req] = gomatrixserverlib.PublicKeyLookupResult{ ValidUntilTS: spec.AsTimestamp(time.Now().Add(24 * time.Hour)), diff --git a/federation/server_room.go b/federation/server_room.go index 83562e41..5401a234 100644 --- a/federation/server_room.go +++ b/federation/server_room.go @@ -260,7 +260,7 @@ func (r *ServerRoom) MustHaveMembershipForUser(t ct.TestLike, userID, wantMember } // ServersInRoom gets all servers currently joined to the room -func (r *ServerRoom) ServersInRoom() (servers []string) { +func (r *ServerRoom) ServersInRoom() (servers []spec.ServerName) { serverSet := make(map[string]struct{}) r.StateMutex.RLock() @@ -282,7 +282,7 @@ func (r *ServerRoom) ServersInRoom() (servers []string) { r.StateMutex.RUnlock() for server := range serverSet { - servers = append(servers, server) + servers = append(servers, spec.ServerName(server)) } return @@ -498,21 +498,27 @@ func (i *ServerRoomImplDefault) GenerateSendJoinResponse(room *ServerRoom, s *Se authEvents := room.AuthChainForEvents(stateEvents) // get servers in room *before* the join event - serversInRoom := []string{s.serverName} + serversInRoom := []spec.ServerName{s.serverName} if !omitServersInRoom { serversInRoom = room.ServersInRoom() } + serversInRoomStrings := make([]string, len(serversInRoom)) + for i, serverName := range serversInRoom { + serversInRoomStrings[i] = string(serverName) + } + // insert the join event into the room state room.AddEvent(joinEvent) log.Printf("Received send-join of event %s", joinEvent.EventID()) // return state and auth chain return fclient.RespSendJoin{ - Origin: spec.ServerName(s.serverName), + Origin: s.serverName, AuthEvents: gomatrixserverlib.NewEventJSONsFromEvents(authEvents), StateEvents: gomatrixserverlib.NewEventJSONsFromEvents(stateEvents), MembersOmitted: expectPartialState, - ServersInRoom: serversInRoom, + // TODO: It feels like `ServersInRoom` should be `[]spec.ServerName` instead of `[]string` + ServersInRoom: serversInRoomStrings, } } diff --git a/federation/server_test.go b/federation/server_test.go index e5126c61..3db645fb 100644 --- a/federation/server_test.go +++ b/federation/server_test.go @@ -55,7 +55,7 @@ func TestComplementServerIsSigned(t *testing.T) { transport := &http.Transport{TLSClientConfig: tc.config} client := &http.Client{Transport: transport} - resp, err := client.Get("https://" + srv.ServerName()) + resp, err := client.Get("https://" + string(srv.ServerName())) if err != nil { if tc.wantSuccess { t.Fatalf("Failed to GET: %s", err) diff --git a/internal/docker/deployment.go b/internal/docker/deployment.go index 4322a5ed..029b3f56 100644 --- a/internal/docker/deployment.go +++ b/internal/docker/deployment.go @@ -12,6 +12,7 @@ import ( "github.com/matrix-org/complement/ct" "github.com/matrix-org/complement/helpers" "github.com/matrix-org/gomatrixserverlib" + "github.com/matrix-org/gomatrixserverlib/spec" ) // Deployment is the complete instantiation of a Blueprint, with running containers @@ -57,6 +58,16 @@ func (hsDep *HomeserverDeployment) SetEndpoints(baseURL string, fedBaseURL strin } } +func (d *Deployment) GetFullyQualifiedHomeserverName(t ct.TestLike, hsName string) spec.ServerName { + _, ok := d.HS[hsName] + if !ok { + ct.Fatalf(t, "Deployment.GetFullyQualifiedHomeserverName - HS name '%s' not found", hsName) + } + // We have network aliases for each Docker container that will resolve the `hsName` to + // the container. + return spec.ServerName(hsName) +} + // DestroyAtCleanup destroys the entire deployment. It should be called at cleanup time for dirty // deployments only. Handles configuration options for things which should run at container destroy // time, like post-run scripts and printing logs. diff --git a/test_main.go b/test_main.go index 94ceda48..39f87f5f 100644 --- a/test_main.go +++ b/test_main.go @@ -39,6 +39,12 @@ func WithCleanup(fn func(config *config.Complement)) opt { } // WithDeployment adds a custom mechanism to deploy homeservers. +// +// For test consistency and compatibility, deployers should be creating servers that can +// be referred to as `hs1`, `hs2`, etc as the `hsName` in the `Deployment` interface. +// The actual resolvable address of the homeserver in the network can be something +// different and just needs to be mapped by +// your implementation of `deployment.GetFullyQualifiedHomeserverName(hsName)`. func WithDeployment(fn func(t ct.TestLike, numServers int, config *config.Complement) Deployment) opt { return func(co *complementOpts) { co.customDeployment = fn @@ -93,6 +99,9 @@ func OldDeploy(t ct.TestLike, blueprint b.Blueprint) Deployment { // Deploy will deploy the given number of servers or terminate the test. // This function is the main setup function for all tests as it provides a deployment with // which tests can interact with. +// +// For test consistency and compatibility, deployers should be creating servers that can +// be referred to as `hs1`, `hs2`, etc as the `hsName` in the `Deployment` interface. func Deploy(t ct.TestLike, numServers int) Deployment { t.Helper() if testPackage == nil { diff --git a/test_package.go b/test_package.go index 720b57d2..e71ee6d8 100644 --- a/test_package.go +++ b/test_package.go @@ -15,11 +15,19 @@ import ( "github.com/matrix-org/complement/ct" "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/internal/docker" + "github.com/matrix-org/gomatrixserverlib/spec" "github.com/sirupsen/logrus" ) // Deployment provides a way for tests to interact with a set of homeservers. type Deployment interface { + // Returns the resolvable server name (host) of a homeserver given its short alias + // (e.g., "hs1", "hs2"). + // + // In the case of the standard Docker deployment, this will be the same `hs1`, `hs2` + // but may be different for other custom deployments (ex. + // `shardDeployment1.GetFullyQualifiedHomeserverName(t, "hs1")` -> `hs1.shard1:8081`). + GetFullyQualifiedHomeserverName(t ct.TestLike, hsName string) spec.ServerName // UnauthenticatedClient returns a blank CSAPI client. UnauthenticatedClient(t ct.TestLike, serverName string) *client.CSAPI // Register a new user on the given server. diff --git a/tests/csapi/admin_test.go b/tests/csapi/admin_test.go index 6234505a..cbaaf432 100644 --- a/tests/csapi/admin_test.go +++ b/tests/csapi/admin_test.go @@ -12,6 +12,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/spec" ) // Check if this homeserver supports Synapse-style admin registration. @@ -69,7 +70,7 @@ func TestServerNotices(t *testing.T) { }) }) t.Run("Alice can join the alert room", func(t *testing.T) { - alice.MustJoinRoom(t, roomID, []string{}) + alice.MustJoinRoom(t, roomID, []spec.ServerName{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHasEventID(roomID, eventID)) }) t.Run("Alice can leave the alert room, after joining it", func(t *testing.T) { diff --git a/tests/csapi/apidoc_presence_test.go b/tests/csapi/apidoc_presence_test.go index 387821d7..937f9917 100644 --- a/tests/csapi/apidoc_presence_test.go +++ b/tests/csapi/apidoc_presence_test.go @@ -16,6 +16,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/spec" ) func TestPresence(t *testing.T) { @@ -27,7 +28,9 @@ func TestPresence(t *testing.T) { // to share presence alice and bob must be in a shared room roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.MustJoinRoom(t, roomID, []string{"hs1"}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // sytest: GET /presence/:user_id/status fetches initial status t.Run("GET /presence/:user_id/status fetches initial status", func(t *testing.T) { diff --git a/tests/csapi/apidoc_room_forget_test.go b/tests/csapi/apidoc_room_forget_test.go index 1e3a4693..e292a301 100644 --- a/tests/csapi/apidoc_room_forget_test.go +++ b/tests/csapi/apidoc_room_forget_test.go @@ -14,6 +14,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/spec" ) // These tests ensure that forgetting about rooms works as intended @@ -40,7 +41,7 @@ func TestRoomForget(t *testing.T) { t.Run("Forgotten room messages cannot be paginated", func(t *testing.T) { t.Parallel() roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", Content: map[string]interface{}{ @@ -62,7 +63,7 @@ func TestRoomForget(t *testing.T) { t.Run("Forgetting room does not show up in v2 initial /sync", func(t *testing.T) { t.Parallel() roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", Content: map[string]interface{}{ @@ -107,7 +108,7 @@ func TestRoomForget(t *testing.T) { // left if it is forgotten quickly. This is arguably a bug in the spec. t.Parallel() roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", Content: map[string]interface{}{ @@ -145,7 +146,7 @@ func TestRoomForget(t *testing.T) { t.Run("Can forget room you've been kicked from", func(t *testing.T) { t.Parallel() roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", Content: map[string]interface{}{ @@ -187,7 +188,7 @@ func TestRoomForget(t *testing.T) { }, }) // Bob joins room - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) messageID := alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", Content: map[string]interface{}{ @@ -210,7 +211,7 @@ func TestRoomForget(t *testing.T) { }) // Re-invite bob alice.MustInviteRoom(t, roomID, bob.UserID) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) // Query messages queryParams := url.Values{} queryParams.Set("dir", "b") diff --git a/tests/csapi/apidoc_room_members_test.go b/tests/csapi/apidoc_room_members_test.go index b62ef843..ac01c74a 100644 --- a/tests/csapi/apidoc_room_members_test.go +++ b/tests/csapi/apidoc_room_members_test.go @@ -11,6 +11,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/spec" ) func TestRoomMembers(t *testing.T) { @@ -249,7 +250,7 @@ func TestRoomMembers(t *testing.T) { roomID := alice.MustCreateRoom(t, map[string]interface{}{}) alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) bob.MustLeaveRoom(t, roomID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncLeftFrom(bob.UserID, roomID)) diff --git a/tests/csapi/apidoc_room_receipts_test.go b/tests/csapi/apidoc_room_receipts_test.go index e78de2a1..30e7fa84 100644 --- a/tests/csapi/apidoc_room_receipts_test.go +++ b/tests/csapi/apidoc_room_receipts_test.go @@ -12,7 +12,7 @@ import ( // tests/10apidoc/37room-receipts.pl -func createRoomForReadReceipts(t *testing.T, c *client.CSAPI, deployment complement.Deployment) (string, string) { +func createRoomForReadReceipts(t *testing.T, c *client.CSAPI) (string, string) { roomID := c.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) c.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(c.UserID, roomID)) @@ -40,7 +40,7 @@ func TestRoomReceipts(t *testing.T) { deployment := complement.Deploy(t, 1) defer deployment.Destroy(t) alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) - roomID, eventID := createRoomForReadReceipts(t, alice, deployment) + roomID, eventID := createRoomForReadReceipts(t, alice) alice.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "receipt", "m.read", eventID}, client.WithJSONBody(t, struct{}{})) @@ -53,7 +53,7 @@ func TestRoomReadMarkers(t *testing.T) { deployment := complement.Deploy(t, 1) defer deployment.Destroy(t) alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) - roomID, eventID := createRoomForReadReceipts(t, alice, deployment) + roomID, eventID := createRoomForReadReceipts(t, alice) reqBody := client.WithJSONBody(t, map[string]interface{}{ "m.fully_read": eventID, diff --git a/tests/csapi/device_lists_test.go b/tests/csapi/device_lists_test.go index 4c259f78..17340ccb 100644 --- a/tests/csapi/device_lists_test.go +++ b/tests/csapi/device_lists_test.go @@ -13,6 +13,7 @@ import ( "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" "github.com/matrix-org/complement/runtime" + "github.com/matrix-org/gomatrixserverlib/spec" "github.com/tidwall/gjson" ) @@ -124,7 +125,9 @@ func TestDeviceListUpdates(t *testing.T) { // The observing user must share a room with the dummy barrier user. roomID := barry.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - observingUser.MustJoinRoom(t, roomID, []string{otherHSName}) + observingUser.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, otherHSName), + }) observingUser.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(observingUser.UserID, roomID)) return func(t *testing.T, nextBatch string) string { @@ -164,7 +167,9 @@ func TestDeviceListUpdates(t *testing.T) { // Bob joins the room t.Logf("%s joins the test room.", bob.UserID) - bob.MustJoinRoom(t, roomID, []string{hsName}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, hsName), + }) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) // Check that Alice receives a device list update from Bob @@ -217,7 +222,9 @@ func TestDeviceListUpdates(t *testing.T) { // Alice joins the room t.Logf("%s joins the test room.", alice.UserID) - alice.MustJoinRoom(t, roomID, []string{otherHSName}) + alice.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, otherHSName), + }) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) // Check that Alice receives a device list update from Bob @@ -265,7 +272,9 @@ func TestDeviceListUpdates(t *testing.T) { // Bob joins the room t.Logf("%s joins the test room.", bob.UserID) - bob.MustJoinRoom(t, roomID, []string{hsName}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, hsName), + }) bobNextBatch := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) // Alice performs an initial sync @@ -322,7 +331,9 @@ func TestDeviceListUpdates(t *testing.T) { // Alice joins the room t.Logf("%s joins the test room.", alice.UserID) - alice.MustJoinRoom(t, roomID, []string{otherHSName}) + alice.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, otherHSName), + }) bobNextBatch := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) // Alice performs an initial sync @@ -379,7 +390,9 @@ func TestDeviceListUpdates(t *testing.T) { // Bob joins the room t.Logf("%s joins the test room.", bob.UserID) - bob.MustJoinRoom(t, roomID, []string{hsName}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, hsName), + }) bobNextBatch := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) // Alice performs an initial sync @@ -411,7 +424,9 @@ func TestDeviceListUpdates(t *testing.T) { // Bob rejoins the room t.Logf("%s joins the test room.", bob.UserID) - bob.MustJoinRoom(t, roomID, []string{hsName}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, hsName), + }) bob.MustSyncUntil(t, client.SyncReq{Since: bobNextBatch}, client.SyncJoinedTo(bob.UserID, roomID)) // Check that Alice is notified that Bob's devices have a change diff --git a/tests/csapi/keychanges_test.go b/tests/csapi/keychanges_test.go index e651ce79..63437bdc 100644 --- a/tests/csapi/keychanges_test.go +++ b/tests/csapi/keychanges_test.go @@ -13,6 +13,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/spec" ) func TestKeyChangesLocal(t *testing.T) { @@ -32,7 +33,7 @@ func TestKeyChangesLocal(t *testing.T) { bob.MustUploadKeys(t, bobDeviceKeys, bobOTKs) roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) nextBatch1 := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) reqBody := client.WithJSONBody(t, map[string]interface{}{ diff --git a/tests/csapi/membership_on_events_test.go b/tests/csapi/membership_on_events_test.go index c3291ab5..48a2a7c1 100644 --- a/tests/csapi/membership_on_events_test.go +++ b/tests/csapi/membership_on_events_test.go @@ -1,10 +1,12 @@ package csapi_tests import ( + "testing" + "github.com/matrix-org/complement/b" "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/runtime" - "testing" + "github.com/matrix-org/gomatrixserverlib/spec" "github.com/matrix-org/complement" "github.com/matrix-org/complement/helpers" @@ -29,7 +31,9 @@ func TestMembershipOnEvents(t *testing.T) { "msgtype": "m.text", "body": "prejoin", }}) - bob.MustJoinRoom(t, roomID, []string{"hs1"}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) postJoinEventID := alice.SendEventSynced(t, roomID, b.Event{Type: "m.room.message", Content: map[string]interface{}{ "msgtype": "m.text", diff --git a/tests/csapi/rooms_invite_test.go b/tests/csapi/rooms_invite_test.go index 6c0f1db0..0c541a68 100644 --- a/tests/csapi/rooms_invite_test.go +++ b/tests/csapi/rooms_invite_test.go @@ -9,6 +9,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/spec" "github.com/tidwall/gjson" ) @@ -28,7 +29,7 @@ func TestRoomsInvite(t *testing.T) { }) alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) }) @@ -101,7 +102,7 @@ func TestRoomsInvite(t *testing.T) { alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) res := alice.InviteRoom(t, roomID, bob.UserID) @@ -135,7 +136,7 @@ func TestRoomsInvite(t *testing.T) { // Invite & join bob alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) // Raise the powerlevel @@ -153,7 +154,7 @@ func TestRoomsInvite(t *testing.T) { bob.MustInviteRoom(t, roomID, alice.UserID) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(alice.UserID, roomID)) // Alice should be able to rejoin - alice.MustJoinRoom(t, roomID, []string{}) + alice.MustJoinRoom(t, roomID, []spec.ServerName{}) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) }) }) diff --git a/tests/csapi/rooms_members_local_test.go b/tests/csapi/rooms_members_local_test.go index fe6ca4e3..b715ddce 100644 --- a/tests/csapi/rooms_members_local_test.go +++ b/tests/csapi/rooms_members_local_test.go @@ -7,6 +7,7 @@ import ( "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/runtime" + "github.com/matrix-org/gomatrixserverlib/spec" ) func TestMembersLocal(t *testing.T) { @@ -30,7 +31,7 @@ func TestMembersLocal(t *testing.T) { ) _, incrementalSyncTokenBeforeBobJoinsRoom := alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"}) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) t.Run("Parallel", func(t *testing.T) { // sytest: New room members see their own join event diff --git a/tests/csapi/sync_test.go b/tests/csapi/sync_test.go index 380de86e..2399cfab 100644 --- a/tests/csapi/sync_test.go +++ b/tests/csapi/sync_test.go @@ -11,11 +11,12 @@ import ( "github.com/matrix-org/complement" "github.com/matrix-org/complement/b" "github.com/matrix-org/complement/client" - "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/federation" + "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/runtime" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib/fclient" + "github.com/matrix-org/gomatrixserverlib/spec" "github.com/matrix-org/util" ) @@ -183,7 +184,7 @@ func TestSync(t *testing.T) { sendMessages(t, alice, roomID, "alice message 1-", 4) _, nextBatch := bob.MustSync(t, client.SyncReq{Filter: filterBob}) sendMessages(t, alice, roomID, "alice message 2-", 4) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) res, _ := bob.MustSync(t, client.SyncReq{Filter: filterBob, Since: nextBatch}) room := res.Get("rooms.join." + client.GjsonEscape(roomID)) @@ -211,7 +212,7 @@ func TestSync(t *testing.T) { roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) _, nextBatch := bob.MustSync(t, client.SyncReq{}) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) nextBatch = bob.MustSyncUntil(t, client.SyncReq{Since: nextBatch}, func(userID string, sync gjson.Result) error { presence := sync.Get("presence") @@ -232,7 +233,7 @@ func TestSync(t *testing.T) { nextBatch := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) sendMessages(t, alice, roomID, "dummy message", 1) _, nextBatch = alice.MustSync(t, client.SyncReq{Since: nextBatch}) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) // wait until there are presence events @@ -287,10 +288,10 @@ func TestSync(t *testing.T) { charlie := srv.UserID("charlie") redactionRoomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - redactionRoom := srv.MustJoinRoom(t, deployment, "hs1", redactionRoomID, charlie) + redactionRoom := srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), redactionRoomID, charlie) sentinelRoomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - sentinelRoom := srv.MustJoinRoom(t, deployment, "hs1", sentinelRoomID, charlie) + sentinelRoom := srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), sentinelRoomID, charlie) // charlie creates a bogus redaction, which he sends out, followed by // a good event - in another room - to act as a sentinel. It's not @@ -303,7 +304,7 @@ func TestSync(t *testing.T) { Redacts: "$12345"}) redactionRoom.AddEvent(redactionEvent) t.Logf("Created redaction event %s", redactionEvent.EventID()) - srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{redactionEvent.JSON()}, nil) + srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{redactionEvent.JSON()}, nil) sentinelEvent := srv.MustCreateEvent(t, sentinelRoom, federation.Event{ Type: "m.room.test", @@ -312,7 +313,7 @@ func TestSync(t *testing.T) { }) sentinelRoom.AddEvent(sentinelEvent) t.Logf("Created sentinel event %s", sentinelEvent.EventID()) - srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{redactionEvent.JSON(), sentinelEvent.JSON()}, nil) + srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{redactionEvent.JSON(), sentinelEvent.JSON()}, nil) // wait for the sentinel to arrive nextBatch := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHasEventID(sentinelRoomID, sentinelEvent.EventID())) @@ -331,7 +332,7 @@ func TestSync(t *testing.T) { pdus[i] = ev.JSON() lastSentEventId = ev.EventID() } - srv.MustSendTransaction(t, deployment, "hs1", pdus, nil) + srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), pdus, nil) t.Logf("Sent filler events, with final event %s", lastSentEventId) // sync, starting from the same ?since each time, until the final message turns up. @@ -462,7 +463,7 @@ func TestSyncTimelineGap(t *testing.T) { charlie := srv.UserID("charlie") roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - room := srv.MustJoinRoom(t, deployment, "hs1", roomID, charlie) + room := srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, charlie) filterID := createFilter(t, alice, map[string]interface{}{ "room": map[string]interface{}{ @@ -514,7 +515,7 @@ func TestSyncTimelineGap(t *testing.T) { // requests. respondToGetMissingEventsEndpoints(t, srv, room, missingEvents) - srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{lastEvent.JSON()}, nil) + srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{lastEvent.JSON()}, nil) // We now test two different modes of /sync work. The first is when we are // syncing when the server receives the `lastEvent` (and so, at least @@ -723,7 +724,7 @@ func TestRoomSummary(t *testing.T) { } sinceToken := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) // Verify Bob sees the correct room summary bob.MustSyncUntil(t, client.SyncReq{Since: sinceToken}, client.SyncJoinedTo(bob.UserID, roomID), joinedCheck) // .. and Alice as well. diff --git a/tests/csapi/thread_notifications_test.go b/tests/csapi/thread_notifications_test.go index 3acfa462..4c9e8b1e 100644 --- a/tests/csapi/thread_notifications_test.go +++ b/tests/csapi/thread_notifications_test.go @@ -11,6 +11,7 @@ import ( "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/runtime" + "github.com/matrix-org/gomatrixserverlib/spec" ) // Builds a `SyncCheckOpt` which enforces that a sync result satisfies some `check` function @@ -313,7 +314,9 @@ func TestThreadReceiptsInSyncMSC4102(t *testing.T) { alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) bob := deployment.Register(t, "hs2", helpers.RegistrationOpts{}) roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.MustJoinRoom(t, roomID, []string{"hs1"}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) eventA := alice.SendEventSynced(t, roomID, b.Event{ Type: "m.room.message", Content: map[string]interface{}{ diff --git a/tests/direct_messaging_test.go b/tests/direct_messaging_test.go index 772f078b..2282507a 100644 --- a/tests/direct_messaging_test.go +++ b/tests/direct_messaging_test.go @@ -8,12 +8,11 @@ import ( "github.com/matrix-org/complement" "github.com/matrix-org/complement/client" - "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/federation" + "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" "github.com/matrix-org/gomatrixserverlib/fclient" - "github.com/matrix-org/gomatrixserverlib/spec" "github.com/matrix-org/gomatrixserverlib" "github.com/tidwall/gjson" @@ -133,7 +132,8 @@ func TestIsDirectFlagFederation(t *testing.T) { t.Fatalf("failed to make invite request: %s", err) } _, since := alice.MustSync(t, client.SyncReq{}) - _, err = srv.FederationClient(deployment).SendInviteV2(context.Background(), spec.ServerName(srv.ServerName()), "hs1", inviteReq) + fedClient := srv.FederationClient(deployment) + _, err = fedClient.SendInviteV2(context.Background(), srv.ServerName(), deployment.GetFullyQualifiedHomeserverName(t, "hs1"), inviteReq) if err != nil { t.Fatalf("failed to send invite v2: %s", err) } diff --git a/tests/federation_acl_test.go b/tests/federation_acl_test.go index 72b6094b..4dd15af3 100644 --- a/tests/federation_acl_test.go +++ b/tests/federation_acl_test.go @@ -11,6 +11,7 @@ import ( "github.com/matrix-org/complement/must" "github.com/matrix-org/complement/runtime" "github.com/matrix-org/complement/should" + "github.com/matrix-org/gomatrixserverlib/spec" ) // Test for https://github.com/matrix-org/dendrite/issues/3004 @@ -29,15 +30,21 @@ func TestACLs(t *testing.T) { aliceSince := alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) // 3. Join this room from 2nd server - bob.MustJoinRoom(t, roomID, []string{"hs1"}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) aliceSince = alice.MustSyncUntil(t, client.SyncReq{Since: aliceSince}, client.SyncJoinedTo(bob.UserID, roomID)) bobSince := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) // create a different room used for a sentinel event sentinelRoom := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) aliceSince = alice.MustSyncUntil(t, client.SyncReq{Since: aliceSince}, client.SyncJoinedTo(alice.UserID, sentinelRoom)) - bob.MustJoinRoom(t, sentinelRoom, []string{"hs1"}) - charlie.MustJoinRoom(t, sentinelRoom, []string{"hs1"}) + bob.MustJoinRoom(t, sentinelRoom, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) + charlie.MustJoinRoom(t, sentinelRoom, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) aliceSince = alice.MustSyncUntil(t, client.SyncReq{Since: aliceSince}, client.SyncJoinedTo(bob.UserID, sentinelRoom), client.SyncJoinedTo(charlie.UserID, sentinelRoom), @@ -59,7 +66,9 @@ func TestACLs(t *testing.T) { bob.MustSyncUntil(t, client.SyncReq{Since: bobSince}, client.SyncTimelineHasEventID(roomID, eventID)) // 5. Join from 3rd server. - charlie.MustJoinRoom(t, roomID, []string{"hs1"}) + charlie.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) aliceSince = alice.MustSyncUntil(t, client.SyncReq{Since: aliceSince}, client.SyncJoinedTo(charlie.UserID, roomID)) charlieSince := charlie.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(charlie.UserID, roomID)) diff --git a/tests/federation_device_list_update_test.go b/tests/federation_device_list_update_test.go index 5cdf7277..770535c8 100644 --- a/tests/federation_device_list_update_test.go +++ b/tests/federation_device_list_update_test.go @@ -16,6 +16,7 @@ import ( "github.com/matrix-org/complement/must" "github.com/matrix-org/complement/runtime" "github.com/matrix-org/gomatrixserverlib" + "github.com/matrix-org/gomatrixserverlib/spec" "github.com/tidwall/gjson" ) @@ -120,7 +121,9 @@ func TestDeviceListsUpdateOverFederation(t *testing.T) { _, aliceSince := alice.MustSync(t, client.SyncReq{TimeoutMillis: "0"}) bobSince := bob.MustSyncUntil(t, client.SyncReq{TimeoutMillis: "0"}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.MustJoinRoom(t, roomID, []string{"hs1"}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // both alice and bob should see device list updates for each other aliceSince = alice.MustSyncUntil( @@ -205,7 +208,7 @@ func TestDeviceListsUpdateOverFederationOnRoomJoin(t *testing.T) { initalEvents := federation.InitialRoomEvents(roomVer, bob) room := srv.MustMakeRoom(t, roomVer, initalEvents) - alice.MustJoinRoom(t, room.RoomID, []string{srv.ServerName()}) + alice.MustJoinRoom(t, room.RoomID, []spec.ServerName{srv.ServerName()}) alice.SendEventSynced(t, room.RoomID, b.Event{ Type: "m.room.message", Content: map[string]interface{}{ @@ -256,7 +259,9 @@ func TestUserAppearsInChangedDeviceListOnJoinOverFederation(t *testing.T) { _, since := joinee.MustSync(t, client.SyncReq{}) // the joiner now joins the room over federation - joiner.MustJoinRoom(t, roomID, []string{"hs2"}) + joiner.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs2"), + }) // we must see the joiner's user ID in device_lists.changed since = joinee.MustSyncUntil(t, client.SyncReq{ diff --git a/tests/federation_event_auth_test.go b/tests/federation_event_auth_test.go index 57bbb8af..f49b4e66 100644 --- a/tests/federation_event_auth_test.go +++ b/tests/federation_event_auth_test.go @@ -7,10 +7,9 @@ import ( "github.com/matrix-org/complement" "github.com/matrix-org/complement/b" - "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/federation" + "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/must" - "github.com/matrix-org/gomatrixserverlib/spec" "github.com/matrix-org/gomatrixserverlib" ) @@ -60,11 +59,11 @@ func TestEventAuth(t *testing.T) { roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) - room := srv.MustJoinRoom(t, deployment, "hs1", roomID, charlie) + room := srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, charlie) firstJoinEvent := room.CurrentState("m.room.member", charlie) - srv.MustLeaveRoom(t, deployment, "hs1", roomID, charlie) + srv.MustLeaveRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, charlie) leaveEvent := room.CurrentState("m.room.member", charlie) - room = srv.MustJoinRoom(t, deployment, "hs1", roomID, charlie) + room = srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, charlie) // now update the auth chain a bit: dendrite had a bug where it returned the auth chain for all // the current state in addition to the event asked for @@ -80,7 +79,15 @@ func TestEventAuth(t *testing.T) { getEventAuth := func(t *testing.T, eventID string, wantAuthEventIDs []string) { t.Helper() t.Logf("/event_auth for %s - want %v", eventID, wantAuthEventIDs) - eventAuthResp, err := srv.FederationClient(deployment).GetEventAuth(context.Background(), spec.ServerName(srv.ServerName()), "hs1", room.Version, roomID, eventID) + fedClient := srv.FederationClient(deployment) + eventAuthResp, err := fedClient.GetEventAuth( + context.Background(), + srv.ServerName(), + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + room.Version, + roomID, + eventID, + ) must.NotError(t, "failed to /event_auth", err) if len(eventAuthResp.AuthEvents) == 0 { t.Fatalf("/event_auth returned 0 auth events") diff --git a/tests/federation_presence_test.go b/tests/federation_presence_test.go index db8d2e2b..9e11ca7f 100644 --- a/tests/federation_presence_test.go +++ b/tests/federation_presence_test.go @@ -9,6 +9,7 @@ import ( "github.com/matrix-org/complement/b" "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/helpers" + "github.com/matrix-org/gomatrixserverlib/spec" ) func TestRemotePresence(t *testing.T) { @@ -20,7 +21,9 @@ func TestRemotePresence(t *testing.T) { // for presence to be sent over federation alice and bob must share a room roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.MustJoinRoom(t, roomID, []string{"hs1"}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // sytest: Presence changes are also reported to remote room members t.Run("Presence changes are also reported to remote room members", func(t *testing.T) { diff --git a/tests/federation_query_profile_test.go b/tests/federation_query_profile_test.go index f6f93ca0..f901c7c6 100644 --- a/tests/federation_query_profile_test.go +++ b/tests/federation_query_profile_test.go @@ -8,7 +8,6 @@ import ( "github.com/matrix-org/complement" "github.com/matrix-org/gomatrixserverlib/fclient" - "github.com/matrix-org/gomatrixserverlib/spec" "github.com/matrix-org/complement/federation" "github.com/matrix-org/complement/helpers" @@ -76,14 +75,14 @@ func TestInboundFederationProfile(t *testing.T) { ) cancel := srv.Listen() defer cancel() - origin := spec.ServerName(srv.ServerName()) + origin := srv.ServerName() // sytest: Non-numeric ports in server names are rejected t.Run("Non-numeric ports in server names are rejected", func(t *testing.T) { fedReq := fclient.NewFederationRequest( "GET", origin, - "hs1", + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), "/_matrix/federation/v1/query/profile"+ "?user_id=@user1:localhost:http"+ "&field=displayname", @@ -107,7 +106,7 @@ func TestInboundFederationProfile(t *testing.T) { fedReq := fclient.NewFederationRequest( "GET", origin, - "hs1", + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), "/_matrix/federation/v1/query/profile"+ "?user_id="+alice.UserID+ "&field=displayname", diff --git a/tests/federation_redaction_test.go b/tests/federation_redaction_test.go index 294bf7c6..94bb03a5 100644 --- a/tests/federation_redaction_test.go +++ b/tests/federation_redaction_test.go @@ -5,11 +5,12 @@ import ( "time" "github.com/matrix-org/complement" - "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/federation" + "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/must" "github.com/matrix-org/complement/runtime" "github.com/matrix-org/gomatrixserverlib" + "github.com/matrix-org/gomatrixserverlib/spec" ) // test that a redaction is sent out over federation even if we don't have the original event @@ -54,7 +55,7 @@ func TestFederationRedactSendsWithoutEvent(t *testing.T) { roomAlias := srv.MakeAliasMapping("flibble", serverRoom.RoomID) // the local homeserver joins the room - alice.MustJoinRoom(t, roomAlias, []string{srv.ServerName()}) + alice.MustJoinRoom(t, roomAlias, []spec.ServerName{srv.ServerName()}) // inject event to redact in the room badEvent := srv.MustCreateEvent(t, serverRoom, federation.Event{ @@ -67,7 +68,7 @@ func TestFederationRedactSendsWithoutEvent(t *testing.T) { eventID := badEvent.EventID() fullServerName := srv.ServerName() - eventToRedact := eventID + ":" + fullServerName + eventToRedact := eventID + ":" + string(fullServerName) // the client sends a request to the local homeserver to send the redaction redactionEventID := alice.MustSendRedaction(t, serverRoom.RoomID, map[string]interface{}{ diff --git a/tests/federation_room_ban_test.go b/tests/federation_room_ban_test.go index 4e3a9f29..9a3ff479 100644 --- a/tests/federation_room_ban_test.go +++ b/tests/federation_room_ban_test.go @@ -6,6 +6,7 @@ import ( "github.com/matrix-org/complement" "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/helpers" + "github.com/matrix-org/gomatrixserverlib/spec" ) // Regression test for https://github.com/matrix-org/synapse/issues/1563 @@ -21,7 +22,9 @@ func TestUnbanViaInvite(t *testing.T) { roomID := bob.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) - alice.MustJoinRoom(t, roomID, []string{"hs2"}) + alice.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs2"), + }) // Ban Alice bob.MustDo(t, "POST", []string{"_matrix", "client", "v3", "rooms", roomID, "ban"}, client.WithJSONBody(t, map[string]interface{}{ @@ -41,5 +44,7 @@ func TestUnbanViaInvite(t *testing.T) { alice.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(alice.UserID, roomID)) // Alice accepts (this is what previously failed in the issue) - alice.MustJoinRoom(t, roomID, []string{"hs2"}) + alice.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs2"), + }) } diff --git a/tests/federation_room_event_auth_test.go b/tests/federation_room_event_auth_test.go index 5b9e3a6b..245f73ef 100644 --- a/tests/federation_room_event_auth_test.go +++ b/tests/federation_room_event_auth_test.go @@ -20,8 +20,8 @@ import ( "github.com/matrix-org/complement/b" "github.com/matrix-org/complement/client" - "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/federation" + "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/must" ) @@ -114,7 +114,7 @@ func TestInboundFederationRejectsEventsWithRejectedAuthEvents(t *testing.T) { "preset": "public_chat", }) charlie := srv.UserID("charlie") - room := srv.MustJoinRoom(t, deployment, "hs1", testRoomID, charlie) + room := srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), testRoomID, charlie) charlieMembershipEvent := room.CurrentState("m.room.member", charlie) // have Charlie send a PL event which will be rejected @@ -128,8 +128,8 @@ func TestInboundFederationRejectsEventsWithRejectedAuthEvents(t *testing.T) { }) _, err := fedClient.SendTransaction(context.Background(), gomatrixserverlib.Transaction{ TransactionID: "complement1", - Origin: spec.ServerName(srv.ServerName()), - Destination: "hs1", + Origin: srv.ServerName(), + Destination: deployment.GetFullyQualifiedHomeserverName(t, "hs1"), OriginServerTS: spec.AsTimestamp(time.Now()), PDUs: []json.RawMessage{ rejectedEvent.JSON(), @@ -199,8 +199,8 @@ func TestInboundFederationRejectsEventsWithRejectedAuthEvents(t *testing.T) { _, err = fedClient.SendTransaction(context.Background(), gomatrixserverlib.Transaction{ TransactionID: "complement2", - Origin: spec.ServerName(srv.ServerName()), - Destination: "hs1", + Origin: srv.ServerName(), + Destination: deployment.GetFullyQualifiedHomeserverName(t, "hs1"), OriginServerTS: spec.AsTimestamp(time.Now()), PDUs: []json.RawMessage{ sentEvent1.JSON(), diff --git a/tests/federation_room_get_missing_events_test.go b/tests/federation_room_get_missing_events_test.go index 684f8490..7c2c0bca 100644 --- a/tests/federation_room_get_missing_events_test.go +++ b/tests/federation_room_get_missing_events_test.go @@ -68,7 +68,7 @@ func TestGetMissingEventsGapFilling(t *testing.T) { roomID := alice.MustCreateRoom(t, map[string]interface{}{ "preset": "public_chat", }) - srvRoom := srv.MustJoinRoom(t, deployment, "hs1", roomID, bob) + srvRoom := srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, bob) lastSharedEvent := srvRoom.Timeline[len(srvRoom.Timeline)-1] // 2) Inject events into Complement but don't deliver them to the HS. @@ -127,7 +127,7 @@ func TestGetMissingEventsGapFilling(t *testing.T) { ).Methods("POST") // 3) ...and send that alone to the HS. - srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{mostRecentEvent.JSON()}, nil) + srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{mostRecentEvent.JSON()}, nil) // 6) Ensure Alice sees all injected events in the correct order. correctOrderEventIDs := append([]string{lastSharedEvent.EventID()}, missingEventIDs...) @@ -233,7 +233,7 @@ func TestOutboundFederationIgnoresMissingEventWithBadJSONForRoomVersion6(t *test t.Fatalf("failed to create event: invalid room version: %s", err) } eb := verImpl.NewEventBuilderFromProtoEvent(&proto) - signedBadEvent, err := eb.Build(time.Now(), spec.ServerName(srv.ServerName()), srv.KeyID, srv.Priv) + signedBadEvent, err := eb.Build(time.Now(), srv.ServerName(), srv.KeyID, srv.Priv) if err != nil { t.Fatalf("failed to sign event: %s", err) } @@ -274,8 +274,8 @@ func TestOutboundFederationIgnoresMissingEventWithBadJSONForRoomVersion6(t *test fedClient := srv.FederationClient(deployment) resp, err := fedClient.SendTransaction(context.Background(), gomatrixserverlib.Transaction{ TransactionID: "wut", - Origin: spec.ServerName(srv.ServerName()), - Destination: spec.ServerName("hs1"), + Origin: srv.ServerName(), + Destination: deployment.GetFullyQualifiedHomeserverName(t, "hs1"), PDUs: []json.RawMessage{ sentEvent.JSON(), }, @@ -320,8 +320,8 @@ func TestOutboundFederationIgnoresMissingEventWithBadJSONForRoomVersion6(t *test resp, err = fedClient.SendTransaction(context.Background(), gomatrixserverlib.Transaction{ TransactionID: "t2", - Origin: spec.ServerName(srv.ServerName()), - Destination: spec.ServerName("hs1"), + Origin: srv.ServerName(), + Destination: deployment.GetFullyQualifiedHomeserverName(t, "hs1"), PDUs: []json.RawMessage{ message3.JSON(), }, @@ -379,13 +379,13 @@ func TestInboundCanReturnMissingEvents(t *testing.T) { Sender: alice.UserID, }) - room := srv.MustJoinRoom(t, deployment, "hs1", roomID, charlie) + room := srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, charlie) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(charlie, roomID)) req := fclient.NewFederationRequest( "POST", - spec.ServerName(srv.ServerName()), - "hs1", + srv.ServerName(), + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), fmt.Sprintf("/_matrix/federation/v1/get_missing_events/%s", roomID), ) @@ -533,7 +533,7 @@ func TestOutboundFederationEventSizeGetMissingEvents(t *testing.T) { } eb.AuthEvents = room.AuthEvents(stateNeeded) - signedBadEvent, err := eb.Build(time.Now(), spec.ServerName(srv.ServerName()), srv.KeyID, srv.Priv) + signedBadEvent, err := eb.Build(time.Now(), srv.ServerName(), srv.KeyID, srv.Priv) switch e := err.(type) { case nil: case gomatrixserverlib.EventValidationError: @@ -579,8 +579,8 @@ func TestOutboundFederationEventSizeGetMissingEvents(t *testing.T) { fedClient := srv.FederationClient(deployment) resp, err := fedClient.SendTransaction(context.Background(), gomatrixserverlib.Transaction{ TransactionID: "wut", - Origin: spec.ServerName(srv.ServerName()), - Destination: spec.ServerName("hs1"), + Origin: srv.ServerName(), + Destination: deployment.GetFullyQualifiedHomeserverName(t, "hs1"), PDUs: []json.RawMessage{ sentEvent.JSON(), }, diff --git a/tests/federation_room_invite_test.go b/tests/federation_room_invite_test.go index 5434f823..fca50315 100644 --- a/tests/federation_room_invite_test.go +++ b/tests/federation_room_invite_test.go @@ -7,8 +7,8 @@ import ( "github.com/matrix-org/complement" "github.com/matrix-org/gomatrixserverlib" - "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/federation" + "github.com/matrix-org/complement/helpers" ) // This test ensures that invite rejections are correctly sent out over federation. @@ -45,7 +45,7 @@ func TestFederationRejectInvite(t *testing.T) { // Alice creates the room, and delia joins roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - room := srv.MustJoinRoom(t, deployment, "hs1", roomID, delia) + room := srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, delia) // Alice invites Charlie; Delia should see the invite waiter = helpers.NewWaiter() diff --git a/tests/federation_room_join_test.go b/tests/federation_room_join_test.go index 111bb028..b99adce8 100644 --- a/tests/federation_room_join_test.go +++ b/tests/federation_room_join_test.go @@ -22,8 +22,8 @@ import ( "github.com/matrix-org/complement/b" "github.com/matrix-org/complement/client" - "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/federation" + "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" "github.com/matrix-org/complement/runtime" @@ -73,14 +73,16 @@ func TestJoinViaRoomIDAndServerName(t *testing.T) { serverRoom := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, charlie)) // join the room by room ID, providing the serverName to join via - alice.MustJoinRoom(t, serverRoom.RoomID, []string{srv.ServerName()}) + alice.MustJoinRoom(t, serverRoom.RoomID, []spec.ServerName{srv.ServerName()}) // 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.Register(t, "hs2", helpers.RegistrationOpts{}) - roomID := bob.MustJoinRoom(t, serverRoom.RoomID, []string{"hs1"}) + roomID := bob.MustJoinRoom(t, serverRoom.RoomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) must.Equal(t, roomID, serverRoom.RoomID, "joined room mismatch") } @@ -110,7 +112,10 @@ func TestJoinFederatedRoomFailOver(t *testing.T) { t.Logf("%s created room %s.", bob.UserID, roomID) t.Logf("%s joins the room via {complement,hs2}.", alice.UserID) - alice.MustJoinRoom(t, roomID, []string{srv.ServerName(), "hs2"}) + alice.MustJoinRoom(t, roomID, []spec.ServerName{ + srv.ServerName(), + deployment.GetFullyQualifiedHomeserverName(t, "hs2"), + }) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, roomID)) } @@ -301,7 +306,7 @@ func TestBannedUserCannotSendJoin(t *testing.T) { federation.HandleTransactionRequests(nil, nil), ) cancel := srv.Listen() - origin := spec.ServerName(srv.ServerName()) + origin := srv.ServerName() defer cancel() fedClient := srv.FederationClient(deployment) @@ -324,7 +329,7 @@ func TestBannedUserCannotSendJoin(t *testing.T) { }) // charlie sends a make_join for a different user - makeJoinResp, err := fedClient.MakeJoin(context.Background(), origin, "hs1", roomID, srv.UserID("charlie2")) + makeJoinResp, err := fedClient.MakeJoin(context.Background(), origin, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, srv.UserID("charlie2")) must.NotError(t, "MakeJoin", err) // ... and does a switcheroo to turn it into a join for himself @@ -334,11 +339,11 @@ func TestBannedUserCannotSendJoin(t *testing.T) { verImpl, err := gomatrixserverlib.GetRoomVersion(makeJoinResp.RoomVersion) must.NotError(t, "JoinEvent.GetRoomVersion", err) eb := verImpl.NewEventBuilderFromProtoEvent(&makeJoinResp.JoinEvent) - joinEvent, err := eb.Build(time.Now(), spec.ServerName(srv.ServerName()), srv.KeyID, srv.Priv) + joinEvent, err := eb.Build(time.Now(), srv.ServerName(), srv.KeyID, srv.Priv) must.NotError(t, "JoinEvent.Build", err) // SendJoin should return a 403. - _, err = fedClient.SendJoin(context.Background(), origin, "hs1", joinEvent) + _, err = fedClient.SendJoin(context.Background(), origin, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), joinEvent) if err == nil { t.Errorf("SendJoin returned 200, want 403") } else if httpError, ok := err.(gomatrix.HTTPError); ok { @@ -406,7 +411,7 @@ func testValidationForSendMembershipEndpoint(t *testing.T, baseApiPath, expected alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) roomId := alice.MustCreateRoom(t, createRoomOpts) charlie := srv.UserID("charlie") - room := srv.MustJoinRoom(t, deployment, "hs1", roomId, charlie) + room := srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomId, charlie) // a helper function which makes a send_* request to the given path and checks // that it fails with a 400 error @@ -417,7 +422,7 @@ func testValidationForSendMembershipEndpoint(t *testing.T, baseApiPath, expected url.PathEscape(event.EventID()), ) t.Logf("PUT %s", path) - req := fclient.NewFederationRequest("PUT", spec.ServerName(srv.ServerName()), "hs1", path) + req := fclient.NewFederationRequest("PUT", srv.ServerName(), deployment.GetFullyQualifiedHomeserverName(t, "hs1"), path) if err := req.SetContent(event); err != nil { t.Errorf("req.SetContent: %v", err) return @@ -506,7 +511,7 @@ func TestSendJoinPartialStateResponse(t *testing.T) { ) cancel := srv.Listen() defer cancel() - origin := spec.ServerName(srv.ServerName()) + origin := srv.ServerName() // annoyingly we can't get to the room that alice and bob already share (see https://github.com/matrix-org/complement/issues/254) // so we have to create a new one. @@ -519,7 +524,7 @@ func TestSendJoinPartialStateResponse(t *testing.T) { // now we send a make_join... charlie := srv.UserID("charlie") fedClient := srv.FederationClient(deployment) - makeJoinResp, err := fedClient.MakeJoin(context.Background(), origin, "hs1", roomID, charlie) + makeJoinResp, err := fedClient.MakeJoin(context.Background(), origin, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, charlie) if err != nil { t.Fatalf("make_join failed: %v", err) } @@ -528,13 +533,13 @@ func TestSendJoinPartialStateResponse(t *testing.T) { verImpl, err := gomatrixserverlib.GetRoomVersion(makeJoinResp.RoomVersion) must.NotError(t, "JoinEvent.GetRoomVersion", err) eb := verImpl.NewEventBuilderFromProtoEvent(&makeJoinResp.JoinEvent) - joinEvent, err := eb.Build(time.Now(), spec.ServerName(srv.ServerName()), srv.KeyID, srv.Priv) + joinEvent, err := eb.Build(time.Now(), srv.ServerName(), srv.KeyID, srv.Priv) if err != nil { t.Fatalf("failed to sign join event: %v", err) } // and send_join it, with the magic param - sendJoinResp, err := fedClient.SendJoinPartialState(context.Background(), origin, "hs1", joinEvent) + sendJoinResp, err := fedClient.SendJoinPartialState(context.Background(), origin, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), joinEvent) if err != nil { t.Fatalf("send_join failed: %v", err) } @@ -602,6 +607,8 @@ func TestJoinFederatedRoomFromApplicationServiceBridgeUser(t *testing.T) { }) // Join the AS bridge user to the remote federated room (without a profile set) - as.MustJoinRoom(t, roomID, []string{"hs2"}) + as.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs2"), + }) }) } diff --git a/tests/federation_room_send_test.go b/tests/federation_room_send_test.go index 40ee0fd8..acc318be 100644 --- a/tests/federation_room_send_test.go +++ b/tests/federation_room_send_test.go @@ -9,6 +9,7 @@ import ( "github.com/matrix-org/complement" "github.com/matrix-org/gomatrixserverlib" + "github.com/matrix-org/gomatrixserverlib/spec" "github.com/tidwall/gjson" "golang.org/x/exp/slices" @@ -63,7 +64,7 @@ func TestOutboundFederationSend(t *testing.T) { roomAlias := srv.MakeAliasMapping("flibble", serverRoom.RoomID) // the local homeserver joins the room - alice.MustJoinRoom(t, roomAlias, []string{deployment.GetConfig().HostnameRunningComplement}) + alice.MustJoinRoom(t, roomAlias, []spec.ServerName{srv.ServerName()}) // the local homeserver sends an event into the room alice.SendEventSynced(t, serverRoom.RoomID, b.Event{ @@ -145,8 +146,8 @@ func TestNetworkPartitionOrdering(t *testing.T) { roomAlias := srv.MakeAliasMapping("flibble", serverRoom.RoomID) // the local homeserver joins the room - alice.MustJoinRoom(t, roomAlias, []string{deployment.GetConfig().HostnameRunningComplement}) - bob.MustJoinRoom(t, roomAlias, []string{deployment.GetConfig().HostnameRunningComplement}) + alice.MustJoinRoom(t, roomAlias, []spec.ServerName{srv.ServerName()}) + bob.MustJoinRoom(t, roomAlias, []spec.ServerName{srv.ServerName()}) // bob requests the last 4 timeline events. We don't care about it right now but do want the since token _, bobSince := bob.MustSync(t, client.SyncReq{ Filter: `{"room":{"timeline":{"limit":4}}}`, @@ -176,7 +177,7 @@ func TestNetworkPartitionOrdering(t *testing.T) { } // remote homeserver now injects event 1' - srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{event1prime.JSON()}, nil) + srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{event1prime.JSON()}, nil) // ensure it gets there alice.MustSyncUntil(t, client.SyncReq{TimeoutMillis: "1000"}, client.SyncTimelineHasEventID(serverRoom.RoomID, event1prime.EventID())) diff --git a/tests/federation_room_typing_test.go b/tests/federation_room_typing_test.go index 26bcafb7..7e4a9b12 100644 --- a/tests/federation_room_typing_test.go +++ b/tests/federation_room_typing_test.go @@ -6,6 +6,7 @@ import ( "github.com/matrix-org/complement" "github.com/matrix-org/complement/client" "github.com/matrix-org/complement/helpers" + "github.com/matrix-org/gomatrixserverlib/spec" ) // sytest: Typing notifications also sent to remote room members @@ -19,7 +20,9 @@ func TestRemoteTyping(t *testing.T) { roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) bob.MustJoinRoom(t, roomID, nil) - charlie.MustJoinRoom(t, roomID, []string{"hs1"}) + charlie.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) bobToken := bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) charlieToken := charlie.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(charlie.UserID, roomID)) diff --git a/tests/federation_rooms_invite_test.go b/tests/federation_rooms_invite_test.go index 896bf9f7..b99509e1 100644 --- a/tests/federation_rooms_invite_test.go +++ b/tests/federation_rooms_invite_test.go @@ -109,14 +109,18 @@ func TestFederationRoomsInvite(t *testing.T) { // bob1 is invited and can join the room (hs2 is now participating of the room) alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.MustJoinRoom(t, roomID, []string{"hs1"}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // Make sure alice can see bob in the room alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) // bob2 is invited and can also join the room alice.MustInviteRoom(t, roomID, bob2.UserID) bob2.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob2.UserID, roomID)) - bob2.MustJoinRoom(t, roomID, []string{"hs1"}) + bob2.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // Make sure alice can see bob2 in the room alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob2.UserID, roomID)) }) @@ -131,7 +135,9 @@ func TestFederationRoomsInvite(t *testing.T) { // bob1 is invited and can join the room (hs2 is now participating of the room) alice.MustInviteRoom(t, roomID, bob.UserID) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncInvitedTo(bob.UserID, roomID)) - bob.MustJoinRoom(t, roomID, []string{"hs1"}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // Make sure alice can see bob in the room alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) @@ -151,7 +157,7 @@ func TestFederationRoomsInvite(t *testing.T) { "invite": []string{bob.UserID}, "is_direct": true, }) - bob.MustJoinRoom(t, roomID, []string{}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{}) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas(roomID, func(result gjson.Result) bool { // We expect a membership event .. diff --git a/tests/federation_sync_test.go b/tests/federation_sync_test.go index f40c45c5..23f67c5b 100644 --- a/tests/federation_sync_test.go +++ b/tests/federation_sync_test.go @@ -14,6 +14,7 @@ import ( "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" "github.com/matrix-org/complement/runtime" + "github.com/matrix-org/gomatrixserverlib/spec" "github.com/tidwall/gjson" ) @@ -44,7 +45,7 @@ func TestSyncOmitsStateChangeOnFilteredEvents(t *testing.T) { serverRoom := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, bob)) // Join Alice to the new room on the federation server and send E1. - alice.MustJoinRoom(t, serverRoom.RoomID, []string{srv.ServerName()}) + alice.MustJoinRoom(t, serverRoom.RoomID, []spec.ServerName{srv.ServerName()}) e1 := alice.SendEventSynced(t, serverRoom.RoomID, b.Event{ Type: "m.room.message", Content: map[string]interface{}{ @@ -84,7 +85,7 @@ func TestSyncOmitsStateChangeOnFilteredEvents(t *testing.T) { }) // fork the dag earlier at e1 and send s2 - srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{s2.JSON()}, nil) + srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{s2.JSON()}, nil) // wait until we see S2 to ensure the server has processed this. alice.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHasEventID(serverRoom.RoomID, s2.EventID())) diff --git a/tests/federation_unreject_rejected_test.go b/tests/federation_unreject_rejected_test.go index 9f0cdfc7..e05e58e3 100644 --- a/tests/federation_unreject_rejected_test.go +++ b/tests/federation_unreject_rejected_test.go @@ -6,8 +6,9 @@ import ( "github.com/matrix-org/complement" "github.com/matrix-org/complement/client" - "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/federation" + "github.com/matrix-org/complement/helpers" + "github.com/matrix-org/gomatrixserverlib/spec" ) // TestUnrejectRejectedEvents creates two events: A and B. @@ -36,7 +37,7 @@ func TestUnrejectRejectedEvents(t *testing.T) { serverRoom := srv.MustMakeRoom(t, ver, federation.InitialRoomEvents(ver, bob)) // Join Alice to the new room on the federation server. - alice.MustJoinRoom(t, serverRoom.RoomID, []string{srv.ServerName()}) + alice.MustJoinRoom(t, serverRoom.RoomID, []spec.ServerName{srv.ServerName()}) alice.MustSyncUntil( t, client.SyncReq{}, client.SyncJoinedTo(alice.UserID, serverRoom.RoomID), @@ -64,12 +65,12 @@ func TestUnrejectRejectedEvents(t *testing.T) { // Send event B into the room. Event A at this point is unknown // to the homeserver and we're not going to respond to the events // request for it, so it should get rejected. - srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{eventB.JSON()}, nil) + srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{eventB.JSON()}, nil) // Now we're going to send Event A into the room, which should give // the server the prerequisite event to pass Event B later. This one // should appear in /sync. - srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{eventA.JSON()}, nil) + srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{eventA.JSON()}, nil) // Wait for event A to appear in the room. We're going to store the // sync token here because we want to assert on the next sync that @@ -81,7 +82,7 @@ func TestUnrejectRejectedEvents(t *testing.T) { // Finally, send Event B again. This time it should be unrejected and // should be sent as a new event down /sync for the first time. - srv.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{eventB.JSON()}, nil) + srv.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{eventB.JSON()}, nil) // Now see if event B appears in the room. Use the since token from the // last sync to ensure we're only waiting for new events since event A. diff --git a/tests/federation_upload_keys_test.go b/tests/federation_upload_keys_test.go index b439b55d..2f91485e 100644 --- a/tests/federation_upload_keys_test.go +++ b/tests/federation_upload_keys_test.go @@ -13,6 +13,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/spec" ) func TestFederationKeyUploadQuery(t *testing.T) { @@ -24,7 +25,9 @@ func TestFederationKeyUploadQuery(t *testing.T) { // for device lists to be shared between alice and bob they must share a room roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) - bob.MustJoinRoom(t, roomID, []string{"hs1"}) + bob.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // Do an initial sync so that we can see the changes come down sync. // We wait until we see the newly joined room as that can cause alice to appear in device_lists diff --git a/tests/knock_restricted_test.go b/tests/knock_restricted_test.go index 7765f974..c5fce41b 100644 --- a/tests/knock_restricted_test.go +++ b/tests/knock_restricted_test.go @@ -52,7 +52,7 @@ func TestRestrictedRoomsLocalJoinInMSC3787Room(t *testing.T) { bob := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) // Execute the checks. - checkRestrictedRoom(t, alice, bob, allowed_room, room, joinRule) + checkRestrictedRoom(t, deployment, alice, bob, allowed_room, room, joinRule) } // See TestRestrictedRoomsRemoteJoin @@ -67,7 +67,7 @@ func TestRestrictedRoomsRemoteJoinInMSC3787Room(t *testing.T) { bob := deployment.Register(t, "hs2", helpers.RegistrationOpts{}) // Execute the checks. - checkRestrictedRoom(t, alice, bob, allowed_room, room, joinRule) + checkRestrictedRoom(t, deployment, alice, bob, allowed_room, room, joinRule) } // See TestRestrictedRoomsRemoteJoinLocalUser diff --git a/tests/knocking_test.go b/tests/knocking_test.go index 4192d5f3..7c1bc98b 100644 --- a/tests/knocking_test.go +++ b/tests/knocking_test.go @@ -17,6 +17,7 @@ import ( "github.com/matrix-org/complement" "github.com/matrix-org/gomatrixserverlib" + "github.com/matrix-org/gomatrixserverlib/spec" "github.com/tidwall/gjson" "github.com/matrix-org/complement/b" @@ -72,10 +73,10 @@ func doTestKnocking(t *testing.T, roomVersion string, joinRule string) { }) alice.MustInviteRoom(t, roomIDOne, david) inviteWaiter.Wait(t, 5*time.Second) - serverRoomOne := srv.MustJoinRoom(t, deployment, "hs1", roomIDOne, david) + serverRoomOne := srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomIDOne, david) // Test knocking between two users on the same homeserver - knockingBetweenTwoUsersTest(t, roomIDOne, alice, bob, serverRoomOne, false, joinRule) + knockingBetweenTwoUsersTest(t, deployment, roomIDOne, alice, bob, serverRoomOne, false, joinRule) // Create a room for alice and charlie to test knocking with roomIDTwo := alice.MustCreateRoom(t, map[string]interface{}{ @@ -85,15 +86,26 @@ func doTestKnocking(t *testing.T, roomVersion string, joinRule string) { inviteWaiter = helpers.NewWaiter() alice.MustInviteRoom(t, roomIDTwo, david) inviteWaiter.Wait(t, 5*time.Second) - serverRoomTwo := srv.MustJoinRoom(t, deployment, "hs1", roomIDTwo, david) + serverRoomTwo := srv.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomIDTwo, david) // Test knocking between two users, each on a separate homeserver - knockingBetweenTwoUsersTest(t, roomIDTwo, alice, charlie, serverRoomTwo, true, joinRule) + knockingBetweenTwoUsersTest(t, deployment, roomIDTwo, alice, charlie, serverRoomTwo, true, joinRule) } -func knockingBetweenTwoUsersTest(t *testing.T, roomID string, inRoomUser, knockingUser *client.CSAPI, serverRoom *federation.ServerRoom, testFederation bool, joinRule string) { +func knockingBetweenTwoUsersTest( + t *testing.T, + deployment complement.Deployment, + roomID string, + inRoomUser, + knockingUser *client.CSAPI, + serverRoom *federation.ServerRoom, + testFederation bool, + joinRule string, +) { t.Run("Knocking on a room with a join rule other than 'knock' should fail", func(t *testing.T) { - knockOnRoomWithStatus(t, knockingUser, roomID, "Can I knock anyways?", []string{"hs1"}, 403) + knockOnRoomWithStatus(t, knockingUser, roomID, "Can I knock anyways?", []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }, 403) }) t.Run("Change the join rule of a room from 'invite' to 'knock'", func(t *testing.T) { @@ -110,18 +122,24 @@ func knockingBetweenTwoUsersTest(t *testing.T, roomID string, inRoomUser, knocki t.Run("Attempting to join a room with join rule 'knock' without an invite should fail", func(t *testing.T) { // Set server_name so we can find rooms via ID over federation - res := knockingUser.JoinRoom(t, roomID, []string{"hs1"}) + res := knockingUser.JoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) must.MatchResponse(t, res, match.HTTPResponse{ StatusCode: 403, }) }) t.Run("Knocking on a room with join rule 'knock' should succeed", func(t *testing.T) { - mustKnockOnRoomSynced(t, knockingUser, roomID, testKnockReason, []string{"hs1"}) + mustKnockOnRoomSynced(t, knockingUser, roomID, testKnockReason, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) }) t.Run("A user that has already knocked is allowed to knock again on the same room", func(t *testing.T) { - mustKnockOnRoomSynced(t, knockingUser, roomID, "I really like knock knock jokes", []string{"hs1"}) + mustKnockOnRoomSynced(t, knockingUser, roomID, "I really like knock knock jokes", []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) }) t.Run("Users in the room see a user's membership update when they knock", func(t *testing.T) { @@ -183,7 +201,9 @@ func knockingBetweenTwoUsersTest(t *testing.T, roomID string, inRoomUser, knocki }) // Knock again to return us to the knocked state - mustKnockOnRoomSynced(t, knockingUser, roomID, "Let me in... again?", []string{"hs1"}) + mustKnockOnRoomSynced(t, knockingUser, roomID, "Let me in... again?", []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) }) } @@ -211,7 +231,9 @@ func knockingBetweenTwoUsersTest(t *testing.T, roomID string, inRoomUser, knocki })) // Knock again - mustKnockOnRoomSynced(t, knockingUser, roomID, "Pleeease let me in?", []string{"hs1"}) + mustKnockOnRoomSynced(t, knockingUser, roomID, "Pleeease let me in?", []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) }) t.Run("A user can knock on a room without a reason", func(t *testing.T) { @@ -227,7 +249,9 @@ func knockingBetweenTwoUsersTest(t *testing.T, roomID string, inRoomUser, knocki ) // Knock again, this time without a reason - mustKnockOnRoomSynced(t, knockingUser, roomID, "", []string{"hs1"}) + mustKnockOnRoomSynced(t, knockingUser, roomID, "", []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) }) t.Run("A user in the room can accept a knock", func(t *testing.T) { @@ -243,13 +267,19 @@ func knockingBetweenTwoUsersTest(t *testing.T, roomID string, inRoomUser, knocki t.Run("A user cannot knock on a room they are already invited to", func(t *testing.T) { reason := "I'm sticking my hand out the window and knocking again!" - knockOnRoomWithStatus(t, knockingUser, roomID, reason, []string{"hs1"}, 403) + knockOnRoomWithStatus(t, knockingUser, roomID, reason, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }, 403) }) t.Run("A user cannot knock on a room they are already in", func(t *testing.T) { - knockingUser.MustJoinRoom(t, roomID, []string{"hs1"}) + knockingUser.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) reason := "I'm sticking my hand out the window and knocking again!" - knockOnRoomWithStatus(t, knockingUser, roomID, reason, []string{"hs1"}, 403) + knockOnRoomWithStatus(t, knockingUser, roomID, reason, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }, 403) }) t.Run("A user that is banned from a room cannot knock on it", func(t *testing.T) { @@ -275,7 +305,9 @@ func knockingBetweenTwoUsersTest(t *testing.T, roomID string, inRoomUser, knocki ev.Get("content").Get("membership").Str != "ban" })) - knockOnRoomWithStatus(t, knockingUser, roomID, "I didn't mean it!", []string{"hs1"}, 403) + knockOnRoomWithStatus(t, knockingUser, roomID, "I didn't mean it!", []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }, 403) }) } @@ -304,7 +336,11 @@ func syncKnockedOn(userID, roomID string) client.SyncCheckOpt { // mustKnockOnRoomSynced will knock on a given room on the behalf of a user, and block until the knock has persisted. // serverNames should be populated if knocking on a room that the user's homeserver isn't currently a part of. // Fails the test if the knock response does not return a 200 status code. -func mustKnockOnRoomSynced(t *testing.T, c *client.CSAPI, roomID, reason string, serverNames []string) { +// +// Args: +// - `serverNames`: The list of servers to attempt to knock on the room through. +// These should be a resolvable addresses within the deplyment network. +func mustKnockOnRoomSynced(t *testing.T, c *client.CSAPI, roomID, reason string, serverNames []spec.ServerName) { knockOnRoomWithStatus(t, c, roomID, reason, serverNames, 200) // The knock should have succeeded. Block until we see the knock appear down sync @@ -314,7 +350,11 @@ func mustKnockOnRoomSynced(t *testing.T, c *client.CSAPI, roomID, reason string, // knockOnRoomWithStatus will knock on a given room on the behalf of a user. // serverNames should be populated if knocking on a room that the user's homeserver isn't currently a part of. // expectedStatus allows setting an expected status code. If the response code differs, the test will fail. -func knockOnRoomWithStatus(t *testing.T, c *client.CSAPI, roomID, reason string, serverNames []string, expectedStatus int) { +// +// Args: +// - `serverNames`: The list of servers to attempt to knock on the room through. +// These should be a resolvable addresses within the deployment network. +func knockOnRoomWithStatus(t *testing.T, c *client.CSAPI, roomID, reason string, serverNames []spec.ServerName, expectedStatus int) { b := []byte("{}") var err error if reason != "" { @@ -331,8 +371,12 @@ func knockOnRoomWithStatus(t *testing.T, c *client.CSAPI, roomID, reason string, } // Add any server names to the query parameters + serverNameStrings := make([]string, len(serverNames)) + for i, serverName := range serverNames { + serverNameStrings[i] = string(serverName) + } query := url.Values{ - "server_name": serverNames, + "server_name": serverNameStrings, } // Knock on the room diff --git a/tests/media_thumbnail_test.go b/tests/media_thumbnail_test.go index 03f9cc8d..dd499f18 100644 --- a/tests/media_thumbnail_test.go +++ b/tests/media_thumbnail_test.go @@ -3,14 +3,6 @@ package tests import ( "bytes" "context" - "github.com/matrix-org/complement" - "github.com/matrix-org/complement/client" - "github.com/matrix-org/complement/federation" - "github.com/matrix-org/complement/helpers" - "github.com/matrix-org/complement/internal/data" - "github.com/matrix-org/complement/runtime" - "github.com/matrix-org/gomatrixserverlib/fclient" - "github.com/matrix-org/gomatrixserverlib/spec" "image/jpeg" "image/png" "io" @@ -20,6 +12,14 @@ import ( "net/url" "strings" "testing" + + "github.com/matrix-org/complement" + "github.com/matrix-org/complement/client" + "github.com/matrix-org/complement/federation" + "github.com/matrix-org/complement/helpers" + "github.com/matrix-org/complement/internal/data" + "github.com/matrix-org/complement/runtime" + "github.com/matrix-org/gomatrixserverlib/fclient" ) // TODO: add JPEG testing @@ -36,11 +36,11 @@ func TestLocalPngThumbnail(t *testing.T) { uri := alice.UploadContent(t, data.LargePng, fileName, contentType) - t.Run("test /_matrix/media/v3 endpoint", func(t *testing.T) { + t.Run("test /_matrix/media/v3 endpoint", func(t *testing.T) { // Synapse no longer allows downloads over the unauthenticated media endpoints by default - runtime.SkipIf(t, runtime.Synapse) + runtime.SkipIf(t, runtime.Synapse) fetchAndValidateThumbnail(t, alice, uri, false) - }) + }) t.Run("test /_matrix/client/v1/media endpoint", func(t *testing.T) { runtime.SkipIf(t, runtime.Dendrite) @@ -62,11 +62,11 @@ func TestRemotePngThumbnail(t *testing.T) { uri := alice.UploadContent(t, data.LargePng, fileName, contentType) - t.Run("test /_matrix/media/v3 endpoint", func(t *testing.T) { + t.Run("test /_matrix/media/v3 endpoint", func(t *testing.T) { // Synapse no longer allows downloads over the unauthenticated media endpoints by default - runtime.SkipIf(t, runtime.Synapse) + runtime.SkipIf(t, runtime.Synapse) fetchAndValidateThumbnail(t, bob, uri, false) - }) + }) t.Run("test /_matrix/client/v1/media endpoint", func(t *testing.T) { runtime.SkipIf(t, runtime.Dendrite) @@ -95,7 +95,7 @@ func TestFederationThumbnail(t *testing.T) { ) cancel := srv.Listen() defer cancel() - origin := spec.ServerName(srv.ServerName()) + origin := srv.ServerName() fileName := "test.png" contentType := "image/png" @@ -122,7 +122,7 @@ func TestFederationThumbnail(t *testing.T) { fedReq := fclient.NewFederationRequest( "GET", origin, - "hs1", + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), "/_matrix/federation/v1/media/thumbnail/"+mediaId+"?method=scale&width=32&height=32", ) diff --git a/tests/msc2836/msc2836_test.go b/tests/msc2836/msc2836_test.go index 92995f09..8437d6dd 100644 --- a/tests/msc2836/msc2836_test.go +++ b/tests/msc2836/msc2836_test.go @@ -19,8 +19,8 @@ import ( "github.com/matrix-org/complement/b" "github.com/matrix-org/complement/client" - "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/federation" + "github.com/matrix-org/complement/helpers" "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" ) @@ -92,7 +92,9 @@ func TestEventRelationships(t *testing.T) { // Join the room from another server bob := deployment.Register(t, "hs2", helpers.RegistrationOpts{}) - _ = bob.MustJoinRoom(t, roomID, []string{"hs1"}) + _ = bob.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, roomID)) // Now hit /event_relationships with eventD @@ -304,7 +306,7 @@ func TestFederatedEventRelationships(t *testing.T) { // join the room on HS1 // HS1 will not have any of these messages, only the room state. - alice.MustJoinRoom(t, room.RoomID, []string{srv.ServerName()}) + alice.MustJoinRoom(t, room.RoomID, []spec.ServerName{srv.ServerName()}) // send a new child in the thread (child of D) so the HS has something to latch on to. eventE := srv.MustCreateEvent(t, room, federation.Event{ @@ -323,8 +325,8 @@ func TestFederatedEventRelationships(t *testing.T) { fedClient := srv.FederationClient(deployment) _, err := fedClient.SendTransaction(context.Background(), gomatrixserverlib.Transaction{ TransactionID: "complement", - Origin: spec.ServerName(srv.ServerName()), - Destination: spec.ServerName("hs1"), + Origin: srv.ServerName(), + Destination: deployment.GetFullyQualifiedHomeserverName(t, "hs1"), OriginServerTS: spec.AsTimestamp(time.Now()), PDUs: []json.RawMessage{ eventE.JSON(), diff --git a/tests/msc3902/federation_room_join_partial_state_test.go b/tests/msc3902/federation_room_join_partial_state_test.go index 2e5fc030..48b86814 100644 --- a/tests/msc3902/federation_room_join_partial_state_test.go +++ b/tests/msc3902/federation_room_join_partial_state_test.go @@ -560,7 +560,7 @@ func TestPartialStateJoin(t *testing.T) { Type: "m.typing", Content: content, } - psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{}, []gomatrixserverlib.EDU{edu}) + psjResult.Server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{}, []gomatrixserverlib.EDU{edu}) // Alice should be able to see that Derek is typing (even though HS1 is resyncing). aliceNextBatch := alice.MustSyncUntil(t, @@ -575,7 +575,7 @@ func TestPartialStateJoin(t *testing.T) { // (See https://github.com/matrix-org/synapse/issues/13684) event := psjResult.CreateMessageEvent(t, "charlie", nil) serverRoom.AddEvent(event) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{event.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{event.JSON()}, nil) aliceNextBatch = awaitEventViaSync(t, alice, serverRoom.RoomID, event.EventID(), aliceNextBatch) // The resync completes. @@ -591,7 +591,7 @@ func TestPartialStateJoin(t *testing.T) { Type: "m.typing", Content: content, } - psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{}, []gomatrixserverlib.EDU{edu}) + psjResult.Server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{}, []gomatrixserverlib.EDU{edu}) // Alice should be able to see that no-one is typing. alice.MustSyncUntil(t, @@ -634,7 +634,7 @@ func TestPartialStateJoin(t *testing.T) { Type: "m.presence", Content: content, } - psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{}, []gomatrixserverlib.EDU{edu}) + psjResult.Server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{}, []gomatrixserverlib.EDU{edu}) alice.MustSyncUntil(t, client.SyncReq{ @@ -683,7 +683,7 @@ func TestPartialStateJoin(t *testing.T) { Type: "m.direct_to_device", Content: content, } - psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{}, []gomatrixserverlib.EDU{edu}) + psjResult.Server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{}, []gomatrixserverlib.EDU{edu}) // Alice should see Derek's to-device message when she syncs. alice.MustSyncUntil(t, @@ -735,7 +735,7 @@ func TestPartialStateJoin(t *testing.T) { Type: "m.receipt", Content: content, } - psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{}, []gomatrixserverlib.EDU{edu}) + psjResult.Server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{}, []gomatrixserverlib.EDU{edu}) // Alice should be able to see Derek's read receipt during the resync alice.MustSyncUntil(t, @@ -781,7 +781,7 @@ func TestPartialStateJoin(t *testing.T) { Content: content, } aliceNextBatch := getSyncToken(t, alice) - psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{}, []gomatrixserverlib.EDU{edu}) + psjResult.Server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{}, []gomatrixserverlib.EDU{edu}) // The resync completes. psjResult.FinishStateRequest() @@ -828,7 +828,7 @@ func TestPartialStateJoin(t *testing.T) { Type: "m.signing_key_update", Content: content, } - psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{}, []gomatrixserverlib.EDU{edu}) + psjResult.Server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{}, []gomatrixserverlib.EDU{edu}) // If we want to check the sync we need to have an encrypted room, // for now just check that the fed transaction is accepted. @@ -1007,7 +1007,7 @@ func TestPartialStateJoin(t *testing.T) { // derek sends a message into the room. event := psjResult.CreateMessageEvent(t, "derek", nil) t.Logf("Derek created event with ID %s", event.EventID()) - psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{event.JSON()}, nil) + psjResult.Server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{event.JSON()}, nil) // wait for the homeserver to persist the event. awaitEventArrival(t, time.Second, alice, serverRoom.RoomID, event.EventID()) @@ -1059,7 +1059,7 @@ func TestPartialStateJoin(t *testing.T) { event2 := psjResult.CreateMessageEvent(t, "derek", nil) t.Logf("Derek created event 1 with ID %s", event1.EventID()) t.Logf("Derek created event 2 with ID %s", event2.EventID()) - psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{event1.JSON(), event2.JSON()}, nil) + psjResult.Server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{event1.JSON(), event2.JSON()}, nil) // wait for the homeserver to persist the event. awaitEventArrival(t, 5*time.Second, alice, serverRoom.RoomID, event2.EventID()) @@ -1128,7 +1128,7 @@ func TestPartialStateJoin(t *testing.T) { // derek sends a message into the room. event := psjResult.CreateMessageEvent(t, "derek", nil) - psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{event.JSON()}, nil) + psjResult.Server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{event.JSON()}, nil) t.Logf("Derek created event with ID %s", event.EventID()) // wait for the homeserver to persist the event. @@ -1283,7 +1283,7 @@ func TestPartialStateJoin(t *testing.T) { defer cancelListener() // join complement to the public room - room := server.MustJoinRoom(t, deployment, "hs1", roomID, server.UserID("david")) + room := server.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, server.UserID("david")) // we expect a /state_ids request from hs2 after it joins the room // we will respond to the request with garbage @@ -1307,12 +1307,12 @@ func TestPartialStateJoin(t *testing.T) { ).Methods("GET") // join charlie on hs2 to the room, via the complement homeserver - charlie.MustJoinRoom(t, roomID, []string{server.ServerName()}) + charlie.MustJoinRoom(t, roomID, []spec.ServerName{server.ServerName()}) // and let hs1 know that charlie has joined, // otherwise hs1 will refuse /state_ids requests member_event := room.CurrentState("m.room.member", charlie.UserID).JSON() - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{member_event}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{member_event}, nil) alice.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(charlie.UserID, roomID)) // wait until hs2 starts syncing state @@ -1385,7 +1385,7 @@ func TestPartialStateJoin(t *testing.T) { }) lastEventID = event.EventID() serverRoom.AddEvent(event) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{event.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{event.JSON()}, nil) } // wait for the events to come down a /sync. @@ -1495,14 +1495,14 @@ func TestPartialStateJoin(t *testing.T) { // now, send over the most recent event, which will make the server get_missing_events // (we will send timelineEvent1), and then request state (we will send all the outliers). - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{timelineEvent2.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{timelineEvent2.JSON()}, nil) t.Logf("Charlie sent timeline event 2") // wait for it to become visible, which implies that all the outliers have been pulled in. awaitEventViaSync(t, alice, serverRoom.RoomID, timelineEvent2.EventID(), syncToken) // now we send over all the other events in the gap. - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{lateEvent.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{lateEvent.JSON()}, nil) t.Logf("Charlie sent late event") for i := 0; i < len(outliers); { @@ -1511,7 +1511,7 @@ func TestPartialStateJoin(t *testing.T) { for j := i; j < i+50 && j < len(outliers); j++ { transactionEvents = append(transactionEvents, outliers[j].JSON()) } - server.MustSendTransaction(t, deployment, "hs1", transactionEvents, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), transactionEvents, nil) t.Logf("Charlie sent %d ex-outliers", len(transactionEvents)) i += len(transactionEvents) } @@ -1588,7 +1588,7 @@ func TestPartialStateJoin(t *testing.T) { serverRoom.AddEvent(sentinelEvent) t.Logf("charlie created sentinel event %s", sentinelEvent.EventID()) - server.MustSendTransaction(t, deployment, "hs1", + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{badStateEvent.JSON(), sentinelEvent.JSON()}, nil) // wait for the sentinel event to be visible @@ -1680,7 +1680,7 @@ func TestPartialStateJoin(t *testing.T) { serverRoom.Depth = badStateEvent.Depth() serverRoom.ForwardExtremities = []string{badStateEvent.EventID()} t.Logf("derek created bad state event %s with auth events %#v", badStateEvent.EventID(), badStateEvent.AuthEventIDs()) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{badStateEvent.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{badStateEvent.JSON()}, nil) // the bad state event should be visible at this point syncToken = awaitEventViaSync(t, alice, serverRoom.RoomID, badStateEvent.EventID(), syncToken) @@ -1785,7 +1785,7 @@ func TestPartialStateJoin(t *testing.T) { serverRoom.AddEvent(sentinelEvent) t.Logf("charlie created sentinel event %s", sentinelEvent.EventID()) - server.MustSendTransaction(t, deployment, "hs1", + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{badKickEvent.JSON(), rejectedStateEvent.JSON(), sentinelEvent.JSON()}, nil) // the bad kick event should be visible at this point @@ -1853,7 +1853,7 @@ func TestPartialStateJoin(t *testing.T) { fedClient2 := testServer2.FederationClient(deployment) // charlie sends a make_join - _, err := fedClient2.MakeJoin(context.Background(), spec.ServerName(testServer2.ServerName()), "hs1", roomID, testServer2.UserID("charlie")) + _, err := fedClient2.MakeJoin(context.Background(), testServer2.ServerName(), deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, testServer2.UserID("charlie")) if err == nil { t.Errorf("MakeJoin returned 200, want 404") @@ -1919,12 +1919,12 @@ func TestPartialStateJoin(t *testing.T) { t.Fatalf("MakeRespMakeJoin: invalid room version: %s", err) } eb := verImpl.NewEventBuilderFromProtoEvent(&makeJoinResp.JoinEvent) - joinEvent, err := eb.Build(time.Now(), spec.ServerName(testServer2.ServerName()), testServer2.KeyID, testServer2.Priv) + joinEvent, err := eb.Build(time.Now(), testServer2.ServerName(), testServer2.KeyID, testServer2.Priv) must.NotError(t, "JoinEvent.Build", err) // SendJoin should return a 404 because the homeserver under test has not // finished its partial join. - _, err = fedClient2.SendJoin(context.Background(), spec.ServerName(testServer2.ServerName()), "hs1", joinEvent) + _, err = fedClient2.SendJoin(context.Background(), testServer2.ServerName(), deployment.GetFullyQualifiedHomeserverName(t, "hs1"), joinEvent) if err == nil { t.Errorf("SendJoin returned 200, want 404") } else if httpError, ok := err.(gomatrix.HTTPError); ok { @@ -2031,7 +2031,7 @@ func TestPartialStateJoin(t *testing.T) { fedClient2 := testServer2.FederationClient(deployment) // charlie sends a make_knock - _, err := fedClient2.MakeKnock(context.Background(), spec.ServerName(testServer2.ServerName()), "hs1", roomID, testServer2.UserID("charlie"), federation.SupportedRoomVersions()) + _, err := fedClient2.MakeKnock(context.Background(), testServer2.ServerName(), deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, testServer2.UserID("charlie"), federation.SupportedRoomVersions()) if err == nil { t.Errorf("MakeKnock returned 200, want 404") @@ -2097,12 +2097,12 @@ func TestPartialStateJoin(t *testing.T) { t.Fatalf("MakeRespMakeJoin: invalid room version: %s", err) } eb := verImpl.NewEventBuilderFromProtoEvent(&makeKnockResp.KnockEvent) - knockEvent, err := eb.Build(time.Now(), spec.ServerName(testServer2.ServerName()), testServer2.KeyID, testServer2.Priv) + knockEvent, err := eb.Build(time.Now(), testServer2.ServerName(), testServer2.KeyID, testServer2.Priv) must.NotError(t, "KnockEvent.Build", err) // SendKnock should return a 404 because the homeserver under test has not // finished its partial join. - _, err = fedClient2.SendKnock(context.Background(), spec.ServerName(testServer2.ServerName()), "hs1", knockEvent) + _, err = fedClient2.SendKnock(context.Background(), testServer2.ServerName(), deployment.GetFullyQualifiedHomeserverName(t, "hs1"), knockEvent) if err == nil { t.Errorf("SendKnock returned 200, want 404") } else if httpError, ok := err.(gomatrix.HTTPError); ok { @@ -2241,7 +2241,7 @@ func TestPartialStateJoin(t *testing.T) { server2Room := server2.MustJoinRoom( t, deployment, - spec.ServerName(server1.ServerName()), + server1.ServerName(), room.RoomID, server2.UserID("elsie"), federation.WithPartialState(), @@ -2289,7 +2289,7 @@ func TestPartialStateJoin(t *testing.T) { server2Room := server2.MustJoinRoom( t, deployment, - spec.ServerName(server1.ServerName()), + server1.ServerName(), room.RoomID, server2.UserID("elsie"), federation.WithPartialState(), @@ -2298,7 +2298,7 @@ func TestPartialStateJoin(t *testing.T) { // is idempotent. Here we wait for server 2 to observe the leave too. defer server2.WithWaitForLeave(t, server2Room, alice.UserID, func() { psjResult.Destroy(t) }) joinEvent := room.CurrentState("m.room.member", server2.UserID("elsie")) - server1.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{joinEvent.JSON()}, nil) + server1.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{joinEvent.JSON()}, nil) awaitEventViaSync(t, alice, room.RoomID, joinEvent.EventID(), "") // Both servers should receive device list updates now. @@ -2331,7 +2331,7 @@ func TestPartialStateJoin(t *testing.T) { server2.MustJoinRoom( t, deployment, - spec.ServerName(server1.ServerName()), + server1.ServerName(), room.RoomID, server2.UserID("elsie"), federation.WithPartialState(), @@ -2346,7 +2346,7 @@ func TestPartialStateJoin(t *testing.T) { // not give server2 a complete or up to date copy of the room state. leaveEvent := createLeaveEvent(t, server2, room, server2.UserID("elsie")) room.AddEvent(leaveEvent) - server1.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{leaveEvent.JSON()}, nil) + server1.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{leaveEvent.JSON()}, nil) awaitEventViaSync(t, alice, room.RoomID, leaveEvent.EventID(), "") // Both homeservers should receive device list updates, since hs1 cannot know that @@ -2405,13 +2405,13 @@ func TestPartialStateJoin(t *testing.T) { server2Room = server2.MustJoinRoom( t, deployment, - spec.ServerName(server1.ServerName()), + server1.ServerName(), room.RoomID, elsie, federation.WithPartialState(), ) joinEvent := room.CurrentState("m.room.member", elsie) - server1.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{joinEvent.JSON()}, nil) + server1.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{joinEvent.JSON()}, nil) syncToken = awaitEventViaSync(t, alice, room.RoomID, joinEvent.EventID(), "") // Both servers should receive device list updates. @@ -2435,7 +2435,7 @@ func TestPartialStateJoin(t *testing.T) { room.Timeline = append(room.Timeline, badKickEvent) room.Depth = badKickEvent.Depth() room.ForwardExtremities = []string{badKickEvent.EventID()} - server1.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{badKickEvent.JSON()}, nil) + server1.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{badKickEvent.JSON()}, nil) awaitEventViaSync(t, alice, room.RoomID, badKickEvent.EventID(), syncToken) return syncToken, server2Room, psjResult @@ -2455,7 +2455,7 @@ func TestPartialStateJoin(t *testing.T) { roomID := alice.MustCreateRoom(t, map[string]interface{}{"preset": "public_chat"}) // @elsie:server2 joins the room. - server2Room := server2.MustJoinRoom(t, deployment, "hs1", roomID, elsie) + server2Room := server2.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), roomID, elsie) alice.MustSyncUntil(t, client.SyncReq{ Since: syncToken, @@ -2469,7 +2469,7 @@ func TestPartialStateJoin(t *testing.T) { // server2 a complete or up to date copy of the room state. leaveEvent := createLeaveEvent(t, server2, partialStateRoom, elsie) partialStateRoom.AddEvent(leaveEvent) - server1.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{leaveEvent.JSON()}, nil) + server1.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{leaveEvent.JSON()}, nil) syncToken = awaitEventViaSync(t, alice, partialStateRoom.RoomID, leaveEvent.EventID(), syncToken) leaveSharedRoom = func() { @@ -2587,7 +2587,7 @@ func TestPartialStateJoin(t *testing.T) { server2Room := server2.MustJoinRoom( t, deployment, - spec.ServerName(server1.ServerName()), + server1.ServerName(), room.RoomID, server2.UserID("elsie"), federation.WithPartialState(), @@ -2618,7 +2618,7 @@ func TestPartialStateJoin(t *testing.T) { server2.MustJoinRoom( t, deployment, - spec.ServerName(server1.ServerName()), + server1.ServerName(), room.RoomID, server2.UserID("elsie"), federation.WithPartialState(), @@ -2776,11 +2776,11 @@ func TestPartialStateJoin(t *testing.T) { Deleted: false, Keys: keys, }) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{}, []gomatrixserverlib.EDU{ + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{}, []gomatrixserverlib.EDU{ { Type: "m.device_list_update", - Origin: server.ServerName(), - Destination: "hs1", + Origin: string(server.ServerName()), + Destination: string(deployment.GetFullyQualifiedHomeserverName(t, "hs1")), Content: deviceListUpdate, }, }) @@ -2931,7 +2931,7 @@ func TestPartialStateJoin(t *testing.T) { // @charlie sends a message. // Depending on the homeserver implementation, @t30alice:hs1 may be told that @charlie's devices are being tracked. event := psjResult.CreateMessageEvent(t, "charlie", nil) - psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{event.JSON()}, nil) + psjResult.Server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{event.JSON()}, nil) syncToken := awaitEventViaSync(t, alice, psjResult.ServerRoom.RoomID, event.EventID(), "") // @charlie updates their device list. @@ -2941,7 +2941,7 @@ func TestPartialStateJoin(t *testing.T) { // Before completing the partial state join, try to wait for the homeserver to finish processing the device list update. event = psjResult.CreateMessageEvent(t, "charlie", nil) - psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{event.JSON()}, nil) + psjResult.Server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{event.JSON()}, nil) awaitEventViaSync(t, alice, psjResult.ServerRoom.RoomID, event.EventID(), syncToken) // Finish the partial state join. @@ -2975,7 +2975,7 @@ func TestPartialStateJoin(t *testing.T) { // @charlie sends a message. // Depending on the homeserver implementation, @t31alice:hs1 may be told that @charlie's devices are being tracked. event := psjResult.CreateMessageEvent(t, "charlie", nil) - psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{event.JSON()}, nil) + psjResult.Server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{event.JSON()}, nil) syncToken := awaitEventViaSync(t, alice, psjResult.ServerRoom.RoomID, event.EventID(), "") // @charlie updates their device list. @@ -2988,7 +2988,7 @@ func TestPartialStateJoin(t *testing.T) { // @charlie joins the room. // Now @charlie's device list is definitely being tracked. - otherRoom := server.MustJoinRoom(t, deployment, "hs1", otherRoomID, server.UserID("charlie")) + otherRoom := server.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), otherRoomID, server.UserID("charlie")) alice.MustSyncUntil(t, client.SyncReq{ Since: syncToken, @@ -3021,7 +3021,7 @@ func TestPartialStateJoin(t *testing.T) { // @elsie joins the room. joinEvent := createJoinEvent(t, server, room, server.UserID("elsie")) room.AddEvent(joinEvent) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{joinEvent.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{joinEvent.JSON()}, nil) awaitEventViaSync(t, alice, room.RoomID, joinEvent.EventID(), syncToken) // hs1 should now be tracking @elsie's device list. Enforce this in two steps: @@ -3070,7 +3070,7 @@ func TestPartialStateJoin(t *testing.T) { // @elsie joins the room. joinEvent := createJoinEvent(t, server, room, server.UserID("elsie")) room.AddEvent(joinEvent) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{joinEvent.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{joinEvent.JSON()}, nil) awaitEventViaSync(t, alice, room.RoomID, joinEvent.EventID(), syncToken) // hs1 should now be tracking @elsie's device list. Enforce this in two steps: @@ -3086,7 +3086,7 @@ func TestPartialStateJoin(t *testing.T) { // @elsie leaves the room. leaveEvent := createLeaveEvent(t, server, room, server.UserID("elsie")) room.AddEvent(leaveEvent) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{leaveEvent.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{leaveEvent.JSON()}, nil) awaitEventViaSync(t, alice, room.RoomID, leaveEvent.EventID(), syncToken) // hs1 should no longer be tracking elsie's device list; subsequent @@ -3115,7 +3115,7 @@ func TestPartialStateJoin(t *testing.T) { // @elsie joins the room. joinEvent := createJoinEvent(t, server, room, server.UserID("elsie")) room.AddEvent(joinEvent) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{joinEvent.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{joinEvent.JSON()}, nil) awaitEventViaSync(t, alice, room.RoomID, joinEvent.EventID(), syncToken) // hs1 should now be tracking @elsie's device list. Enforce this in two steps: @@ -3157,7 +3157,7 @@ func TestPartialStateJoin(t *testing.T) { // @elsie joins the room. joinEvent := createJoinEvent(t, server, room, server.UserID("elsie")) room.AddEvent(joinEvent) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{joinEvent.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{joinEvent.JSON()}, nil) awaitEventViaSync(t, alice, room.RoomID, joinEvent.EventID(), "") // hs1 should now be tracking @elsie's device list. Enforce this in two steps: @@ -3218,7 +3218,7 @@ func TestPartialStateJoin(t *testing.T) { // @elsie joins the room. joinEvent := createJoinEvent(t, server, room, elsie) room.AddEvent(joinEvent) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{joinEvent.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{joinEvent.JSON()}, nil) syncToken = awaitEventViaSync(t, alice, room.RoomID, joinEvent.EventID(), "") // @fred "bans" @derek. @@ -3240,7 +3240,7 @@ func TestPartialStateJoin(t *testing.T) { room.Timeline = append(room.Timeline, badKickEvent) room.Depth = badKickEvent.Depth() room.ForwardExtremities = []string{badKickEvent.EventID()} - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{badKickEvent.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{badKickEvent.JSON()}, nil) syncToken = awaitEventViaSync(t, alice, room.RoomID, badKickEvent.EventID(), syncToken) // @derek kicks @elsie. @@ -3253,12 +3253,12 @@ func TestPartialStateJoin(t *testing.T) { Content: map[string]interface{}{"membership": "leave"}, }) room.AddEvent(kickEvent) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{kickEvent.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{kickEvent.JSON()}, nil) // Ensure that the kick event has been persisted. sentinelEvent := psjResult.CreateMessageEvent(t, "charlie", nil) room.AddEvent(sentinelEvent) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{sentinelEvent.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{sentinelEvent.JSON()}, nil) syncToken = awaitEventViaSync(t, alice, room.RoomID, sentinelEvent.EventID(), syncToken) // Check that the last kick was incorrectly rejected. @@ -3332,7 +3332,7 @@ func TestPartialStateJoin(t *testing.T) { // @elsie rejoins the room. joinEvent := createJoinEvent(t, server, room, server.UserID("elsie")) room.AddEvent(joinEvent) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{joinEvent.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{joinEvent.JSON()}, nil) awaitEventViaSync(t, alice, room.RoomID, joinEvent.EventID(), syncToken) // @elsie's device list is still cached. @@ -3381,7 +3381,7 @@ func TestPartialStateJoin(t *testing.T) { // @elsie rejoins the room. joinEvent := createJoinEvent(t, server, room, server.UserID("elsie")) room.AddEvent(joinEvent) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{joinEvent.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{joinEvent.JSON()}, nil) awaitEventViaSync(t, alice, room.RoomID, joinEvent.EventID(), syncToken) // @elsie's device list ought to have been flushed from the cache. @@ -3416,7 +3416,7 @@ func TestPartialStateJoin(t *testing.T) { // @elsie joins the room. // The homeserver under test is now subscribed to @elsie's device list updates. - server.MustJoinRoom(t, deployment, "hs1", otherRoomID, server.UserID("elsie")) + server.MustJoinRoom(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), otherRoomID, server.UserID("elsie")) alice.MustSyncUntil(t, client.SyncReq{ Since: syncToken, @@ -3554,7 +3554,7 @@ func TestPartialStateJoin(t *testing.T) { defer psjResult.Destroy(t) server.AddPDUHandler(func(e gomatrixserverlib.PDU) bool { return true }) - bob.MustJoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) + bob.MustJoinRoom(t, serverRoom.RoomID, []spec.ServerName{server.ServerName()}) alice.MustSyncUntil(t, client.SyncReq{ Filter: buildLazyLoadingSyncFilter(nil), @@ -3748,7 +3748,7 @@ func TestPartialStateJoin(t *testing.T) { ) t.Log("Bob joins too") - bob.MustJoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) + bob.MustJoinRoom(t, serverRoom.RoomID, []spec.ServerName{server.ServerName()}) t.Log("Bob waits to see his join") bobNextBatch := bob.MustSyncUntil( @@ -3809,7 +3809,7 @@ func TestPartialStateJoin(t *testing.T) { // The resync has not completed because we have not called psjResult.FinishStateRequest() t.Log("Alice rejoins her room") - alice.MustJoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) + alice.MustJoinRoom(t, serverRoom.RoomID, []spec.ServerName{server.ServerName()}) aliceNextBatch = alice.MustSyncUntil( t, client.SyncReq{Since: aliceNextBatch, Filter: buildLazyLoadingSyncFilter(nil)}, @@ -3857,7 +3857,7 @@ func TestPartialStateJoin(t *testing.T) { // The resync has not completed because we have not called psjResult.FinishStateRequest() t.Log("Now Bob joins the room") - bob.MustJoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) + bob.MustJoinRoom(t, serverRoom.RoomID, []spec.ServerName{server.ServerName()}) bob.MustSyncUntil( t, client.SyncReq{Filter: buildLazyLoadingSyncFilter(nil)}, @@ -3901,7 +3901,7 @@ func TestPartialStateJoin(t *testing.T) { }), }) serverRoom.AddEvent(kickEvent) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{kickEvent.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{kickEvent.JSON()}, nil) // The kick occurs mid-resync, because we have not yet called // psjResult.FinishStateRequest(). @@ -3955,7 +3955,7 @@ func TestPartialStateJoin(t *testing.T) { }), }) serverRoom.AddEvent(banEvent) - server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{banEvent.JSON()}, nil) + server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{banEvent.JSON()}, nil) // The ban occurs mid-resync, because we have not yet called // psjResult.FinishStateRequest(). @@ -3969,7 +3969,7 @@ func TestPartialStateJoin(t *testing.T) { ) t.Log("Alice tries to rejoin...") - response := alice.JoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) + response := alice.JoinRoom(t, serverRoom.RoomID, []spec.ServerName{server.ServerName()}) t.Log("... but Alice was forbidden from rejoining") must.MatchResponse(t, response, match.HTTPResponse{StatusCode: http.StatusForbidden}) @@ -4181,7 +4181,7 @@ func testReceiveEventDuringPartialStateJoin( t *testing.T, deployment complement.Deployment, alice *client.CSAPI, psjResult partialStateJoinResult, event gomatrixserverlib.PDU, syncToken string, ) string { // send the event to the homeserver - psjResult.Server.MustSendTransaction(t, deployment, "hs1", []json.RawMessage{event.JSON()}, nil) + psjResult.Server.MustSendTransaction(t, deployment, deployment.GetFullyQualifiedHomeserverName(t, "hs1"), []json.RawMessage{event.JSON()}, nil) syncToken = awaitEventViaSync(t, alice, psjResult.ServerRoom.RoomID, event.EventID(), syncToken) @@ -4194,7 +4194,7 @@ func testReceiveEventDuringPartialStateJoin( // is resolved. For now, we use this to check whether Synapse has calculated the partial state // flag for the last event correctly. - stateReq := fclient.NewFederationRequest("GET", spec.ServerName(psjResult.Server.ServerName()), "hs1", + stateReq := fclient.NewFederationRequest("GET", psjResult.Server.ServerName(), deployment.GetFullyQualifiedHomeserverName(t, "hs1"), fmt.Sprintf("/_matrix/federation/v1/state_ids/%s?event_id=%s", url.PathEscape(psjResult.ServerRoom.RoomID), url.QueryEscape(event.EventID()), @@ -4238,7 +4238,7 @@ func testReceiveEventDuringPartialStateJoin( ) // check the server's idea of the state at the event. We do this by making a `state_ids` request over federation - stateReq = fclient.NewFederationRequest("GET", spec.ServerName(psjResult.Server.ServerName()), "hs1", + stateReq = fclient.NewFederationRequest("GET", psjResult.Server.ServerName(), deployment.GetFullyQualifiedHomeserverName(t, "hs1"), fmt.Sprintf("/_matrix/federation/v1/state_ids/%s?event_id=%s", url.PathEscape(psjResult.ServerRoom.RoomID), url.QueryEscape(event.EventID()), @@ -4391,7 +4391,7 @@ func beginPartialStateJoin(t *testing.T, server *server, serverRoom *federation. ) // have joiningUser join the room by room ID. - joiningUser.MustJoinRoom(t, serverRoom.RoomID, []string{server.ServerName()}) + joiningUser.MustJoinRoom(t, serverRoom.RoomID, []spec.ServerName{server.ServerName()}) t.Logf("/join request completed") success = true diff --git a/tests/restricted_room_hierarchy_test.go b/tests/restricted_room_hierarchy_test.go index fec2e8b5..32ad0f0a 100644 --- a/tests/restricted_room_hierarchy_test.go +++ b/tests/restricted_room_hierarchy_test.go @@ -13,6 +13,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/spec" ) // Request the room summary and ensure the expected rooms are in the response. @@ -74,7 +75,7 @@ func TestRestrictedRoomsSpacesSummaryLocal(t *testing.T) { { "type": "m.room_membership", "room_id": &space, - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }, }, @@ -85,7 +86,7 @@ func TestRestrictedRoomsSpacesSummaryLocal(t *testing.T) { Type: "m.space.child", StateKey: &room, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }) @@ -99,7 +100,9 @@ func TestRestrictedRoomsSpacesSummaryLocal(t *testing.T) { requestAndAssertSummary(t, bob, space, []interface{}{space}) // Join the space, and now the restricted room should appear. - bob.MustJoinRoom(t, space, []string{"hs1"}) + bob.MustJoinRoom(t, space, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) bob.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(bob.UserID, space)) requestAndAssertSummary(t, bob, space, []interface{}{space, room}) } @@ -158,7 +161,7 @@ func TestRestrictedRoomsSpacesSummaryFederation(t *testing.T) { { "type": "m.room_membership", "room_id": &space, - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }, }, @@ -183,7 +186,9 @@ func TestRestrictedRoomsSpacesSummaryFederation(t *testing.T) { // charlie joins the space and now hs2 knows that alice is in the space (and // can join the room). - charlie.MustJoinRoom(t, space, []string{"hs1"}) + charlie.MustJoinRoom(t, space, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) charlie.MustSyncUntil(t, client.SyncReq{}, client.SyncJoinedTo(charlie.UserID, space)) // The restricted room should appear for alice (who is in the space). diff --git a/tests/restricted_rooms_test.go b/tests/restricted_rooms_test.go index 4d31f169..2787ad74 100644 --- a/tests/restricted_rooms_test.go +++ b/tests/restricted_rooms_test.go @@ -14,6 +14,7 @@ import ( "github.com/matrix-org/complement/match" "github.com/matrix-org/complement/must" "github.com/matrix-org/complement/runtime" + "github.com/matrix-org/gomatrixserverlib/spec" ) // Creates two rooms on room version 8 and sets the second room to have @@ -43,7 +44,7 @@ func setupRestrictedRoom(t *testing.T, deployment complement.Deployment, roomVer { "type": "m.room_membership", "room_id": &allowed_room, - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }, }, @@ -54,17 +55,21 @@ func setupRestrictedRoom(t *testing.T, deployment complement.Deployment, roomVer return alice, allowed_room, room } -func checkRestrictedRoom(t *testing.T, alice *client.CSAPI, bob *client.CSAPI, allowed_room string, room string, joinRule string) { +func checkRestrictedRoom(t *testing.T, deployment complement.Deployment, alice *client.CSAPI, bob *client.CSAPI, allowed_room string, room string, joinRule string) { t.Helper() t.Run("Join should fail initially", func(t *testing.T) { - res := bob.JoinRoom(t, room, []string{"hs1"}) + res := bob.JoinRoom(t, room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) must.MatchFailure(t, res) }) t.Run("Join should succeed when joined to allowed room", func(t *testing.T) { // Join the allowed room. - bob.JoinRoom(t, allowed_room, []string{"hs1"}) + bob.JoinRoom(t, allowed_room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // Confirm that we joined the allowed room by changing displayname and // waiting for confirmation in the /sync response. (This is an attempt @@ -86,7 +91,9 @@ func checkRestrictedRoom(t *testing.T, alice *client.CSAPI, bob *client.CSAPI, a ) // We should now be able to join the restricted room. - bob.JoinRoom(t, room, []string{"hs1"}) + bob.JoinRoom(t, room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // Joining the same room again should work fine (e.g. to change your display name). bob.SendEventSynced( @@ -123,18 +130,24 @@ func checkRestrictedRoom(t *testing.T, alice *client.CSAPI, bob *client.CSAPI, a return ev.Get("content").Get("membership").Str == "leave" })) - res := bob.JoinRoom(t, room, []string{"hs1"}) + res := bob.JoinRoom(t, room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) must.MatchFailure(t, res) }) t.Run("Join should succeed when invited", func(t *testing.T) { // Invite the user and joining should work. alice.MustInviteRoom(t, room, bob.UserID) - bob.JoinRoom(t, room, []string{"hs1"}) + bob.JoinRoom(t, room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // Leave the room again, and join the allowed room. bob.MustLeaveRoom(t, room) - bob.JoinRoom(t, allowed_room, []string{"hs1"}) + bob.JoinRoom(t, allowed_room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) }) t.Run("Join should fail with mangled join rules", func(t *testing.T) { @@ -155,7 +168,9 @@ func checkRestrictedRoom(t *testing.T, alice *client.CSAPI, bob *client.CSAPI, a }, ) // Fails since invalid values get filtered out of allow. - must.MatchFailure(t, bob.JoinRoom(t, room, []string{"hs1"})) + must.MatchFailure(t, bob.JoinRoom(t, room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + })) alice.SendEventSynced( t, @@ -171,7 +186,9 @@ func checkRestrictedRoom(t *testing.T, alice *client.CSAPI, bob *client.CSAPI, a }, ) // Fails since a fully invalid allow key requires an invite. - must.MatchFailure(t, bob.JoinRoom(t, room, []string{"hs1"})) + must.MatchFailure(t, bob.JoinRoom(t, room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + })) }) } @@ -187,7 +204,7 @@ func TestRestrictedRoomsLocalJoin(t *testing.T) { bob := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) // Execute the checks. - checkRestrictedRoom(t, alice, bob, allowed_room, room, "restricted") + checkRestrictedRoom(t, deployment, alice, bob, allowed_room, room, "restricted") } // Test joining a room with join rules restricted to membership in another room. @@ -202,7 +219,7 @@ func TestRestrictedRoomsRemoteJoin(t *testing.T) { bob := deployment.Register(t, "hs2", helpers.RegistrationOpts{}) // Execute the checks. - checkRestrictedRoom(t, alice, bob, allowed_room, room, "restricted") + checkRestrictedRoom(t, deployment, alice, bob, allowed_room, room, "restricted") } // A server will do a remote join for a local user if it is unable to to issue @@ -241,7 +258,7 @@ func doTestRestrictedRoomsRemoteJoinLocalUser(t *testing.T, roomVersion string, { "type": "m.room_membership", "room_id": &allowed_room, - "via": []string{"hs2"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs2"))}, }, }, }, @@ -252,7 +269,9 @@ func doTestRestrictedRoomsRemoteJoinLocalUser(t *testing.T, roomVersion string, // Invite alice manually and accept it. alice := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) charlie.MustInviteRoom(t, room, alice.UserID) - alice.JoinRoom(t, room, []string{"hs2"}) + alice.JoinRoom(t, room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs2"), + }) // Confirm that Alice cannot issue invites (due to the default power levels). bob := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) @@ -262,13 +281,19 @@ func doTestRestrictedRoomsRemoteJoinLocalUser(t *testing.T, roomVersion string, }) // Bob cannot join the room. - must.MatchFailure(t, bob.JoinRoom(t, room, []string{"hs1"})) + must.MatchFailure(t, bob.JoinRoom(t, room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + })) // Join the allowed room via hs2. - bob.JoinRoom(t, allowed_room, []string{"hs2"}) + bob.JoinRoom(t, allowed_room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs2"), + }) // Joining the room should work, although we're joining via hs1, it will end up // as a remote join through hs2. - bob.JoinRoom(t, room, []string{"hs1"}) + bob.JoinRoom(t, room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // Ensure that the join comes down sync on hs2. Note that we want to ensure hs2 // accepted the event. @@ -316,7 +341,9 @@ func doTestRestrictedRoomsRemoteJoinLocalUser(t *testing.T, roomVersion string, // Have bob leave and rejoin. This should still work even though hs2 isn't in // the room anymore! bob.MustLeaveRoom(t, room) - bob.JoinRoom(t, room, []string{"hs1"}) + bob.JoinRoom(t, room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) } // A server will request a failover if asked to /make_join and it does not have @@ -361,22 +388,33 @@ func doTestRestrictedRoomsRemoteJoinFailOver(t *testing.T, roomVersion string, j // Bob joins the room and allowed room. t.Logf("%s joins the authorizing room via hs1.", bob.UserID) t.Logf("%s joins the restricted room via hs1.", bob.UserID) - bob.JoinRoom(t, allowed_room, []string{"hs1"}) - bob.JoinRoom(t, room, []string{"hs1"}) + bob.JoinRoom(t, allowed_room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) + bob.JoinRoom(t, room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // Charlie should join the allowed room (which gives access to the room). charlie := deployment.Register(t, "hs3", helpers.RegistrationOpts{}) t.Logf("%s joins the authorizing room via hs1.", charlie.UserID) - charlie.JoinRoom(t, allowed_room, []string{"hs1"}) + charlie.JoinRoom(t, allowed_room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // hs2 doesn't have anyone to invite from, so the join fails. t.Logf("%s joins the restricted room via hs2, which is expected to fail.", charlie.UserID) - res := charlie.JoinRoom(t, room, []string{"hs2"}) + res := charlie.JoinRoom(t, room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs2"), + }) must.MatchFailure(t, res) // Including hs1 (and failing over to it) allows the join to succeed. t.Logf("%s joins the restricted room via {hs2,hs1}.", charlie.UserID) - charlie.JoinRoom(t, room, []string{"hs2", "hs1"}) + charlie.JoinRoom(t, room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs2"), + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // Double check that the join was authorised via hs1. bob.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas( @@ -423,11 +461,16 @@ func doTestRestrictedRoomsRemoteJoinFailOver(t *testing.T, roomVersion string, j // hs2 cannot complete the join since they do not know if Charlie meets the // requirements (since it is no longer in the allowed room). t.Logf("%s joins the restricted room via hs2, which is expected to fail.", charlie.UserID) - must.MatchFailure(t, charlie.JoinRoom(t, room, []string{"hs2"})) + must.MatchFailure(t, charlie.JoinRoom(t, room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs2"), + })) // Including hs1 (and failing over to it) allows the join to succeed. t.Logf("%s joins the restricted room via {hs2,hs1}.", charlie.UserID) - charlie.JoinRoom(t, room, []string{"hs2", "hs1"}) + charlie.JoinRoom(t, room, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs2"), + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // Double check that the join was authorised via hs1. bob.MustSyncUntil(t, client.SyncReq{}, client.SyncTimelineHas( diff --git a/tests/room_hierarchy_test.go b/tests/room_hierarchy_test.go index c9b766fa..0d58fcbf 100644 --- a/tests/room_hierarchy_test.go +++ b/tests/room_hierarchy_test.go @@ -26,6 +26,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/spec" ) var ( @@ -159,7 +160,7 @@ func TestClientSpacesSummary(t *testing.T) { Type: spaceChildEventType, StateKey: &r1, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, "suggested": true, }, }) @@ -168,7 +169,7 @@ func TestClientSpacesSummary(t *testing.T) { Type: spaceChildEventType, StateKey: &ss1, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }) rootToR2 := eventKey(root, r2, spaceChildEventType) @@ -176,7 +177,7 @@ func TestClientSpacesSummary(t *testing.T) { Type: spaceChildEventType, StateKey: &r2, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, "suggested": true, }, }) @@ -185,14 +186,14 @@ func TestClientSpacesSummary(t *testing.T) { Type: spaceChildEventType, StateKey: &r5, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }) alice.SendEventSynced(t, r2, b.Event{ // parent link Type: spaceParentEventType, StateKey: &root, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }) ss1ToSS2 := eventKey(ss1, ss2, spaceChildEventType) @@ -200,7 +201,7 @@ func TestClientSpacesSummary(t *testing.T) { Type: spaceChildEventType, StateKey: &ss2, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }) ss2ToR3 := eventKey(ss2, r3, spaceChildEventType) @@ -208,7 +209,7 @@ func TestClientSpacesSummary(t *testing.T) { Type: spaceChildEventType, StateKey: &r3, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }) ss2ToR4 := eventKey(ss2, r4, spaceChildEventType) @@ -216,7 +217,7 @@ func TestClientSpacesSummary(t *testing.T) { Type: spaceChildEventType, StateKey: &r4, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }) @@ -440,7 +441,7 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { Type: spaceChildEventType, StateKey: &r1, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }) rootToSS1 := eventKey(root, ss1, spaceChildEventType) @@ -448,7 +449,7 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { Type: spaceChildEventType, StateKey: &ss1, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }) ss1ToR2 := eventKey(ss1, r2, spaceChildEventType) @@ -456,7 +457,7 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { Type: spaceChildEventType, StateKey: &r2, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }) ss1ToR3 := eventKey(ss1, r3, spaceChildEventType) @@ -464,13 +465,15 @@ func TestClientSpacesSummaryJoinRules(t *testing.T) { Type: spaceChildEventType, StateKey: &r3, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }) // Querying is done by bob who is not yet in any of the rooms. bob := deployment.Register(t, "hs1", helpers.RegistrationOpts{}) - bob.MustJoinRoom(t, root, []string{"hs1"}) + bob.MustJoinRoom(t, root, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) res := bob.MustDo(t, "GET", []string{"_matrix", "client", "v1", "rooms", root, "hierarchy"}) must.MatchResponse(t, res, match.HTTPResponse{ @@ -588,7 +591,7 @@ func TestFederatedClientSpaces(t *testing.T) { Type: spaceChildEventType, StateKey: &r1, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }) rootToSS1 := eventKey(root, ss1, spaceChildEventType) @@ -596,7 +599,7 @@ func TestFederatedClientSpaces(t *testing.T) { Type: spaceChildEventType, StateKey: &ss1, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }) rootToR2 := eventKey(root, r2, spaceChildEventType) @@ -604,7 +607,7 @@ func TestFederatedClientSpaces(t *testing.T) { Type: spaceChildEventType, StateKey: &r2, Content: map[string]interface{}{ - "via": []string{"hs2"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs2"))}, }, }) ss1ToSS2 := eventKey(ss1, ss2, spaceChildEventType) @@ -612,7 +615,7 @@ func TestFederatedClientSpaces(t *testing.T) { Type: spaceChildEventType, StateKey: &ss2, Content: map[string]interface{}{ - "via": []string{"hs2"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs2"))}, }, }) ss1ToR3 := eventKey(ss1, r3, spaceChildEventType) @@ -620,7 +623,7 @@ func TestFederatedClientSpaces(t *testing.T) { Type: spaceChildEventType, StateKey: &r3, Content: map[string]interface{}{ - "via": []string{"hs2"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs2"))}, }, }) ss2ToR4 := eventKey(ss2, r4, spaceChildEventType) @@ -628,7 +631,7 @@ func TestFederatedClientSpaces(t *testing.T) { Type: spaceChildEventType, StateKey: &r4, Content: map[string]interface{}{ - "via": []string{"hs1"}, + "via": []string{string(deployment.GetFullyQualifiedHomeserverName(t, "hs1"))}, }, }) allEvents := []string{ diff --git a/tests/room_timestamp_to_event_test.go b/tests/room_timestamp_to_event_test.go index 41bcb57c..c9d14d6d 100644 --- a/tests/room_timestamp_to_event_test.go +++ b/tests/room_timestamp_to_event_test.go @@ -21,6 +21,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/spec" "github.com/tidwall/gjson" "golang.org/x/exp/slices" ) @@ -71,7 +72,9 @@ func TestJumpToDateEndpoint(t *testing.T) { // Join from the application service bridge user so we can use to send // some messages at a specific time. - as.MustJoinRoom(t, roomID, []string{"hs1"}) + as.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // Send a couple messages with the same timestamp after the other test // messages in the room. @@ -91,7 +94,9 @@ func TestJumpToDateEndpoint(t *testing.T) { // Join from the application service bridge user so we can use to send // some messages at a specific time. - as.MustJoinRoom(t, roomID, []string{"hs1"}) + as.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // Send a couple messages with the same timestamp after the other test // messages in the room. @@ -164,14 +169,18 @@ func TestJumpToDateEndpoint(t *testing.T) { t.Run("looking forwards, should be able to find event that was sent before we joined", func(t *testing.T) { t.Parallel() roomID, eventA, _ := createTestRoom(t, alice) - remoteCharlie.MustJoinRoom(t, roomID, []string{"hs1"}) + remoteCharlie.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) mustCheckEventisReturnedForTime(t, remoteCharlie, roomID, eventA.BeforeTimestamp, "f", eventA.EventID) }) t.Run("looking backwards, should be able to find event that was sent before we joined", func(t *testing.T) { t.Parallel() roomID, _, eventB := createTestRoom(t, alice) - remoteCharlie.MustJoinRoom(t, roomID, []string{"hs1"}) + remoteCharlie.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) mustCheckEventisReturnedForTime(t, remoteCharlie, roomID, eventB.AfterTimestamp, "b", eventB.EventID) }) @@ -182,20 +191,26 @@ func TestJumpToDateEndpoint(t *testing.T) { // Join from the application service bridge user so we can use it to send // some messages at a specific time. - as.MustJoinRoom(t, roomID, []string{"hs1"}) + as.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) // Import a message in the room before the room was created importTime := time.Date(2022, 01, 03, 0, 0, 0, 0, time.Local) importedEventID := sendMessageWithTimestamp(t, as, alice, roomID, importTime, "old imported event") - remoteCharlie.MustJoinRoom(t, roomID, []string{"hs1"}) + remoteCharlie.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) mustCheckEventisReturnedForTime(t, remoteCharlie, roomID, timeBeforeRoomCreation, "b", importedEventID) }) t.Run("can paginate after getting remote event from timestamp to event endpoint", func(t *testing.T) { t.Parallel() roomID, eventA, eventB := createTestRoom(t, alice) - remoteCharlie.MustJoinRoom(t, roomID, []string{"hs1"}) + remoteCharlie.MustJoinRoom(t, roomID, []spec.ServerName{ + deployment.GetFullyQualifiedHomeserverName(t, "hs1"), + }) mustCheckEventisReturnedForTime(t, remoteCharlie, roomID, eventB.AfterTimestamp, "b", eventB.EventID) // Get a pagination token from eventB