Auth: Cache Auth Info (#80620)
* leverage cache for auth info * fix tests and integration * fix panic * fix panic
This commit is contained in:
@@ -10,12 +10,16 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/sync/singleflight"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/remotecache"
|
||||
"github.com/grafana/grafana/pkg/login/social/socialtest"
|
||||
"github.com/grafana/grafana/pkg/services/login"
|
||||
"github.com/grafana/grafana/pkg/services/login/authinfoimpl"
|
||||
"github.com/grafana/grafana/pkg/services/secrets/fakes"
|
||||
secretsManager "github.com/grafana/grafana/pkg/services/secrets/manager"
|
||||
"github.com/grafana/grafana/pkg/services/user"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
)
|
||||
@@ -117,10 +121,9 @@ func TestService_TryTokenRefresh_ValidToken(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
socialConnector.AssertNumberOfCalls(t, "TokenSource", 1)
|
||||
|
||||
authInfoQuery := &login.GetAuthInfoQuery{}
|
||||
authInfoQuery := &login.GetAuthInfoQuery{UserId: 1}
|
||||
resultUsr, err := srv.AuthInfoService.GetAuthInfo(ctx, authInfoQuery)
|
||||
|
||||
assert.Nil(t, err)
|
||||
require.Nil(t, err)
|
||||
|
||||
// User's token data had not been updated
|
||||
assert.Equal(t, resultUsr.OAuthAccessToken, token.AccessToken)
|
||||
@@ -190,10 +193,10 @@ func TestService_TryTokenRefresh_ExpiredToken(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
socialConnector.AssertNumberOfCalls(t, "TokenSource", 1)
|
||||
|
||||
authInfoQuery := &login.GetAuthInfoQuery{}
|
||||
authInfoQuery := &login.GetAuthInfoQuery{UserId: 1}
|
||||
authInfo, err := srv.AuthInfoService.GetAuthInfo(ctx, authInfoQuery)
|
||||
|
||||
assert.Nil(t, err)
|
||||
require.Nil(t, err)
|
||||
|
||||
// newToken should be returned after the .Token() call, therefore the User had to be updated
|
||||
assert.Equal(t, authInfo.OAuthAccessToken, newToken.AccessToken)
|
||||
@@ -229,7 +232,8 @@ func setupOAuthTokenService(t *testing.T) (*Service, *FakeAuthInfoStore, *social
|
||||
}
|
||||
|
||||
authInfoStore := &FakeAuthInfoStore{}
|
||||
authInfoService := authinfoimpl.ProvideService(authInfoStore)
|
||||
authInfoService := authinfoimpl.ProvideService(authInfoStore, remotecache.NewFakeCacheStorage(),
|
||||
secretsManager.SetupTestService(t, fakes.NewFakeSecretsStore()))
|
||||
return &Service{
|
||||
Cfg: setting.NewCfg(),
|
||||
SocialService: socialService,
|
||||
|
||||
Reference in New Issue
Block a user