Skip to content

Commit 5fb6604

Browse files
committed
Add ExternalOIDCWithUpstreamParity e2e tests
1 parent c77ff4a commit 5fb6604

2 files changed

Lines changed: 436 additions & 5 deletions

File tree

test/extended/authentication/keycloak_client.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ func (kc *keycloakClient) CreateGroup(name string) error {
6565
}
6666
defer resp.Body.Close()
6767

68-
if resp.StatusCode != http.StatusCreated {
68+
if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusConflict {
69+
// If the group already exists (409 Conflict), that's fine - we can reuse it
6970
respBytes, _ := io.ReadAll(resp.Body)
7071
return fmt.Errorf("failed creating group %q: %s - %s", name, resp.Status, respBytes)
7172
}
@@ -95,11 +96,15 @@ const (
9596
)
9697

9798
func (kc *keycloakClient) CreateUser(username, password string, groups ...string) error {
99+
return kc.CreateUserWithEmail(username, fmt.Sprintf("%s@payload.openshift.io", username), password, groups...)
100+
}
101+
102+
func (kc *keycloakClient) CreateUserWithEmail(username, email, password string, groups ...string) error {
98103
userURL := kc.adminURL.JoinPath("users")
99104

100105
user := user{
101106
Username: username,
102-
Email: fmt.Sprintf("%s@payload.openshift.io", username),
107+
Email: email,
103108
Enabled: true,
104109
EmailVerified: true,
105110
Groups: groups,
@@ -114,18 +119,18 @@ func (kc *keycloakClient) CreateUser(username, password string, groups ...string
114119

115120
userBytes, err := json.Marshal(user)
116121
if err != nil {
117-
return fmt.Errorf("marshalling user configuration %v", user)
122+
return fmt.Errorf("marshalling user configuration for %q: %w", username, err)
118123
}
119124

120125
resp, err := kc.DoRequest(http.MethodPost, userURL.String(), runtime.ContentTypeJSON, true, bytes.NewBuffer(userBytes))
121126
if err != nil {
122-
return fmt.Errorf("sending POST request to %q to create user %v", userURL.String(), user)
127+
return fmt.Errorf("sending POST request to %q to create user %q: %w", userURL.String(), username, err)
123128
}
124129
defer resp.Body.Close()
125130

126131
if resp.StatusCode != http.StatusCreated {
127132
respBytes, _ := io.ReadAll(resp.Body)
128-
return fmt.Errorf("failed creating user %v: %s - %s", user, resp.Status, respBytes)
133+
return fmt.Errorf("failed creating user %q: %s - %s", username, resp.Status, respBytes)
129134
}
130135

131136
return nil

0 commit comments

Comments
 (0)