mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
Pass join errors through internal API boundaries (#1157)
* Pass join errors through internal API boundaries Required for certain invite sytests. We will need to think of a better way of handling this going forwards. * Include m.room.avatar in stripped state; handle trailing slashes when GETing state events * Update whitelist * Update whitelist
This commit is contained in:
parent
1f93427ed9
commit
0577bfca55
7 changed files with 66 additions and 6 deletions
|
@ -298,9 +298,12 @@ func buildInviteStrippedState(
|
|||
return nil, fmt.Errorf("room %q unknown", input.Event.RoomID())
|
||||
}
|
||||
stateWanted := []gomatrixserverlib.StateKeyTuple{}
|
||||
// "If they are set on the room, at least the state for m.room.avatar, m.room.canonical_alias, m.room.join_rules, and m.room.name SHOULD be included."
|
||||
// https://matrix.org/docs/spec/client_server/r0.6.0#m-room-member
|
||||
for _, t := range []string{
|
||||
gomatrixserverlib.MRoomName, gomatrixserverlib.MRoomCanonicalAlias,
|
||||
gomatrixserverlib.MRoomAliases, gomatrixserverlib.MRoomJoinRules,
|
||||
"m.room.avatar",
|
||||
} {
|
||||
stateWanted = append(stateWanted, gomatrixserverlib.StateKeyTuple{
|
||||
EventType: t,
|
||||
|
|
|
@ -2,6 +2,7 @@ package internal
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -21,9 +22,11 @@ func (r *RoomserverInternalAPI) PerformJoin(
|
|||
) error {
|
||||
_, domain, err := gomatrixserverlib.SplitID('@', req.UserID)
|
||||
if err != nil {
|
||||
res.Error = api.JoinErrorBadRequest
|
||||
return fmt.Errorf("Supplied user ID %q in incorrect format", req.UserID)
|
||||
}
|
||||
if domain != r.Cfg.Matrix.ServerName {
|
||||
res.Error = api.JoinErrorBadRequest
|
||||
return fmt.Errorf("User %q does not belong to this homeserver", req.UserID)
|
||||
}
|
||||
if strings.HasPrefix(req.RoomIDOrAlias, "!") {
|
||||
|
@ -32,6 +35,7 @@ func (r *RoomserverInternalAPI) PerformJoin(
|
|||
if strings.HasPrefix(req.RoomIDOrAlias, "#") {
|
||||
return r.performJoinRoomByAlias(ctx, req, res)
|
||||
}
|
||||
res.Error = api.JoinErrorBadRequest
|
||||
return fmt.Errorf("Room ID or alias %q is invalid", req.RoomIDOrAlias)
|
||||
}
|
||||
|
||||
|
@ -99,6 +103,7 @@ func (r *RoomserverInternalAPI) performJoinRoomByID(
|
|||
// Get the domain part of the room ID.
|
||||
_, domain, err := gomatrixserverlib.SplitID('!', req.RoomIDOrAlias)
|
||||
if err != nil {
|
||||
res.Error = api.JoinErrorBadRequest
|
||||
return fmt.Errorf("Room ID %q is invalid", req.RoomIDOrAlias)
|
||||
}
|
||||
req.ServerNames = append(req.ServerNames, domain)
|
||||
|
@ -198,6 +203,10 @@ func (r *RoomserverInternalAPI) performJoinRoomByID(
|
|||
}
|
||||
inputRes := api.InputRoomEventsResponse{}
|
||||
if err = r.InputRoomEvents(ctx, &inputReq, &inputRes); err != nil {
|
||||
var notAllowed *gomatrixserverlib.NotAllowed
|
||||
if errors.As(err, ¬Allowed) {
|
||||
res.Error = api.JoinErrorNotAllowed
|
||||
}
|
||||
return fmt.Errorf("r.InputRoomEvents: %w", err)
|
||||
}
|
||||
}
|
||||
|
@ -207,6 +216,7 @@ func (r *RoomserverInternalAPI) performJoinRoomByID(
|
|||
// room. If it is then there's nothing more to do - the room just
|
||||
// hasn't been created yet.
|
||||
if domain == r.Cfg.Matrix.ServerName {
|
||||
res.Error = api.JoinErrorNoRoom
|
||||
return fmt.Errorf("Room ID %q does not exist", req.RoomIDOrAlias)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue