diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index cce150343..e82c8861c 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -733,7 +733,7 @@ func Setup( ).Methods(http.MethodGet, http.MethodPost, http.MethodOptions) v3mux.Handle("/auth/{authType}/fallback/web", - httputil.MakeHTMLAPI("auth_fallback", userAPI, enableMetrics, func(w http.ResponseWriter, req *http.Request) { + httputil.MakeHTTPAPI("auth_fallback", userAPI, enableMetrics, func(w http.ResponseWriter, req *http.Request) { vars := mux.Vars(req) AuthFallback(w, req, vars["authType"], cfg) }), diff --git a/federationapi/routing/routing.go b/federationapi/routing/routing.go index 810fa9022..91718efdb 100644 --- a/federationapi/routing/routing.go +++ b/federationapi/routing/routing.go @@ -679,8 +679,8 @@ func MakeFedAPI( return httputil.MakeExternalAPI(metricsName, h) } -// MakeFedHTMLAPI makes an http.Handler that checks matrix federation authentication. -func MakeFedHTMLAPI( +// MakeFedHTTPAPI makes an http.Handler that checks matrix federation authentication. +func MakeFedHTTPAPI( serverName spec.ServerName, isLocalServerName func(spec.ServerName) bool, keyRing gomatrixserverlib.JSONVerifier, diff --git a/internal/httputil/httpapi.go b/internal/httputil/httpapi.go index 921c12a0e..0559fbb72 100644 --- a/internal/httputil/httpapi.go +++ b/internal/httputil/httpapi.go @@ -59,7 +59,7 @@ func WithAllowGuests() AuthAPIOption { } } -// WithAuth is an option to MakeHTMLAPI to add authentication. +// WithAuth is an option to MakeHTTPAPI to add authentication. func WithAuth() AuthAPIOption { return func(opts *AuthAPIOpts) { opts.WithAuth = true @@ -206,9 +206,9 @@ func MakeExternalAPI(metricsName string, f func(*http.Request) util.JSONResponse return http.HandlerFunc(withSpan) } -// MakeHTMLAPI adds Span metrics to the HTML Handler function +// MakeHTTPAPI adds Span metrics to the HTML Handler function // This is used to serve HTML alongside JSON error messages -func MakeHTMLAPI(metricsName string, userAPI userapi.QueryAcccessTokenAPI, enableMetrics bool, f func(http.ResponseWriter, *http.Request), checks ...AuthAPIOption) http.Handler { +func MakeHTTPAPI(metricsName string, userAPI userapi.QueryAcccessTokenAPI, enableMetrics bool, f func(http.ResponseWriter, *http.Request), checks ...AuthAPIOption) http.Handler { withSpan := func(w http.ResponseWriter, req *http.Request) { trace, ctx := internal.StartTask(req.Context(), metricsName) defer trace.EndTask() @@ -224,7 +224,6 @@ func MakeHTMLAPI(metricsName string, userAPI userapi.QueryAcccessTokenAPI, enabl logger := util.GetLogger(req.Context()) _, jsonErr := auth.VerifyUserFromRequest(req, userAPI) if jsonErr != nil { - logger.Debugf("VerifyUserFromRequest %s -> HTTP %d", req.RemoteAddr, jsonErr.Code) w.WriteHeader(jsonErr.Code) if err := json.NewEncoder(w).Encode(jsonErr.JSON); err != nil { logger.WithError(err).Error("failed to encode JSON response") diff --git a/internal/sqlutil/sqlutil_test.go b/internal/sqlutil/sqlutil_test.go index c40757893..93b84aa20 100644 --- a/internal/sqlutil/sqlutil_test.go +++ b/internal/sqlutil/sqlutil_test.go @@ -218,5 +218,5 @@ func assertNoError(t *testing.T, err error, msg string) { if err == nil { return } - t.Fatalf(msg) + t.Fatal(msg) } diff --git a/mediaapi/routing/routing.go b/mediaapi/routing/routing.go index d567d9abd..2867df605 100644 --- a/mediaapi/routing/routing.go +++ b/mediaapi/routing/routing.go @@ -105,20 +105,20 @@ func Setup( ).Methods(http.MethodGet, http.MethodOptions) // v1 client endpoints requiring auth - downloadHandlerAuthed := httputil.MakeHTMLAPI("download", userAPI, cfg.Global.Metrics.Enabled, makeDownloadAPI("download_authed_client", &cfg.MediaAPI, rateLimits, db, client, federationClient, activeRemoteRequests, activeThumbnailGeneration, false), httputil.WithAuth()) + downloadHandlerAuthed := httputil.MakeHTTPAPI("download", userAPI, cfg.Global.Metrics.Enabled, makeDownloadAPI("download_authed_client", &cfg.MediaAPI, rateLimits, db, client, federationClient, activeRemoteRequests, activeThumbnailGeneration, false), httputil.WithAuth()) v1mux.Handle("/config", configHandler).Methods(http.MethodGet, http.MethodOptions) v1mux.Handle("/download/{serverName}/{mediaId}", downloadHandlerAuthed).Methods(http.MethodGet, http.MethodOptions) v1mux.Handle("/download/{serverName}/{mediaId}/{downloadName}", downloadHandlerAuthed).Methods(http.MethodGet, http.MethodOptions) v1mux.Handle("/thumbnail/{serverName}/{mediaId}", - httputil.MakeHTMLAPI("thumbnail", userAPI, cfg.Global.Metrics.Enabled, makeDownloadAPI("thumbnail_authed_client", &cfg.MediaAPI, rateLimits, db, client, federationClient, activeRemoteRequests, activeThumbnailGeneration, false), httputil.WithAuth()), + httputil.MakeHTTPAPI("thumbnail", userAPI, cfg.Global.Metrics.Enabled, makeDownloadAPI("thumbnail_authed_client", &cfg.MediaAPI, rateLimits, db, client, federationClient, activeRemoteRequests, activeThumbnailGeneration, false), httputil.WithAuth()), ).Methods(http.MethodGet, http.MethodOptions) // same, but for federation - v1fedMux.Handle("/download/{mediaId}", routing.MakeFedHTMLAPI(cfg.Global.ServerName, cfg.Global.IsLocalServerName, keyRing, + v1fedMux.Handle("/download/{mediaId}", routing.MakeFedHTTPAPI(cfg.Global.ServerName, cfg.Global.IsLocalServerName, keyRing, makeDownloadAPI("download_authed_federation", &cfg.MediaAPI, rateLimits, db, client, federationClient, activeRemoteRequests, activeThumbnailGeneration, true), )).Methods(http.MethodGet, http.MethodOptions) - v1fedMux.Handle("/thumbnail/{mediaId}", routing.MakeFedHTMLAPI(cfg.Global.ServerName, cfg.Global.IsLocalServerName, keyRing, + v1fedMux.Handle("/thumbnail/{mediaId}", routing.MakeFedHTTPAPI(cfg.Global.ServerName, cfg.Global.IsLocalServerName, keyRing, makeDownloadAPI("thumbnail_authed_federation", &cfg.MediaAPI, rateLimits, db, client, federationClient, activeRemoteRequests, activeThumbnailGeneration, true), )).Methods(http.MethodGet, http.MethodOptions) } diff --git a/roomserver/acls/acls_test.go b/roomserver/acls/acls_test.go index 09920308c..7fd20f114 100644 --- a/roomserver/acls/acls_test.go +++ b/roomserver/acls/acls_test.go @@ -29,11 +29,11 @@ func TestOpenACLsWithBlacklist(t *testing.T) { roomID := "!test:test.com" allowRegex, err := compileACLRegex("*") if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err) } denyRegex, err := compileACLRegex("foo.com") if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err) } acls := ServerACLs{ @@ -72,7 +72,7 @@ func TestDefaultACLsWithWhitelist(t *testing.T) { roomID := "!test:test.com" allowRegex, err := compileACLRegex("foo.com") if err != nil { - t.Fatalf(err.Error()) + t.Fatal(err) } acls := ServerACLs{ diff --git a/userapi/internal/key_api.go b/userapi/internal/key_api.go index 422898c70..81127481e 100644 --- a/userapi/internal/key_api.go +++ b/userapi/internal/key_api.go @@ -196,7 +196,7 @@ func (a *UserInternalAPI) QueryDeviceMessages(ctx context.Context, req *api.Quer if m.StreamID > maxStreamID { maxStreamID = m.StreamID } - if m.KeyJSON == nil || len(m.KeyJSON) == 0 { + if len(m.KeyJSON) == 0 { continue } result = append(result, m)