From bf053595ae813fb619c0292414f005444e69bf90 Mon Sep 17 00:00:00 2001 From: KuhnChris Date: Sun, 18 Jun 2023 21:57:21 +0000 Subject: [PATCH] Clean up merge from main --- clientapi/auth/login.go | 2 +- clientapi/routing/login.go | 1 - clientapi/routing/login_test.go | 2 +- clientapi/routing/register_test.go | 3 +++ internal/validate.go | 12 ++++++------ internal/validate_test.go | 3 +-- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/clientapi/auth/login.go b/clientapi/auth/login.go index 96310f0df..58a27e593 100644 --- a/clientapi/auth/login.go +++ b/clientapi/auth/login.go @@ -74,7 +74,7 @@ func LoginFromJSONReader( if err != nil { err := &util.JSONResponse{ Code: http.StatusForbidden, - JSON: jsonerror.MissingToken(err.Error()), + JSON: spec.MissingToken(err.Error()), } return nil, nil, err } diff --git a/clientapi/routing/login.go b/clientapi/routing/login.go index b6e984bf0..068642f80 100644 --- a/clientapi/routing/login.go +++ b/clientapi/routing/login.go @@ -20,7 +20,6 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" - "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/userutil" "github.com/matrix-org/dendrite/setup/config" userapi "github.com/matrix-org/dendrite/userapi/api" diff --git a/clientapi/routing/login_test.go b/clientapi/routing/login_test.go index bb531a1d7..9ffe92a83 100644 --- a/clientapi/routing/login_test.go +++ b/clientapi/routing/login_test.go @@ -116,7 +116,7 @@ func TestLogin(t *testing.T) { t.Run("Supported log-in flows are returned", func(t *testing.T) { req := test.NewRequest(t, http.MethodGet, "/_matrix/client/v3/login") rec := httptest.NewRecorder() - base.PublicClientAPIMux.ServeHTTP(rec, req) + routers.Client.ServeHTTP(rec, req) if rec.Code != http.StatusOK { t.Fatalf("failed to get log-in flows: %s", rec.Body.String()) } diff --git a/clientapi/routing/register_test.go b/clientapi/routing/register_test.go index c92f53fa9..2a88ec380 100644 --- a/clientapi/routing/register_test.go +++ b/clientapi/routing/register_test.go @@ -22,6 +22,7 @@ import ( "net/http" "net/http/httptest" "reflect" + "regexp" "strings" "testing" "time" @@ -31,6 +32,8 @@ import ( "github.com/matrix-org/dendrite/internal/caching" "github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/dendrite/roomserver" + "github.com/matrix-org/dendrite/setup/config" + "github.com/matrix-org/dendrite/setup/jetstream" "github.com/matrix-org/dendrite/test" "github.com/matrix-org/dendrite/test/testrig" "github.com/matrix-org/dendrite/userapi" diff --git a/internal/validate.go b/internal/validate.go index 736411016..a90a6636f 100644 --- a/internal/validate.go +++ b/internal/validate.go @@ -20,10 +20,10 @@ import ( "net/http" "regexp" - "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/userutil" "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/gomatrixserverlib" + "github.com/matrix-org/gomatrixserverlib/spec" "github.com/matrix-org/util" ) @@ -102,7 +102,7 @@ func UsernameResponse(err error) *util.JSONResponse { } // ValidateApplicationServiceUsername returns an error if the username is invalid for an application service -func ValidateApplicationServiceUsername(localpart string, domain gomatrixserverlib.ServerName) error { +func ValidateApplicationServiceUsername(localpart string, domain spec.ServerName) error { userID := userutil.MakeUserID(localpart, domain) return ValidateApplicationServiceUserID(userID) } @@ -190,7 +190,7 @@ func ValidateApplicationServiceRequest( if err != nil { return "", &util.JSONResponse{ Code: http.StatusUnauthorized, - JSON: jsonerror.InvalidUsername(err.Error()), + JSON: spec.InvalidUsername(err.Error()), } } @@ -208,7 +208,7 @@ func ValidateApplicationServiceRequest( if matchedApplicationService == nil { return "", &util.JSONResponse{ Code: http.StatusUnauthorized, - JSON: jsonerror.UnknownToken("Supplied access_token does not match any known application service"), + JSON: spec.UnknownToken("Supplied access_token does not match any known application service"), } } @@ -217,7 +217,7 @@ func ValidateApplicationServiceRequest( // If we didn't find any matches, return M_EXCLUSIVE return "", &util.JSONResponse{ Code: http.StatusBadRequest, - JSON: jsonerror.ASExclusive(fmt.Sprintf( + JSON: spec.ASExclusive(fmt.Sprintf( "Supplied username %s did not match any namespaces for application service ID: %s", userIDOrLocalpart, matchedApplicationService.ID)), } } @@ -226,7 +226,7 @@ func ValidateApplicationServiceRequest( if userIDMatchesMultipleExclusiveNamespaces(cfg, userID) { return "", &util.JSONResponse{ Code: http.StatusBadRequest, - JSON: jsonerror.ASExclusive(fmt.Sprintf( + JSON: spec.ASExclusive(fmt.Sprintf( "Supplied username %s matches multiple exclusive application service namespaces. Only 1 match allowed", userIDOrLocalpart)), } } diff --git a/internal/validate_test.go b/internal/validate_test.go index 4533583e0..a9e6b7649 100644 --- a/internal/validate_test.go +++ b/internal/validate_test.go @@ -7,9 +7,8 @@ import ( "strings" "testing" - "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/setup/config" - "github.com/matrix-org/gomatrixserverlib" + "github.com/matrix-org/gomatrixserverlib/spec" "github.com/matrix-org/util" )