-
Notifications
You must be signed in to change notification settings - Fork 52
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
Move /send_leave
to GMSL
#387
base: main
Are you sure you want to change the base?
Changes from 1 commit
bc7260c
9e1377a
2640a7e
645785d
b7a785d
5d099f9
540062a
1f82150
717c829
e3b02c9
2369def
498c486
185a49a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,12 +106,11 @@ | |
CurrentStateEvent(ctx context.Context, roomID spec.RoomID, eventType string, stateKey string) (PDU, error) | ||
} | ||
|
||
// HandleSendLeave handles requests to `/send_leave | ||
// Returns the parsed event and an error. | ||
func HandleSendLeave(ctx context.Context, | ||
requestContent []byte, | ||
// handleSendLeave handles requests to `/send_leave | ||
// Returns the parsed event or an error. | ||
func handleSendLeave(ctx context.Context, | ||
event PDU, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The proposal I mentioned in #387 (comment) was to keep this function public, and to serve as the entry point for callers, because:
|
||
origin spec.ServerName, | ||
roomVersion RoomVersion, | ||
eventID, roomID string, | ||
querier CurrentStateQuerier, | ||
verifier JSONVerifier, | ||
|
@@ -122,21 +121,6 @@ | |
return nil, err | ||
} | ||
|
||
verImpl, err := GetRoomVersion(roomVersion) | ||
if err != nil { | ||
return nil, spec.UnsupportedRoomVersion(fmt.Sprintf("QueryRoomVersionForRoom returned unknown version: %s", roomVersion)) | ||
} | ||
|
||
// Decode the event JSON from the request. | ||
event, err := verImpl.NewEventFromUntrustedJSON(requestContent) | ||
switch err.(type) { | ||
case BadJSONError: | ||
return nil, spec.BadJSON(err.Error()) | ||
case nil: | ||
default: | ||
return nil, spec.NotJSON("The request body could not be decoded into valid JSON. " + err.Error()) | ||
} | ||
|
||
// Check that the room ID is correct. | ||
if (event.RoomID()) != roomID { | ||
return nil, spec.BadJSON("The room ID in the request path must match the room ID in the leave event JSON") | ||
|
@@ -153,29 +137,29 @@ | |
return nil, spec.BadJSON("No state key was provided in the leave event.") | ||
} | ||
if !event.StateKeyEquals(event.Sender()) { | ||
return nil, spec.BadJSON("Event state key must match the event sender.") | ||
} | ||
|
||
leavingUser, err := spec.NewUserID(*event.StateKey(), true) | ||
if err != nil { | ||
return nil, spec.Forbidden("The leaving user ID is invalid") | ||
} | ||
|
||
// Check that the sender belongs to the server that is sending us | ||
// the request. By this point we've already asserted that the sender | ||
// and the state key are equal so we don't need to check both. | ||
sender, err := spec.NewUserID(event.Sender(), true) | ||
if err != nil { | ||
return nil, spec.Forbidden("The sender of the join is invalid") | ||
} | ||
if sender.Domain() != origin { | ||
return nil, spec.Forbidden("The sender does not match the server that originated the request") | ||
} | ||
|
||
stateEvent, err := querier.CurrentStateEvent(ctx, *rID, spec.MRoomMember, leavingUser.String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
// we weren't joined at all | ||
if stateEvent == nil { | ||
return nil, nil | ||
|
@@ -186,18 +170,19 @@ | |
} | ||
// we already processed this event | ||
if event.EventID() == stateEvent.EventID() { | ||
return nil, nil | ||
} | ||
|
||
// Check that the event is signed by the server sending the request. | ||
redacted, err := verImpl.RedactEventJSON(event.JSON()) | ||
resultEvent := event | ||
event.Redact() | ||
if err != nil { | ||
util.GetLogger(ctx).WithError(err).Errorf("unable to redact event") | ||
return nil, spec.BadJSON("The event JSON could not be redacted") | ||
} | ||
verifyRequests := []VerifyJSONRequest{{ | ||
ServerName: sender.Domain(), | ||
Message: redacted, | ||
Message: event.JSON(), | ||
AtTS: event.OriginServerTS(), | ||
StrictValidityChecking: true, | ||
}} | ||
|
@@ -213,12 +198,12 @@ | |
// check membership is set to leave | ||
mem, err := event.Membership() | ||
if err != nil { | ||
util.GetLogger(ctx).WithError(err).Error("event.Membership failed") | ||
return nil, spec.BadJSON("missing content.membership key") | ||
} | ||
if mem != spec.Leave { | ||
return nil, spec.BadJSON("The membership in the event content must be set to leave") | ||
} | ||
|
||
return event, nil | ||
return resultEvent, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is problematic if
v != event.Version()
.