Skip to content

Commit

Permalink
Merge pull request #653 from matrix-org/complement-fixes
Browse files Browse the repository at this point in the history
Small tweaks to work with pseudoIDs
  • Loading branch information
devonh authored Sep 26, 2023
2 parents a5fec0c + 911cfa5 commit 21187b3
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions internal/federation/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/matrix-org/gomatrix"
"github.com/matrix-org/gomatrixserverlib/fclient"
"github.com/matrix-org/gomatrixserverlib/spec"
"github.com/tidwall/sjson"

"github.com/gorilla/mux"
"github.com/matrix-org/gomatrixserverlib"
Expand Down Expand Up @@ -361,17 +362,54 @@ func (s *Server) MustJoinRoom(t *testing.T, deployment *docker.Deployment, remot
if err != nil {
t.Fatalf("MustJoinRoom: invalid room version: %v", err)
}

var senderID spec.SenderID
signingKey := s.Priv
keyID := s.KeyID
origOrigin := origin
switch roomVer {
case gomatrixserverlib.RoomVersionPseudoIDs:
_, key, err := ed25519.GenerateKey(nil)
if err != nil {
t.Fatalf("MustJoinRoom: failed generating senderID: %v", err)
}
senderID, signingKey, err = spec.SenderIDFromPseudoIDKey(key), key, nil
keyID = "ed25519:1"
origin = spec.ServerName(senderID)
mapping := gomatrixserverlib.MXIDMapping{
UserRoomKey: senderID,
UserID: userID,
}
if err = mapping.Sign(origOrigin, s.KeyID, s.Priv); err != nil {
t.Fatalf("MustJoinRoom: failed signing mxid_mapping: %v", err)
}

path := "mxid_mapping"
eventJSON, err := sjson.SetBytes(makeJoinResp.JoinEvent.Content, path, mapping)
if err != nil {
t.Fatalf("MustJoinRoom: failed setting mxid_mapping in content: %v", err)
}
eventJSON = gomatrixserverlib.CanonicalJSONAssumeValid(eventJSON)
makeJoinResp.JoinEvent.Content = eventJSON
default:
senderID = spec.SenderID(userID)
}

stateKey := string(senderID)
makeJoinResp.JoinEvent.SenderID = string(senderID)
makeJoinResp.JoinEvent.StateKey = &stateKey

eb := verImpl.NewEventBuilderFromProtoEvent(&makeJoinResp.JoinEvent)
joinEvent, err := eb.Build(time.Now(), origin, s.KeyID, s.Priv)
joinEvent, err := eb.Build(time.Now(), origin, keyID, signingKey)
if err != nil {
t.Fatalf("MustJoinRoom: failed to sign event: %v", err)
}
var sendJoinResp fclient.RespSendJoin
if len(partialState) == 0 || !partialState[0] {
// Default to doing a regular join.
sendJoinResp, err = fedClient.SendJoin(context.Background(), origin, remoteServer, joinEvent)
sendJoinResp, err = fedClient.SendJoin(context.Background(), origOrigin, remoteServer, joinEvent)
} else {
sendJoinResp, err = fedClient.SendJoinPartialState(context.Background(), origin, remoteServer, joinEvent)
sendJoinResp, err = fedClient.SendJoinPartialState(context.Background(), origOrigin, remoteServer, joinEvent)
}
if err != nil {
t.Fatalf("MustJoinRoom: send_join failed: %v", err)
Expand Down

0 comments on commit 21187b3

Please sign in to comment.