Skip to content

Commit ba56a5a

Browse files
committed
test(oidc): test current keycloak implementation
1 parent c91acd2 commit ba56a5a

File tree

6 files changed

+291
-97
lines changed

6 files changed

+291
-97
lines changed

.drone.yml

+16-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ steps:
6262
TYPESENSE_API_KEY: typesense
6363
TEXT_EXTRACTION_TIKA_URL: http://tika:9998
6464
RAG_CRAWLER_LAUNCHER_URL: http://chrome:7317
65+
KEYCLOAK_URL: http://keycloak:8080/auth
66+
KEYCLOAK_FRONTEND_URL: http://keycloak:8080/auth/
67+
KEYCLOAK_PASSWORD: REPLACE_ME
68+
6569
commands:
6670
- go test -v ./...
6771
when:
@@ -146,7 +150,18 @@ services:
146150
POSTGRES_USER: postgres
147151
POSTGRES_PASSWORD: postgres
148152
POSTGRES_DB: postgres
149-
153+
- name: keycloak
154+
image: quay.io/keycloak/keycloak:23.0
155+
command: ["start-dev"]
156+
environment:
157+
KC_DB: postgres
158+
KC_DB_URL: jdbc:postgresql://postgres:5432/postgres # Unable to run scripts to create keycloak database, so using the default instead
159+
KC_DB_USERNAME: postgres
160+
KC_DB_PASSWORD: postgres
161+
KEYCLOAK_ADMIN: admin
162+
KEYCLOAK_ADMIN_PASSWORD: REPLACE_ME
163+
KC_HOSTNAME_PATH: /auth
164+
KC_HTTP_RELATIVE_PATH: /auth/
150165
---
151166
kind: pipeline
152167
type: docker

api/pkg/auth/keycloak.go

+10
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ func setRealmConfigurations(gck *gocloak.GoCloak, token string, cfg *config.Keyc
165165
return fmt.Errorf("setRealmConfiguration: error decoding realm.json: %s", err.Error())
166166
}
167167

168+
// Initialize attributes if not set
169+
if keycloakRealmConfig.Attributes == nil {
170+
keycloakRealmConfig.Attributes = &map[string]string{}
171+
}
172+
168173
_, err = gck.CreateRealm(context.Background(), token, keycloakRealmConfig)
169174
if err != nil {
170175
return fmt.Errorf("setRealmConfiguration: no Keycloak realm found, attempt to create realm failed with: %s", err.Error())
@@ -176,6 +181,11 @@ func setRealmConfigurations(gck *gocloak.GoCloak, token string, cfg *config.Keyc
176181
}
177182
}
178183

184+
// Initialize attributes if not set
185+
if realm.Attributes == nil {
186+
realm.Attributes = &map[string]string{}
187+
}
188+
179189
attributes := *realm.Attributes
180190
attributes["frontendUrl"] = cfg.KeycloakFrontEndURL
181191
*realm.Attributes = attributes

0 commit comments

Comments
 (0)