Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small tweaks to work with pseudoIDs #653

Merged
merged 1 commit into from
Sep 26, 2023
Merged
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
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
Loading