@@ -58,9 +58,7 @@ const (
5858)
5959
6060func TestExternalOIDCWithKeycloak (t * testing.T ) {
61- testCtx , cancel := context .WithCancel (context .Background ())
62- defer cancel ()
63-
61+ testCtx := t .Context ()
6462 testClient , err := newTestClient (t , testCtx )
6563 require .NoError (t , err )
6664
@@ -150,26 +148,12 @@ func TestExternalOIDCWithKeycloak(t *testing.T) {
150148 require .NoError (t , waitErr , "failed to wait for auth configmap to get deleted: %v" , err )
151149 })
152150
153- t .Run ("invalid OIDC config degrades auth operator " , func (t * testing.T ) {
151+ t .Run ("invalid CEL expression rejects auth CR admission " , func (t * testing.T ) {
154152 for _ , tt := range []struct {
155153 name string
156154 specUpdate func (* configv1.AuthenticationSpec )
157155 requireFeatureGates []configv1.FeatureGateName
158156 }{
159- {
160- name : "invalid issuer CA bundle" ,
161- specUpdate : func (s * configv1.AuthenticationSpec ) {
162- s .OIDCProviders [0 ].Issuer .CertificateAuthority .Name = "invalid-ca-bundle"
163- },
164- requireFeatureGates : []configv1.FeatureGateName {},
165- },
166- {
167- name : "invalid issuer URL" ,
168- specUpdate : func (s * configv1.AuthenticationSpec ) {
169- s .OIDCProviders [0 ].Issuer .URL = "https://invalid-idp.testing"
170- },
171- requireFeatureGates : []configv1.FeatureGateName {},
172- },
173157 {
174158 name : "uncompilable CEL expression for uid claim mapping" ,
175159 specUpdate : func (s * configv1.AuthenticationSpec ) {
@@ -198,13 +182,47 @@ func TestExternalOIDCWithKeycloak(t *testing.T) {
198182 t .Skipf ("skipping as required feature gate %q is not enabled" , fg )
199183 }
200184 }
185+ _ , err := testClient .updateAuthResource (t , testCtx , testSpec , tt .specUpdate )
186+ require .Error (t , err , "uncompilable CEL expression should return in admission error" )
187+ })
188+ }
189+ })
190+
191+ t .Run ("invalid OIDC config degrades auth operator" , func (t * testing.T ) {
192+ for _ , tt := range []struct {
193+ name string
194+ specUpdate func (* configv1.AuthenticationSpec )
195+ requireFeatureGates []configv1.FeatureGateName
196+ }{
197+ {
198+ name : "invalid issuer CA bundle" ,
199+ specUpdate : func (s * configv1.AuthenticationSpec ) {
200+ s .OIDCProviders [0 ].Issuer .CertificateAuthority .Name = "invalid-ca-bundle"
201+ },
202+ requireFeatureGates : []configv1.FeatureGateName {},
203+ },
204+ {
205+ name : "invalid issuer URL" ,
206+ specUpdate : func (s * configv1.AuthenticationSpec ) {
207+ s .OIDCProviders [0 ].Issuer .URL = "https://invalid-idp.testing"
208+ },
209+ requireFeatureGates : []configv1.FeatureGateName {},
210+ },
211+ } {
212+ t .Run (tt .name , func (t * testing.T ) {
213+ for _ , fg := range tt .requireFeatureGates {
214+ if ! featureGateEnabled (testCtx , testClient .configClient , fg ) {
215+ t .Skipf ("skipping as required feature gate %q is not enabled" , fg )
216+ }
217+ }
201218
202219 err := testClient .authResourceRollback (testCtx , origAuthSpec )
203220 require .NoError (t , err , "failed to roll back auth resource" )
204221
205222 testClient .checkPreconditions (t , testCtx , typeOAuth , operatorAvailable , nil )
206223
207- testClient .updateAuthResource (t , testCtx , testSpec , tt .specUpdate )
224+ _ , err = testClient .updateAuthResource (t , testCtx , testSpec , tt .specUpdate )
225+ require .NoError (t , err , "failed to update authentication/cluster" )
208226
209227 require .NoError (t , test .WaitForClusterOperatorDegraded (t , testClient .configClient .ConfigV1 (), "authentication" ))
210228
@@ -237,13 +255,14 @@ func TestExternalOIDCWithKeycloak(t *testing.T) {
237255 testClient .checkPreconditions (t , testCtx , nil , operatorAvailable , operatorAvailable )
238256
239257 kasOriginalRevision := testClient .kasLatestAvailableRevision (t , testCtx )
240- auth := testClient .updateAuthResource (t , testCtx , testSpec , func (baseSpec * configv1.AuthenticationSpec ) {
258+ auth , err := testClient .updateAuthResource (t , testCtx , testSpec , func (baseSpec * configv1.AuthenticationSpec ) {
241259 baseSpec .OIDCProviders [0 ].ClaimMappings .Username = configv1.UsernameClaimMapping {
242260 Claim : tt .claim ,
243261 PrefixPolicy : tt .prefixPolicy ,
244262 Prefix : tt .prefix ,
245263 }
246264 })
265+ require .NoError (t , err , "failed to update authentication/cluster" )
247266
248267 require .NoError (t , test .WaitForClusterOperatorStatusAlwaysAvailable (t , testCtx , testClient .configClient .ConfigV1 (), "authentication" ))
249268 require .NoError (t , test .WaitForClusterOperatorStatusAlwaysAvailable (t , testCtx , testClient .configClient .ConfigV1 (), "kube-apiserver" ))
@@ -288,13 +307,14 @@ func TestExternalOIDCWithKeycloak(t *testing.T) {
288307 testClient .checkPreconditions (t , testCtx , nil , operatorAvailable , operatorAvailable )
289308
290309 kasOriginalRevision := testClient .kasLatestAvailableRevision (t , testCtx )
291- auth := testClient .updateAuthResource (t , testCtx , testSpec , func (baseSpec * configv1.AuthenticationSpec ) {
310+ auth , err := testClient .updateAuthResource (t , testCtx , testSpec , func (baseSpec * configv1.AuthenticationSpec ) {
292311 baseSpec .OIDCProviders [0 ].ClaimMappings .Username = configv1.UsernameClaimMapping {
293312 Claim : "unknown" ,
294313 PrefixPolicy : configv1 .NoPrefix ,
295314 Prefix : nil ,
296315 }
297316 })
317+ require .NoError (t , err , "failed to update authentication/cluster" )
298318
299319 require .NoError (t , test .WaitForClusterOperatorStatusAlwaysAvailable (t , testCtx , testClient .configClient .ConfigV1 (), "authentication" ))
300320 require .NoError (t , test .WaitForClusterOperatorStatusAlwaysAvailable (t , testCtx , testClient .configClient .ConfigV1 (), "kube-apiserver" ))
@@ -559,21 +579,24 @@ func (tc *testClient) getAuth(t *testing.T, ctx context.Context) *configv1.Authe
559579}
560580
561581// updateAuthResource deep-copies the baseSpec, applies updates to the copy and persists them in the auth resource
562- func (tc * testClient ) updateAuthResource (t * testing.T , ctx context.Context , baseSpec * configv1.AuthenticationSpec , updateAuthSpec func (baseSpec * configv1.AuthenticationSpec )) * configv1.Authentication {
582+ func (tc * testClient ) updateAuthResource (t * testing.T , ctx context.Context , baseSpec * configv1.AuthenticationSpec , updateAuthSpec func (baseSpec * configv1.AuthenticationSpec )) ( * configv1.Authentication , error ) {
563583 auth := tc .getAuth (t , ctx )
564584 if updateAuthSpec == nil {
565- return auth
585+ return auth , nil
566586 }
567587
568588 spec := baseSpec .DeepCopy ()
569589 updateAuthSpec (spec )
570590
571591 auth .Spec = * spec
572592 auth , err := tc .configClient .ConfigV1 ().Authentications ().Update (ctx , auth , metav1.UpdateOptions {})
573- require .NoError (t , err , "failed to update authentication/cluster" )
593+ if err != nil {
594+ return nil , err
595+ }
596+
574597 require .True (t , equality .Semantic .DeepEqual (auth .Spec , * spec ))
575598
576- return auth
599+ return auth , nil
577600}
578601
579602func (tc * testClient ) checkPreconditions (t * testing.T , ctx context.Context , authType * configv1.AuthenticationType , caoStatus []configv1.ClusterOperatorStatusCondition , kasoStatus []configv1.ClusterOperatorStatusCondition ) {
0 commit comments