Fixed integration tests

This commit is contained in:
Claudiu Dragalina-Paraipan 2024-09-26 20:47:57 +03:00
parent 71c33dcbe3
commit 914ca237e2
3 changed files with 17 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"github.com/grafana/grafana/pkg/infra/db" "github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/httpclient" "github.com/grafana/grafana/pkg/infra/httpclient"
"github.com/grafana/grafana/pkg/plugins/manager/registry" "github.com/grafana/grafana/pkg/plugins/manager/registry"
"github.com/grafana/grafana/pkg/services/auth"
"github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/grpcserver" "github.com/grafana/grafana/pkg/services/grpcserver"
"github.com/grafana/grafana/pkg/services/notifications" "github.com/grafana/grafana/pkg/services/notifications"
@ -24,6 +25,7 @@ func ProvideTestEnv(
oAuthTokenService *oauthtokentest.Service, oAuthTokenService *oauthtokentest.Service,
featureMgmt featuremgmt.FeatureToggles, featureMgmt featuremgmt.FeatureToggles,
resourceClient resource.ResourceClient, resourceClient resource.ResourceClient,
idService auth.IDService,
) (*TestEnv, error) { ) (*TestEnv, error) {
return &TestEnv{ return &TestEnv{
Server: server, Server: server,
@ -36,6 +38,7 @@ func ProvideTestEnv(
OAuthTokenService: oAuthTokenService, OAuthTokenService: oAuthTokenService,
FeatureToggles: featureMgmt, FeatureToggles: featureMgmt,
ResourceClient: resourceClient, ResourceClient: resourceClient,
IDService: idService,
}, nil }, nil
} }
@ -51,4 +54,5 @@ type TestEnv struct {
RequestMiddleware web.Middleware RequestMiddleware web.Middleware
FeatureToggles featuremgmt.FeatureToggles FeatureToggles featuremgmt.FeatureToggles
ResourceClient resource.ResourceClient ResourceClient resource.ResourceClient
IDService auth.IDService
} }

View File

@ -33,7 +33,6 @@ import (
"github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol" "github.com/grafana/grafana/pkg/services/accesscontrol/ossaccesscontrol"
"github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions" "github.com/grafana/grafana/pkg/services/accesscontrol/resourcepermissions"
"github.com/grafana/grafana/pkg/services/apiserver/endpoints/request" "github.com/grafana/grafana/pkg/services/apiserver/endpoints/request"
"github.com/grafana/grafana/pkg/services/auth/idtest"
"github.com/grafana/grafana/pkg/services/datasources" "github.com/grafana/grafana/pkg/services/datasources"
"github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/org" "github.com/grafana/grafana/pkg/services/org"
@ -498,7 +497,7 @@ func (c *K8sTestHelper) CreateUser(name string, orgName string, basicRole org.Ro
require.Equal(c.t, orgId, s.OrgID) require.Equal(c.t, orgId, s.OrgID)
require.Equal(c.t, basicRole, s.OrgRole) // make sure the role was set properly require.Equal(c.t, basicRole, s.OrgRole) // make sure the role was set properly
idToken, idClaims, err := idtest.CreateInternalToken(s, []byte("secret")) idToken, idClaims, err := c.env.IDService.SignIdentity(context.Background(), s)
require.NoError(c.t, err) require.NoError(c.t, err)
s.IDToken = idToken s.IDToken = idToken
s.IDTokenClaims = idClaims s.IDTokenClaims = idClaims

View File

@ -52,6 +52,11 @@ func StartGrafanaEnv(t *testing.T, grafDir, cfgPath string) (string, *server.Tes
serverOpts := server.Options{Listener: listener, HomePath: grafDir} serverOpts := server.Options{Listener: listener, HomePath: grafDir}
apiServerOpts := api.ServerOptions{Listener: listener} apiServerOpts := api.ServerOptions{Listener: listener}
// Replace the placeholder in the `signing_keys_url` with the actual address
grpcServerAuthSection := cfg.SectionWithEnvOverrides("grpc_server_authentication")
signingKeysUrl := grpcServerAuthSection.Key("signing_keys_url")
signingKeysUrl.SetValue(strings.Replace(signingKeysUrl.String(), "<placeholder>", listener.Addr().String(), 1))
// Potentially allocate a real gRPC port for unified storage // Potentially allocate a real gRPC port for unified storage
runstore := false runstore := false
unistore, _ := cfg.Raw.GetSection("grafana-apiserver") unistore, _ := cfg.Raw.GetSection("grafana-apiserver")
@ -289,6 +294,13 @@ func CreateGrafDir(t *testing.T, opts ...GrafanaOpts) (string, string) {
_, err = analyticsSect.NewKey("intercom_secret", "intercom_secret_at_config") _, err = analyticsSect.NewKey("intercom_secret", "intercom_secret_at_config")
require.NoError(t, err) require.NoError(t, err)
grpcServerAuth, err := cfg.NewSection("grpc_server_authentication")
require.NoError(t, err)
_, err = grpcServerAuth.NewKey("signing_keys_url", "http://<placeholder>/api/signing-keys/keys")
require.NoError(t, err)
_, err = grpcServerAuth.NewKey("allowed_audiences", "org:1")
require.NoError(t, err)
getOrCreateSection := func(name string) (*ini.Section, error) { getOrCreateSection := func(name string) (*ini.Section, error) {
section, err := cfg.GetSection(name) section, err := cfg.GetSection(name)
if err != nil { if err != nil {