Skip to content

Commit 9849104

Browse files
Merge pull request #30040 from everettraven/oidc/fix-testing
CNTRLPLANE-945: oidc: fix test issues
2 parents 7e8f07d + b1ee547 commit 9849104

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

test/extended/authentication/keycloak_client.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (kc *keycloakClient) CreateUser(username, password string, groups ...string
104104
Groups: groups,
105105
Credentials: []credential{
106106
{
107-
Temporary: true,
107+
Temporary: false,
108108
Type: credentialTypePassword,
109109
Value: password,
110110
},
@@ -131,8 +131,10 @@ func (kc *keycloakClient) CreateUser(username, password string, groups ...string
131131
}
132132

133133
type authenticationResponse struct {
134-
AccessToken string `json:"access_token"`
135-
IDToken string `json:"id_token"`
134+
AccessToken string `json:"access_token"`
135+
IDToken string `json:"id_token"`
136+
Error string `json:"error,omitempty"`
137+
ErrorDescription string `json:"error_description,omitempty"`
136138
}
137139

138140
func (kc *keycloakClient) Authenticate(clientID, username, password string) error {
@@ -159,6 +161,10 @@ func (kc *keycloakClient) Authenticate(clientID, username, password string) erro
159161
return fmt.Errorf("unmarshalling response data: %w", err)
160162
}
161163

164+
if respBody.Error != "" {
165+
return fmt.Errorf("%s: %s", respBody.Error, respBody.ErrorDescription)
166+
}
167+
162168
kc.accessToken = respBody.AccessToken
163169
kc.idToken = respBody.IDToken
164170

test/extended/authentication/keycloak_helpers.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ func createKeycloakRoute(ctx context.Context, service *corev1.Service, client ty
351351
}
352352

353353
func waitForKeycloakAvailable(ctx context.Context, client *exutil.CLI, namespace string) error {
354-
timeoutCtx, cancel := context.WithDeadline(ctx, time.Now().Add(5*time.Minute))
354+
timeoutCtx, cancel := context.WithDeadline(ctx, time.Now().Add(10*time.Minute))
355355
defer cancel()
356356
err := wait.PollUntilContextCancel(timeoutCtx, 10*time.Second, true, func(ctx context.Context) (done bool, err error) {
357357
deploy, err := client.AdminKubeClient().AppsV1().Deployments(namespace).Get(ctx, keycloakResourceName, metav1.GetOptions{})
@@ -365,6 +365,8 @@ func waitForKeycloakAvailable(ctx context.Context, client *exutil.CLI, namespace
365365
}
366366
}
367367

368+
fmt.Println("keycloak deployment is not yet available. status: ", deploy.Status)
369+
368370
return false, nil
369371
})
370372

test/extended/authentication/oidc.go

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
exutil "github.com/openshift/origin/test/extended/util"
1616
authnv1 "k8s.io/api/authentication/v1"
1717
corev1 "k8s.io/api/core/v1"
18+
"k8s.io/apimachinery/pkg/api/equality"
1819
apierrors "k8s.io/apimachinery/pkg/api/errors"
1920
"k8s.io/apimachinery/pkg/util/errors"
2021

@@ -150,7 +151,8 @@ var _ = g.Describe("[sig-auth][Suite:openshift/auth/external-oidc][Serial][Slow]
150151
gomega.Expect(err).NotTo(o.HaveOccurred(), "should not encounter an error authenticating as keycloak user")
151152

152153
copiedOC := *oc
153-
tokenOC := copiedOC.WithToken(keycloakCli.AccessToken())
154+
token := keycloakCli.AccessToken()
155+
tokenOC := copiedOC.WithToken(token)
154156
ssr, err := tokenOC.KubeClient().AuthenticationV1().SelfSubjectReviews().Create(ctx, &authnv1.SelfSubjectReview{
155157
ObjectMeta: metav1.ObjectMeta{
156158
Name: fmt.Sprintf("%s-info", username),
@@ -183,10 +185,12 @@ var _ = g.Describe("[sig-auth][Suite:openshift/auth/external-oidc][Serial][Slow]
183185
gomega.Expect(err).NotTo(o.HaveOccurred(), "should be able to create a SelfSubjectReview")
184186
}).WithTimeout(5 * time.Minute).WithPolling(10 * time.Second).Should(o.Succeed())
185187

186-
err := resetAuthentication(ctx, oc, originalAuth)
188+
err, modified := resetAuthentication(ctx, oc, originalAuth)
187189
o.Expect(err).NotTo(o.HaveOccurred(), "should not encounter an error reverting authentication to original state")
188190

189-
waitForRollout(ctx, oc)
191+
if modified {
192+
waitForRollout(ctx, oc)
193+
}
190194
})
191195

192196
g.It("should rollout configuration on the kube-apiserver successfully", func() {
@@ -360,13 +364,16 @@ var _ = g.Describe("[sig-auth][Suite:openshift/auth/external-oidc][Serial][Slow]
360364
})
361365

362366
g.AfterAll(func() {
363-
err := removeResources(ctx, cleanups...)
364-
o.Expect(err).NotTo(o.HaveOccurred(), "should not encounter an error cleaning up keycloak resources")
365-
366-
err = resetAuthentication(ctx, oc, originalAuth)
367+
err, modified := resetAuthentication(ctx, oc, originalAuth)
367368
o.Expect(err).NotTo(o.HaveOccurred(), "should not encounter an error reverting authentication to original state")
368369

369-
waitForRollout(ctx, oc)
370+
// Only if we modified the Authentication resource during the reset should we wait for a rollout
371+
if modified {
372+
waitForRollout(ctx, oc)
373+
}
374+
375+
err = removeResources(ctx, cleanups...)
376+
o.Expect(err).NotTo(o.HaveOccurred(), "should not encounter an error cleaning up keycloak resources")
370377
})
371378
})
372379

@@ -477,11 +484,12 @@ func admittedURLForRoute(ctx context.Context, client *exutil.CLI, routeName, nam
477484
return fmt.Sprintf("https://%s", admittedURL), err
478485
}
479486

480-
func resetAuthentication(ctx context.Context, client *exutil.CLI, original *configv1.Authentication) error {
487+
func resetAuthentication(ctx context.Context, client *exutil.CLI, original *configv1.Authentication) (error, bool) {
481488
if original == nil {
482-
return nil
489+
return nil, false
483490
}
484491

492+
modified := false
485493
timeoutCtx, cancel := context.WithDeadline(ctx, time.Now().Add(5*time.Minute))
486494
defer cancel()
487495
cli := client.AdminConfigClient().ConfigV1().Authentications()
@@ -491,17 +499,24 @@ func resetAuthentication(ctx context.Context, client *exutil.CLI, original *conf
491499
return false, fmt.Errorf("getting the current authentications.config.openshift.io/cluster: %w", err)
492500
}
493501

502+
if equality.Semantic.DeepEqual(current.Spec, original.Spec) {
503+
return true, nil
504+
}
505+
494506
current.Spec = original.Spec
507+
modified = true
495508

496509
_, err = cli.Update(ctx, current, metav1.UpdateOptions{})
497510
if err != nil {
498-
return false, err
511+
// Only log the error so we continue to retry until the context has timed out
512+
fmt.Println("updating authentication resource:", err)
513+
return false, nil
499514
}
500515

501516
return true, nil
502517
})
503518

504-
return err
519+
return err, modified
505520
}
506521

507522
func waitForRollout(ctx context.Context, client *exutil.CLI) {
@@ -523,8 +538,8 @@ func waitForRollout(ctx context.Context, client *exutil.CLI) {
523538
}
524539

525540
gomega.Expect(found).To(o.BeTrue(), "should have found the NodeInstallerProgressing condition")
526-
gomega.Expect(nipCond.Status).To(o.Equal(operatorv1.ConditionTrue), "NodeInstallerProgressing condition should be True")
527-
}).WithTimeout(5*time.Minute).WithPolling(10*time.Second).Should(o.Succeed(), "should eventually begin rolling out a new revision")
541+
gomega.Expect(nipCond.Status).To(o.Equal(operatorv1.ConditionTrue), "NodeInstallerProgressing condition should be True", nipCond)
542+
}).WithTimeout(10*time.Minute).WithPolling(20*time.Second).Should(o.Succeed(), "should eventually begin rolling out a new revision")
528543

529544
// Then wait for it to flip back
530545
o.Eventually(func(gomega o.Gomega) {
@@ -542,6 +557,6 @@ func waitForRollout(ctx context.Context, client *exutil.CLI) {
542557
}
543558

544559
gomega.Expect(found).To(o.BeTrue(), "should have found the NodeInstallerProgressing condition")
545-
gomega.Expect(nipCond.Status).To(o.Equal(operatorv1.ConditionFalse), "NodeInstallerProgressing condition should be True")
560+
gomega.Expect(nipCond.Status).To(o.Equal(operatorv1.ConditionFalse), "NodeInstallerProgressing condition should be False", nipCond)
546561
}).WithTimeout(30*time.Minute).WithPolling(30*time.Second).Should(o.Succeed(), "should eventually rollout out a new revision successfully")
547562
}

0 commit comments

Comments
 (0)