From 0913eb6655dcf9e3fdd2a851ae59c63c630164dd Mon Sep 17 00:00:00 2001 From: hellivan Date: Thu, 24 Feb 2022 08:42:37 +0100 Subject: [PATCH] fix: openid config provider not initialized correctly (#14399) Up until now `InitializeProvider` method of `Config` struct was implemented on a value receiver which is why changes on `provider` field where never reflected to method callers. In order to fix this issue, the method was implemented on a pointer receiver. --- internal/config/identity/openid/jwt.go | 2 +- internal/config/identity/openid/jwt_test.go | 25 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/internal/config/identity/openid/jwt.go b/internal/config/identity/openid/jwt.go index dbfa231e1..9349fceea 100644 --- a/internal/config/identity/openid/jwt.go +++ b/internal/config/identity/openid/jwt.go @@ -155,7 +155,7 @@ const ( // InitializeProvider initializes if any additional vendor specific // information was provided, initialization will return an error // initial login fails. -func (r Config) InitializeProvider(kvs config.KVS) error { +func (r *Config) InitializeProvider(kvs config.KVS) error { vendor := env.Get(EnvIdentityOpenIDVendor, kvs.Get(Vendor)) if vendor == "" { return nil diff --git a/internal/config/identity/openid/jwt_test.go b/internal/config/identity/openid/jwt_test.go index 175a8ea72..c2bfa519b 100644 --- a/internal/config/identity/openid/jwt_test.go +++ b/internal/config/identity/openid/jwt_test.go @@ -27,6 +27,7 @@ import ( "time" jwtg "github.com/golang-jwt/jwt/v4" + "github.com/minio/minio/internal/config" jwtm "github.com/minio/minio/internal/jwt" xnet "github.com/minio/pkg/net" ) @@ -230,3 +231,27 @@ func TestExpCorrect(t *testing.T) { t.Error(err) } } + +func TestKeycloakProviderInitialization(t *testing.T) { + testConfig := Config{ + DiscoveryDoc: DiscoveryDoc{ + TokenEndpoint: "http://keycloak.test/token/endpoint", + }, + } + testKvs := config.KVS{} + testKvs.Set(Vendor, "keycloak") + testKvs.Set(KeyCloakRealm, "TestRealm") + testKvs.Set(KeyCloakAdminURL, "http://keycloak.test/auth/admin") + + if testConfig.provider != nil { + t.Errorf("Empty config cannot have any provider!") + } + + if err := testConfig.InitializeProvider(testKvs); err != nil { + t.Error(err) + } + + if testConfig.provider == nil { + t.Errorf("keycloak provider must be initialized!") + } +}