@@ -123,6 +123,45 @@ func TestApplicationAuthReconciler_syncApplicationAuth(t *testing.T) {
123123 expectedKey : "testkey" ,
124124 wantErr : false ,
125125 },
126+ {
127+ name : "returns error with empty client_secret with empty secret" ,
128+ mockServer : & mockApplicationAuthServer {
129+ authMode : "oidc" ,
130+ keys : []string {},
131+ userAccountID : appID ,
132+ appID : userAccountID ,
133+ },
134+ authMode : "oidc" ,
135+ authSecret : getEmptyAuthSecret (),
136+ expectedKey : "" ,
137+ wantErr : true ,
138+ },
139+ {
140+ name : "update existing client_secret with value from secret" ,
141+ mockServer : & mockApplicationAuthServer {
142+ authMode : "oidc" ,
143+ keys : []string {"initalkey" },
144+ userAccountID : appID ,
145+ appID : userAccountID ,
146+ },
147+ authMode : "oidc" ,
148+ authSecret : getAuthSecret (),
149+ expectedKey : "testkey" ,
150+ wantErr : false ,
151+ },
152+ {
153+ name : "update existing client_secret with the same value should not return error" ,
154+ mockServer : & mockApplicationAuthServer {
155+ authMode : "oidc" ,
156+ keys : []string {"testkey" },
157+ userAccountID : appID ,
158+ appID : userAccountID ,
159+ },
160+ authMode : "oidc" ,
161+ authSecret : getAuthSecret (),
162+ expectedKey : "testkey" ,
163+ wantErr : false ,
164+ },
126165 }
127166 for _ , tt := range tests {
128167 t .Run (tt .name , func (t * testing.T ) {
@@ -260,6 +299,30 @@ func TestApplicationAuthReconciler_authSecretReferenceSource(t *testing.T) {
260299 wantErr : false ,
261300 err : "" ,
262301 },
302+ {
303+ name : "return error when secret is empty" ,
304+ authMode : "oidc" ,
305+ generateSecret : true ,
306+ secretData : map [string ][]byte {},
307+ wantErr : true ,
308+ err : "secret field 'ClientSecret' is required in secret 'test'" ,
309+ },
310+ {
311+ name : "generate client_secret when secret is empty" ,
312+ authMode : "oidc" ,
313+ generateSecret : true ,
314+ secretData : map [string ][]byte {"ClientSecret" : []byte ("" )},
315+ wantErr : false ,
316+ err : "" ,
317+ },
318+ {
319+ name : "use client_secret value in secret" ,
320+ authMode : "oidc" ,
321+ generateSecret : true ,
322+ secretData : map [string ][]byte {"ClientSecret" : []byte ("testkey" )},
323+ wantErr : false ,
324+ err : "" ,
325+ },
263326 }
264327 for _ , tt := range tests {
265328 t .Run (tt .name , func (t * testing.T ) {
@@ -317,6 +380,10 @@ func TestApplicationAuthReconciler_authSecretReferenceSource(t *testing.T) {
317380 if authSecret .ApplicationKey != string (newSecret .Data ["ApplicationKey" ]) {
318381 t .Fatalf ("mismatch user_key expected = '%s', got '%s'" , authSecret .ApplicationKey , newSecret .Data ["ApplicationKey" ])
319382 }
383+ case "oidc" :
384+ if authSecret .ClientSecret != string (newSecret .Data [ClientSecret ]) {
385+ t .Fatalf ("mismatch user_key expected = '%s', got '%s'" , authSecret .ClientSecret , newSecret .Data [ClientSecret ])
386+ }
320387 }
321388 }
322389 })
@@ -373,6 +440,7 @@ func getAuthSecret() AuthSecret {
373440 UserKey : "testkey" ,
374441 ApplicationKey : "testkey" ,
375442 ApplicationID : "" ,
443+ ClientSecret : "testkey" ,
376444 }
377445 return authSecret
378446}
@@ -400,7 +468,7 @@ func (m *mockApplicationAuthServer) GetKey(mode string) string {
400468 switch mode {
401469 case "1" :
402470 return m .userKey
403- case "2" :
471+ case "2" , "oidc" :
404472 return strings .Join (m .keys , "," )
405473 default :
406474 return ""
@@ -461,6 +529,8 @@ func (m *mockApplicationAuthServer) applicationKeysHandler(w http.ResponseWriter
461529
462530 if m .authMode == "2" {
463531 keyLimit = 5
532+ } else if m .authMode == "oidc" {
533+ keyLimit = 1
464534 }
465535
466536 // Check if the current length does not exceed 5 keys limit
0 commit comments