Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions federation/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ import (
"github.com/matrix-org/util"
)

// HandleVersionRequests is an option which makes the server process `/_matrix/federation/v1/version` requests.
func HandleVersionRequests() func(*Server) {
return func(srv *Server) {
mux := srv.mux.PathPrefix("/_matrix/federation/v1").Subrouter()

handlerFn := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(200)
b, _ := json.Marshal(map[string]interface{}{
"server": map[string]interface{}{
"name": "complement-federation-test-server",
"version": "0.1.0",
},
})
w.Write(b)
})

mux.Handle("/version", handlerFn).Methods("GET")
}
}

// EXPERIMENTAL
// MakeJoinRequestsHandler is the http.Handler implementation for the make_join part of
// HandleMakeSendJoinRequests.
Expand Down
25 changes: 25 additions & 0 deletions tests/federation_room_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package tests

import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"strings"
Expand All @@ -24,6 +26,7 @@ import (
"github.com/matrix-org/complement/client"
"github.com/matrix-org/complement/federation"
"github.com/matrix-org/complement/helpers"
"github.com/matrix-org/complement/internal"
"github.com/matrix-org/complement/match"
"github.com/matrix-org/complement/must"
"github.com/matrix-org/complement/runtime"
Expand Down Expand Up @@ -296,19 +299,41 @@ func TestJoinFederatedRoomWithUnverifiableEvents(t *testing.T) {
})
}

func VersionRequestHandler(s *federation.Server, w http.ResponseWriter, req *http.Request) {
// Send it
}
Comment on lines +302 to +304
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused


// This test checks that users cannot circumvent the auth checks via send_join.
func TestBannedUserCannotSendJoin(t *testing.T) {
deployment := complement.Deploy(t, 1)
defer deployment.Destroy(t)

srv := federation.NewServer(t, deployment,
federation.HandleVersionRequests(),
federation.HandleKeyRequests(),
federation.HandleTransactionRequests(nil, nil),
)
cancel := srv.Listen()
origin := srv.ServerName()
defer cancel()

// XXX: Sanity check that the server is listening and responding (at-least from the host perspective)
splitPieces := strings.SplitN(string(srv.ServerName()), ":", 2)
port := splitPieces[1]
// Ignore HTTPS/TLS verification for localhost
httpTransport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
httpClient := &http.Client{Transport: httpTransport}
// Make the request
res, err := httpClient.Get("https://localhost:" + port + "/_matrix/federation/v1/version")
if err != nil {
t.Fatalf("Failed to GET: %s", err)
}
defer internal.CloseIO(res.Body, "server response body")
resBody, err := io.ReadAll(res.Body)
t.Logf("asdf request %d %s", res.StatusCode, resBody)

fedClient := srv.FederationClient(deployment)

charlie := srv.UserID("charlie")
Expand Down
Loading