mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
SSO: fix reloading settings when a provider contains empty settings (#85102)
* fix reloading settings when a provider contains empty settings * do not increment reloadFailures if settings are empty
This commit is contained in:
parent
71c5070240
commit
fad6dc4db1
@ -365,9 +365,14 @@ func (s *Service) doReload(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for provider, connector := range s.reloadables {
|
for provider, connector := range s.reloadables {
|
||||||
setting := getSettingByProvider(provider, settingsList)
|
settings := getSettingByProvider(provider, settingsList)
|
||||||
|
|
||||||
err = connector.Reload(ctx, *setting)
|
if settings == nil || len(settings.Settings) == 0 {
|
||||||
|
s.logger.Warn("SSO Settings is empty", "provider", provider)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
err = connector.Reload(ctx, *settings)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.metrics.reloadFailures.WithLabelValues(provider).Inc()
|
s.metrics.reloadFailures.WithLabelValues(provider).Inc()
|
||||||
s.logger.Error("failed to reload SSO Settings", "provider", provider, "err", err)
|
s.logger.Error("failed to reload SSO Settings", "provider", provider, "err", err)
|
||||||
|
@ -1248,6 +1248,36 @@ func TestService_DoReload(t *testing.T) {
|
|||||||
env.service.doReload(context.Background())
|
env.service.doReload(context.Background())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("successfully reload settings when some providers have empty settings", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
env := setupTestEnv(t, false, false, nil)
|
||||||
|
|
||||||
|
settingsList := []*models.SSOSettings{
|
||||||
|
{
|
||||||
|
Provider: "azuread",
|
||||||
|
Settings: map[string]any{
|
||||||
|
"enabled": true,
|
||||||
|
"client_id": "azuread_client_id",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Provider: "google",
|
||||||
|
Settings: map[string]any{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
env.store.ExpectedSSOSettings = settingsList
|
||||||
|
|
||||||
|
reloadable := ssosettingstests.NewMockReloadable(t)
|
||||||
|
reloadable.On("Reload", mock.Anything, *settingsList[0]).Return(nil).Once()
|
||||||
|
env.reloadables["azuread"] = reloadable
|
||||||
|
|
||||||
|
// registers a provider with empty settings
|
||||||
|
env.reloadables["github"] = nil
|
||||||
|
|
||||||
|
env.service.doReload(context.Background())
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("failed fetching the SSO settings", func(t *testing.T) {
|
t.Run("failed fetching the SSO settings", func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user