@@ -151,10 +151,51 @@ func TestApplicationAuthReconciler_syncApplicationAuth(t *testing.T) {
151151 expectedKey : "testkey1,testkey2,testkey3" ,
152152 wantErr : false ,
153153 },
154+ {
155+ name : "returns error with empty client_secret with empty secret" ,
156+ mockServer : & mockApplicationAuthServer {
157+ authMode : "oidc" ,
158+ keys : []string {},
159+ userAccountID : appID ,
160+ appID : userAccountID ,
161+ },
162+ authMode : "oidc" ,
163+ authSecret : getEmptyAuthSecret (),
164+ expectedKey : "" ,
165+ wantErr : true ,
166+ },
167+ {
168+ name : "update existing client_secret with value from secret" ,
169+ mockServer : & mockApplicationAuthServer {
170+ authMode : "oidc" ,
171+ keys : []string {"initalkey" },
172+ userAccountID : appID ,
173+ appID : userAccountID ,
174+ },
175+ authMode : "oidc" ,
176+ authSecret : getAuthSecret (),
177+ expectedKey : "testkey" ,
178+ wantErr : false ,
179+ },
180+ {
181+ name : "update existing client_secret with the same value should not return error" ,
182+ mockServer : & mockApplicationAuthServer {
183+ authMode : "oidc" ,
184+ keys : []string {"testkey" },
185+ userAccountID : appID ,
186+ appID : userAccountID ,
187+ },
188+ authMode : "oidc" ,
189+ authSecret : getAuthSecret (),
190+ expectedKey : "testkey" ,
191+ wantErr : false ,
192+ },
154193 }
155194 for _ , tt := range tests {
156195 t .Run (tt .name , func (t * testing.T ) {
157196 srv := tt .mockServer .GetServer ()
197+ defer srv .Close ()
198+
158199 ap , _ := threescaleapi .NewAdminPortalFromStr (srv .URL )
159200 threescaleClient := threescaleapi .NewThreeScale (ap , "test" , srv .Client ())
160201
@@ -236,6 +277,30 @@ func TestApplicationAuthReconciler_authSecretReferenceSource(t *testing.T) {
236277 wantErr : false ,
237278 err : "" ,
238279 },
280+ {
281+ name : "return error when secret is empty" ,
282+ authMode : "oidc" ,
283+ generateSecret : true ,
284+ secretData : map [string ][]byte {},
285+ wantErr : true ,
286+ err : "secret field 'ClientSecret' is required in secret 'test'" ,
287+ },
288+ {
289+ name : "generate client_secret when secret is empty" ,
290+ authMode : "oidc" ,
291+ generateSecret : true ,
292+ secretData : map [string ][]byte {"ClientSecret" : []byte ("" )},
293+ wantErr : false ,
294+ err : "" ,
295+ },
296+ {
297+ name : "use client_secret value in secret" ,
298+ authMode : "oidc" ,
299+ generateSecret : true ,
300+ secretData : map [string ][]byte {"ClientSecret" : []byte ("testkey" )},
301+ wantErr : false ,
302+ err : "" ,
303+ },
239304 {
240305 name : "return error with unknown authMode" ,
241306 authMode : "unknown" ,
@@ -293,6 +358,10 @@ func TestApplicationAuthReconciler_authSecretReferenceSource(t *testing.T) {
293358 if authSecret .ApplicationKey != string (newSecret .Data ["ApplicationKey" ]) {
294359 t .Fatalf ("mismatch user_key expected = '%s', got '%s'" , authSecret .ApplicationKey , newSecret .Data ["ApplicationKey" ])
295360 }
361+ case "oidc" :
362+ if authSecret .ClientSecret != string (newSecret .Data [ClientSecret ]) {
363+ t .Fatalf ("mismatch user_key expected = '%s', got '%s'" , authSecret .ClientSecret , newSecret .Data [ClientSecret ])
364+ }
296365 }
297366 }
298367 })
@@ -349,6 +418,7 @@ func getAuthSecret() AuthSecret {
349418 UserKey : "testkey" ,
350419 ApplicationKey : "testkey" ,
351420 ApplicationID : "" ,
421+ ClientSecret : "testkey" ,
352422 }
353423 return authSecret
354424}
@@ -376,7 +446,7 @@ func (m *mockApplicationAuthServer) GetKey(mode string) string {
376446 switch mode {
377447 case "1" :
378448 return m .userKey
379- case "2" :
449+ case "2" , "oidc" :
380450 return strings .Join (m .keys , "," )
381451 default :
382452 return ""
@@ -437,6 +507,8 @@ func (m *mockApplicationAuthServer) applicationKeysHandler(w http.ResponseWriter
437507
438508 if m .authMode == "2" {
439509 keyLimit = 5
510+ } else if m .authMode == "oidc" {
511+ keyLimit = 1
440512 }
441513
442514 // Check if the current lenght does not exceed 5 keys limit
0 commit comments