Error on obvious problems with the make_join response instead of overwriting them

This commit is contained in:
Neil Alexander 2021-11-09 15:55:53 +00:00
parent f3e83c1a07
commit f21a585647
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -162,21 +162,28 @@ func (r *FederationSenderInternalAPI) performJoinUsingServer(
// Set all the fields to be what they should be, this should be a no-op // Set all the fields to be what they should be, this should be a no-op
// but it's possible that the remote server returned us something "odd" // but it's possible that the remote server returned us something "odd"
respMakeJoin.JoinEvent.Type = gomatrixserverlib.MRoomMember switch {
respMakeJoin.JoinEvent.Sender = userID case respMakeJoin.JoinEvent.Type != gomatrixserverlib.MRoomMember:
respMakeJoin.JoinEvent.StateKey = &userID fallthrough
respMakeJoin.JoinEvent.RoomID = roomID case respMakeJoin.JoinEvent.Sender != userID:
respMakeJoin.JoinEvent.Redacts = "" fallthrough
if content == nil { case respMakeJoin.JoinEvent.StateKey == nil:
content = map[string]interface{}{} fallthrough
case *respMakeJoin.JoinEvent.StateKey != userID:
fallthrough
case respMakeJoin.JoinEvent.RoomID != roomID:
fallthrough
case respMakeJoin.JoinEvent.Redacts != "":
fallthrough
case len(respMakeJoin.JoinEvent.Content) == 0:
return fmt.Errorf("respMakeJoin.JoinEvent contains invalid values")
}
if err = json.Unmarshal(respMakeJoin.JoinEvent.Content, &content); err != nil {
return fmt.Errorf("json.Unmarshal: %w", err)
} }
content["membership"] = "join"
if err = respMakeJoin.JoinEvent.SetContent(content); err != nil { if err = respMakeJoin.JoinEvent.SetContent(content); err != nil {
return fmt.Errorf("respMakeJoin.JoinEvent.SetContent: %w", err) return fmt.Errorf("respMakeJoin.JoinEvent.SetContent: %w", err)
} }
if err = respMakeJoin.JoinEvent.SetUnsigned(struct{}{}); err != nil {
return fmt.Errorf("respMakeJoin.JoinEvent.SetUnsigned: %w", err)
}
// Work out if we support the room version that has been supplied in // Work out if we support the room version that has been supplied in
// the make_join response. // the make_join response.