Skip to content

Commit 6f8bcdd

Browse files
committed
Add ExternalOIDCWithUpstreamParity e2e tests
1 parent 1980b0d commit 6f8bcdd

2 files changed

Lines changed: 469 additions & 4 deletions

File tree

test/extended/authentication/keycloak_client.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ func (kc *keycloakClient) CreateGroup(name string) error {
6666
defer resp.Body.Close()
6767

6868
if resp.StatusCode != http.StatusCreated {
69+
// If the group already exists (409 Conflict), that's fine - we can reuse it
70+
if resp.StatusCode == http.StatusConflict {
71+
return nil
72+
}
6973
respBytes, _ := io.ReadAll(resp.Body)
7074
return fmt.Errorf("failed creating group %q: %s - %s", name, resp.Status, respBytes)
7175
}
@@ -95,11 +99,15 @@ const (
9599
)
96100

97101
func (kc *keycloakClient) CreateUser(username, password string, groups ...string) error {
102+
return kc.CreateUserWithEmail(username, fmt.Sprintf("%s@payload.openshift.io", username), password, groups...)
103+
}
104+
105+
func (kc *keycloakClient) CreateUserWithEmail(username, email, password string, groups ...string) error {
98106
userURL := kc.adminURL.JoinPath("users")
99107

100108
user := user{
101109
Username: username,
102-
Email: fmt.Sprintf("%s@payload.openshift.io", username),
110+
Email: email,
103111
Enabled: true,
104112
EmailVerified: true,
105113
Groups: groups,
@@ -114,18 +122,18 @@ func (kc *keycloakClient) CreateUser(username, password string, groups ...string
114122

115123
userBytes, err := json.Marshal(user)
116124
if err != nil {
117-
return fmt.Errorf("marshalling user configuration %v", user)
125+
return fmt.Errorf("marshalling user configuration for %q: %w", username, err)
118126
}
119127

120128
resp, err := kc.DoRequest(http.MethodPost, userURL.String(), runtime.ContentTypeJSON, true, bytes.NewBuffer(userBytes))
121129
if err != nil {
122-
return fmt.Errorf("sending POST request to %q to create user %v", userURL.String(), user)
130+
return fmt.Errorf("sending POST request to %q to create user %q: %w", userURL.String(), username, err)
123131
}
124132
defer resp.Body.Close()
125133

126134
if resp.StatusCode != http.StatusCreated {
127135
respBytes, _ := io.ReadAll(resp.Body)
128-
return fmt.Errorf("failed creating user %v: %s - %s", user, resp.Status, respBytes)
136+
return fmt.Errorf("failed creating user %q: %s - %s", username, resp.Status, respBytes)
129137
}
130138

131139
return nil

0 commit comments

Comments
 (0)