Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSO: fix reloading settings when a provider contains empty settings #85102

Merged
merged 3 commits into from Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions pkg/services/ssosettings/ssosettingsimpl/service.go
Expand Up @@ -365,9 +365,14 @@ func (s *Service) doReload(ctx context.Context) {
}

for provider, connector := range s.reloadables {
setting := getSettingByProvider(provider, settingsList)
settings := getSettingByProvider(provider, settingsList)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced setting with settings because we had a name collision with the package setting.


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 {
s.metrics.reloadFailures.WithLabelValues(provider).Inc()
s.logger.Error("failed to reload SSO Settings", "provider", provider, "err", err)
Expand Down
30 changes: 30 additions & 0 deletions pkg/services/ssosettings/ssosettingsimpl/service_test.go
Expand Up @@ -1248,6 +1248,36 @@ func TestService_DoReload(t *testing.T) {
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.Parallel()

Expand Down