mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-12 17:59:06 +02:00
Default the grant allowlist when updating a connector without one
This commit is contained in:
@@ -119,12 +119,17 @@ func (p *Provider) UpdateConnector(ctx context.Context, cfg *ConnectorConfig) er
|
||||
name = old.Name
|
||||
}
|
||||
|
||||
grantTypes := old.GrantTypes
|
||||
if len(grantTypes) == 0 {
|
||||
grantTypes = slices.Clone(DefaultGrantTypes)
|
||||
}
|
||||
|
||||
return storage.Connector{
|
||||
ID: cfg.ID,
|
||||
Type: old.Type,
|
||||
Name: name,
|
||||
Config: configData,
|
||||
GrantTypes: old.GrantTypes,
|
||||
GrantTypes: grantTypes,
|
||||
}, nil
|
||||
}); err != nil {
|
||||
return fmt.Errorf("failed to update connector: %w", err)
|
||||
|
||||
@@ -252,6 +252,28 @@ func TestConnectorGrantTypes(t *testing.T) {
|
||||
"an empty list would re-enable token exchange for this connector")
|
||||
})
|
||||
|
||||
t.Run("updating a connector stored without an allowlist sets the default", func(t *testing.T) {
|
||||
p, cleanup := newTestProvider(t)
|
||||
defer cleanup()
|
||||
|
||||
// Mimic a connector written by an older release.
|
||||
require.NoError(t, p.storage.CreateConnector(ctx, storage.Connector{
|
||||
ID: "legacy-oidc",
|
||||
Type: "oidc",
|
||||
Name: "Legacy",
|
||||
Config: []byte(`{"issuer":"https://accounts.example.com","clientID":"client-id"}`),
|
||||
}))
|
||||
|
||||
require.NoError(t, p.UpdateConnector(ctx, &ConnectorConfig{
|
||||
ID: "legacy-oidc",
|
||||
ClientSecret: "new-secret",
|
||||
}))
|
||||
|
||||
conn, err := p.storage.GetConnector(ctx, "legacy-oidc")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, DefaultGrantTypes, conn.GrantTypes)
|
||||
})
|
||||
|
||||
t.Run("backfills connectors stored without an allowlist", func(t *testing.T) {
|
||||
p, cleanup := newTestProvider(t)
|
||||
defer cleanup()
|
||||
|
||||
+2
-1
@@ -12,6 +12,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -123,7 +124,7 @@ func NewProvider(ctx context.Context, config *Config) (*Provider, error) {
|
||||
Storage: stor,
|
||||
SkipApprovalScreen: true,
|
||||
SupportedResponseTypes: []string{"code"},
|
||||
AllowedGrantTypes: DefaultGrantTypes,
|
||||
AllowedGrantTypes: slices.Clone(DefaultGrantTypes),
|
||||
ContinueOnConnectorFailure: true,
|
||||
Logger: logger,
|
||||
PrometheusRegistry: prometheus.NewRegistry(),
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/dexidp/dex/storage"
|
||||
@@ -173,7 +174,7 @@ func (c *EmbeddedIdPConfig) ToYAMLConfig() (*dex.YAMLConfig, error) {
|
||||
// the minimal set instead. Operators can still opt in to more by setting it.
|
||||
grantTypes := c.GrantTypes
|
||||
if len(grantTypes) == 0 {
|
||||
grantTypes = dex.DefaultGrantTypes
|
||||
grantTypes = slices.Clone(dex.DefaultGrantTypes)
|
||||
}
|
||||
|
||||
cfg := &dex.YAMLConfig{
|
||||
|
||||
Reference in New Issue
Block a user