mirror of
https://github.com/matrix-org/dendrite
synced 2024-06-14 02:18:34 +02:00
Tests and admin endpoint
This commit is contained in:
parent
fa3671e422
commit
5dcb991a9c
|
@ -1429,7 +1429,6 @@ func TestEventReportsGetDelete(t *testing.T) {
|
|||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("expected getting report to fail, got HTTP %d instead: %s", w.Code, w.Body.String())
|
||||
}
|
||||
t.Logf("%s", w.Body.String())
|
||||
resp := api.QueryAdminEventReportResponse{}
|
||||
if err = json.Unmarshal(w.Body.Bytes(), &resp); err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -1448,5 +1447,29 @@ func TestEventReportsGetDelete(t *testing.T) {
|
|||
t.Fatal("mismatching eventJSON")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Can delete with a valid ID", func(t *testing.T) {
|
||||
w = httptest.NewRecorder()
|
||||
req = httptest.NewRequest(http.MethodDelete, "/_synapse/admin/v1/event_reports/1", strings.NewReader(string(body)))
|
||||
req.Header.Set("Authorization", "Bearer "+accessTokens[alice].accessToken)
|
||||
|
||||
routers.SynapseAdmin.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("expected getting report to fail, got HTTP %d instead: %s", w.Code, w.Body.String())
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Can not query deleted report", func(t *testing.T) {
|
||||
w = httptest.NewRecorder()
|
||||
req = httptest.NewRequest(http.MethodGet, "/_synapse/admin/v1/event_reports/1", strings.NewReader(string(body)))
|
||||
req.Header.Set("Authorization", "Bearer "+accessTokens[alice].accessToken)
|
||||
|
||||
routers.SynapseAdmin.ServeHTTP(w, req)
|
||||
|
||||
if w.Code == http.StatusOK {
|
||||
t.Fatalf("expected getting report to fail, got HTTP %d instead: %s", w.Code, w.Body.String())
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -554,6 +554,30 @@ func GetEventReport(req *http.Request, rsAPI roomserverAPI.ClientRoomserverAPI,
|
|||
}
|
||||
}
|
||||
|
||||
func DeleteEventReport(req *http.Request, rsAPI roomserverAPI.ClientRoomserverAPI, reportID string) util.JSONResponse {
|
||||
parsedReportID, err := strconv.ParseUint(reportID, 10, 64)
|
||||
if err != nil {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusBadRequest,
|
||||
// Given this is an admin endpoint, let them know what didn't work.
|
||||
JSON: spec.InvalidParam(err.Error()),
|
||||
}
|
||||
}
|
||||
|
||||
err = rsAPI.PerformAdminDeleteEventReport(req.Context(), parsedReportID)
|
||||
if err != nil {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusInternalServerError,
|
||||
JSON: spec.Unknown(err.Error()),
|
||||
}
|
||||
}
|
||||
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusOK,
|
||||
JSON: struct{}{},
|
||||
}
|
||||
}
|
||||
|
||||
func parseUint64OrDefault(input string, defaultValue uint64) uint64 {
|
||||
v, err := strconv.ParseUint(input, 10, 64)
|
||||
if err != nil {
|
||||
|
|
|
@ -1535,7 +1535,7 @@ func Setup(
|
|||
).Methods(http.MethodPost, http.MethodOptions)
|
||||
|
||||
synapseAdminRouter.Handle("/admin/v1/event_reports",
|
||||
httputil.MakeAdminAPI("admin_report_event", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
||||
httputil.MakeAdminAPI("admin_report_events", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
||||
from := parseUint64OrDefault(req.URL.Query().Get("from"), 0)
|
||||
limit := parseUint64OrDefault(req.URL.Query().Get("limit"), 100)
|
||||
dir := req.URL.Query().Get("dir")
|
||||
|
@ -1557,4 +1557,14 @@ func Setup(
|
|||
return GetEventReport(req, rsAPI, vars["reportID"])
|
||||
}),
|
||||
).Methods(http.MethodGet, http.MethodOptions)
|
||||
|
||||
synapseAdminRouter.Handle("/admin/v1/event_reports/{reportID}",
|
||||
httputil.MakeAdminAPI("admin_report_event_delete", userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse {
|
||||
vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return DeleteEventReport(req, rsAPI, vars["reportID"])
|
||||
}),
|
||||
).Methods(http.MethodDelete, http.MethodOptions)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue