Skip to content

Commit

Permalink
Small tweaks to work with pseudoIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
devonh committed Sep 26, 2023
1 parent a5fec0c commit 911cfa5
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 911cfa5

Please sign in to comment.