Authlib: Use types package rather than claims (#99243)

This commit is contained in:
Ryan McKinley
2025-01-21 12:06:55 +03:00
committed by GitHub
parent b2d0359e72
commit 680e6bc1f8
149 changed files with 394 additions and 376 deletions
+7 -7
View File
@@ -7,10 +7,10 @@ import (
"net/http/httptest"
"testing"
"github.com/grafana/authlib/claims"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
authlib "github.com/grafana/authlib/types"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/infra/log/logtest"
"github.com/grafana/grafana/pkg/infra/tracing"
@@ -68,7 +68,7 @@ func TestAuth_Middleware(t *testing.T) {
desc: "ReqSignedIn should return 200 for anonymous user",
path: "/api/secure",
authMiddleware: ReqSignedIn,
identity: &authn.Identity{Type: claims.TypeAnonymous},
identity: &authn.Identity{Type: authlib.TypeAnonymous},
expecedReached: true,
expectedCode: http.StatusOK,
},
@@ -76,7 +76,7 @@ func TestAuth_Middleware(t *testing.T) {
desc: "ReqSignedIn should return redirect anonymous user with forceLogin query string",
path: "/secure?forceLogin=true",
authMiddleware: ReqSignedIn,
identity: &authn.Identity{Type: claims.TypeAnonymous},
identity: &authn.Identity{Type: authlib.TypeAnonymous},
expecedReached: false,
expectedCode: http.StatusFound,
},
@@ -84,7 +84,7 @@ func TestAuth_Middleware(t *testing.T) {
desc: "ReqSignedIn should return redirect anonymous user when orgId in query string is different from currently used",
path: "/secure?orgId=2",
authMiddleware: ReqSignedIn,
identity: &authn.Identity{Type: claims.TypeAnonymous},
identity: &authn.Identity{Type: authlib.TypeAnonymous},
expecedReached: false,
expectedCode: http.StatusFound,
},
@@ -92,7 +92,7 @@ func TestAuth_Middleware(t *testing.T) {
desc: "ReqSignedInNoAnonymous should return 401 for anonymous user",
path: "/api/secure",
authMiddleware: ReqSignedInNoAnonymous,
identity: &authn.Identity{Type: claims.TypeAnonymous},
identity: &authn.Identity{Type: authlib.TypeAnonymous},
expecedReached: false,
expectedCode: http.StatusUnauthorized,
},
@@ -100,7 +100,7 @@ func TestAuth_Middleware(t *testing.T) {
desc: "ReqSignedInNoAnonymous should return 200 for authenticated user",
path: "/api/secure",
authMiddleware: ReqSignedInNoAnonymous,
identity: &authn.Identity{ID: "1", Type: claims.TypeUser},
identity: &authn.Identity{ID: "1", Type: authlib.TypeUser},
expecedReached: true,
expectedCode: http.StatusOK,
},
@@ -108,7 +108,7 @@ func TestAuth_Middleware(t *testing.T) {
desc: "snapshot public mode disabled should return 200 for authenticated user",
path: "/api/secure",
authMiddleware: SnapshotPublicModeOrCreate(&setting.Cfg{SnapshotPublicMode: false}, ac),
identity: &authn.Identity{ID: "1", Type: claims.TypeUser},
identity: &authn.Identity{ID: "1", Type: authlib.TypeUser},
expecedReached: true,
expectedCode: http.StatusOK,
},
+2 -1
View File
@@ -3,9 +3,10 @@ package middleware
import (
"testing"
"github.com/grafana/authlib/claims"
"github.com/stretchr/testify/assert"
claims "github.com/grafana/authlib/types"
"github.com/grafana/grafana/pkg/services/auth"
"github.com/grafana/grafana/pkg/services/authn"
"github.com/grafana/grafana/pkg/services/quota/quotatest"