Make full HTTP tests less upsetti

This commit is contained in:
Neil Alexander 2022-01-26 14:06:35 +00:00
parent 80e015a7e8
commit deae1d08d8
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
3 changed files with 29 additions and 10 deletions

View file

@ -360,14 +360,16 @@ type lookupMissingEvents struct {
RoomID string RoomID string
Missing gomatrixserverlib.MissingEvents Missing gomatrixserverlib.MissingEvents
RoomVersion gomatrixserverlib.RoomVersion RoomVersion gomatrixserverlib.RoomVersion
Res *gomatrixserverlib.RespMissingEvents Res struct {
Err *api.FederationClientError Events []gomatrixserverlib.RawJSON `json:"events"`
}
Err *api.FederationClientError
} }
func (h *httpFederationInternalAPI) LookupMissingEvents( func (h *httpFederationInternalAPI) LookupMissingEvents(
ctx context.Context, s gomatrixserverlib.ServerName, roomID string, ctx context.Context, s gomatrixserverlib.ServerName, roomID string,
missing gomatrixserverlib.MissingEvents, roomVersion gomatrixserverlib.RoomVersion, missing gomatrixserverlib.MissingEvents, roomVersion gomatrixserverlib.RoomVersion,
) (gomatrixserverlib.RespMissingEvents, error) { ) (res gomatrixserverlib.RespMissingEvents, err error) {
span, ctx := opentracing.StartSpanFromContext(ctx, "LookupMissingEvents") span, ctx := opentracing.StartSpanFromContext(ctx, "LookupMissingEvents")
defer span.Finish() defer span.Finish()
@ -377,16 +379,23 @@ func (h *httpFederationInternalAPI) LookupMissingEvents(
Missing: missing, Missing: missing,
RoomVersion: roomVersion, RoomVersion: roomVersion,
} }
var response lookupMissingEvents
apiURL := h.federationAPIURL + FederationAPILookupMissingEventsPath apiURL := h.federationAPIURL + FederationAPILookupMissingEventsPath
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &response) err = httputil.PostJSON(ctx, span, h.httpClient, apiURL, &request, &request)
if err != nil { if err != nil {
return gomatrixserverlib.RespMissingEvents{}, err return res, err
} }
if response.Err != nil { if request.Err != nil {
return gomatrixserverlib.RespMissingEvents{}, response.Err return res, request.Err
} }
return *response.Res, nil res.Events = make([]*gomatrixserverlib.Event, 0, len(request.Res.Events))
for _, js := range request.Res.Events {
ev, err := gomatrixserverlib.NewEventFromUntrustedJSON(js, roomVersion)
if err != nil {
return res, err
}
res.Events = append(res.Events, ev)
}
return res, nil
} }
type getEvent struct { type getEvent struct {

View file

@ -259,7 +259,13 @@ func AddRoutes(intAPI api.FederationInternalAPI, internalAPIMux *mux.Router) {
} }
} }
} }
request.Res = &res for _, event := range res.Events {
js, err := json.Marshal(event)
if err != nil {
return util.MessageResponse(http.StatusInternalServerError, err.Error())
}
request.Res.Events = append(request.Res.Events, js)
}
return util.JSONResponse{Code: http.StatusOK, JSON: request} return util.JSONResponse{Code: http.StatusOK, JSON: request}
}), }),
) )

View file

@ -101,6 +101,10 @@ func (r *Inputer) processRoomEvent(
"type": event.Type(), "type": event.Type(),
}) })
if _, err := headered.RoomVersion.EventIDFormat(); err != nil {
panic("UNKNOWN ROOM VERSION")
}
// if we have already got this event then do not process it again, if the input kind is an outlier. // if we have already got this event then do not process it again, if the input kind is an outlier.
// Outliers contain no extra information which may warrant a re-processing. // Outliers contain no extra information which may warrant a re-processing.
if input.Kind == api.KindOutlier { if input.Kind == api.KindOutlier {