Skip to content

Commit 856479f

Browse files
committed
keycloakclient: fix user creation so that authentication as the created user is valid
Signed-off-by: Bryce Palmer <[email protected]>
1 parent 489cf9d commit 856479f

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
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/oidc.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ var _ = g.Describe("[sig-auth][Suite:openshift/auth/external-oidc][Serial][Slow]
150150
gomega.Expect(err).NotTo(o.HaveOccurred(), "should not encounter an error authenticating as keycloak user")
151151

152152
copiedOC := *oc
153-
tokenOC := copiedOC.WithToken(keycloakCli.AccessToken())
153+
token := keycloakCli.AccessToken()
154+
tokenOC := copiedOC.WithToken(token)
154155
ssr, err := tokenOC.KubeClient().AuthenticationV1().SelfSubjectReviews().Create(ctx, &authnv1.SelfSubjectReview{
155156
ObjectMeta: metav1.ObjectMeta{
156157
Name: fmt.Sprintf("%s-info", username),
@@ -495,7 +496,9 @@ func resetAuthentication(ctx context.Context, client *exutil.CLI, original *conf
495496

496497
_, err = cli.Update(ctx, current, metav1.UpdateOptions{})
497498
if err != nil {
498-
return false, err
499+
// Only log the error so we continue to retry until the context has timed out
500+
g.GinkgoLogr.Error(err, "updating authentication resource")
501+
return false, nil
499502
}
500503

501504
return true, nil
@@ -523,8 +526,8 @@ func waitForRollout(ctx context.Context, client *exutil.CLI) {
523526
}
524527

525528
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")
529+
gomega.Expect(nipCond.Status).To(o.Equal(operatorv1.ConditionTrue), "NodeInstallerProgressing condition should be True", nipCond)
530+
}).WithTimeout(10*time.Minute).WithPolling(20*time.Second).Should(o.Succeed(), "should eventually begin rolling out a new revision")
528531

529532
// Then wait for it to flip back
530533
o.Eventually(func(gomega o.Gomega) {
@@ -542,6 +545,6 @@ func waitForRollout(ctx context.Context, client *exutil.CLI) {
542545
}
543546

544547
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")
548+
gomega.Expect(nipCond.Status).To(o.Equal(operatorv1.ConditionFalse), "NodeInstallerProgressing condition should be False", nipCond)
546549
}).WithTimeout(30*time.Minute).WithPolling(30*time.Second).Should(o.Succeed(), "should eventually rollout out a new revision successfully")
547550
}

0 commit comments

Comments
 (0)