Object store: get user from context (#56346)
* GRPC Server: Add signedInUser to context after auth * add permissions to signedInUser * add access control permissions test * add additional signedInUser checks * get user from context * move `UserFromContext` to object/auth.go Co-authored-by: Todd Treece <todd.treece@grafana.com>
This commit is contained in:
co-authored by
Todd Treece
parent
4a14d75086
commit
a94acb7f61
@@ -9,13 +9,14 @@ import (
|
||||
saAPI "github.com/grafana/grafana/pkg/services/serviceaccounts/api"
|
||||
saTests "github.com/grafana/grafana/pkg/services/serviceaccounts/tests"
|
||||
"github.com/grafana/grafana/pkg/services/store/object"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/tests/testinfra"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
func createServiceAccountAdminToken(t *testing.T, env *server.TestEnv) string {
|
||||
func createServiceAccountAdminToken(t *testing.T, env *server.TestEnv) (string, *user.SignedInUser) {
|
||||
t.Helper()
|
||||
|
||||
account := saTests.SetupUserServiceAccount(t, env.SQLStore, saTests.TestUser{
|
||||
@@ -37,12 +38,19 @@ func createServiceAccountAdminToken(t *testing.T, env *server.TestEnv) string {
|
||||
ServiceAccountID: &account.ID,
|
||||
})
|
||||
|
||||
return keyGen.ClientSecret
|
||||
return keyGen.ClientSecret, &user.SignedInUser{
|
||||
UserID: account.ID,
|
||||
Email: account.Email,
|
||||
Name: account.Name,
|
||||
Login: account.Login,
|
||||
OrgID: account.OrgID,
|
||||
}
|
||||
}
|
||||
|
||||
type testContext struct {
|
||||
authToken string
|
||||
client object.ObjectStoreClient
|
||||
user *user.SignedInUser
|
||||
}
|
||||
|
||||
func createTestContext(t *testing.T) testContext {
|
||||
@@ -54,7 +62,7 @@ func createTestContext(t *testing.T) testContext {
|
||||
})
|
||||
_, env := testinfra.StartGrafanaEnv(t, dir, path)
|
||||
|
||||
authToken := createServiceAccountAdminToken(t, env)
|
||||
authToken, serviceAccountUser := createServiceAccountAdminToken(t, env)
|
||||
|
||||
conn, err := grpc.Dial(
|
||||
env.GRPCServer.GetAddress(),
|
||||
@@ -67,5 +75,6 @@ func createTestContext(t *testing.T) testContext {
|
||||
return testContext{
|
||||
authToken: authToken,
|
||||
client: client,
|
||||
user: serviceAccountUser,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,8 +149,8 @@ func TestObjectServer(t *testing.T) {
|
||||
ctx = metadata.AppendToOutgoingContext(ctx, "authorization", fmt.Sprintf("Bearer %s", testCtx.authToken))
|
||||
|
||||
fakeUser := &object.UserInfo{
|
||||
Login: "fake",
|
||||
Id: 1,
|
||||
Login: testCtx.user.Login,
|
||||
Id: testCtx.user.UserID,
|
||||
}
|
||||
firstVersion := "1"
|
||||
kind := "dashboard"
|
||||
|
||||
Reference in New Issue
Block a user