From a89275da850c1c2cfaf4cc5d3e2dbe5fa9d0e9f3 Mon Sep 17 00:00:00 2001 From: Ferruh Cihan <63190600+ferruhcihan@users.noreply.github.com> Date: Wed, 2 Oct 2024 10:05:25 +0200 Subject: [PATCH] test: users --- src/operator/keycloak.ts | 8 ++++---- src/tasks/keycloak/config.ts | 7 ++----- src/tasks/keycloak/realm-factory.ts | 4 +--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/operator/keycloak.ts b/src/operator/keycloak.ts index 36f97a3..d1a113e 100644 --- a/src/operator/keycloak.ts +++ b/src/operator/keycloak.ts @@ -710,8 +710,8 @@ async function manageGroups(connection: KeycloakConnection) { } async function createUpdateUser(api: any, user: any) { - const { username, email, firstName, lastName, isPlatformAdmin, isTeamAdmin, teams, teamId } = user - const userConf = createTeamUser(username, email, firstName, lastName, isPlatformAdmin, isTeamAdmin, teams, teamId) + const { email, firstName, lastName, isPlatformAdmin, isTeamAdmin, teams } = user + const userConf = createTeamUser(email, firstName, lastName, isPlatformAdmin, isTeamAdmin, teams) const existingUsersByUserEmail = (await doApiCall([], `Getting users`, () => api.users.realmUsersGet(keycloakRealm, false, `${email}`), )) as UserRepresentation[] @@ -723,11 +723,11 @@ async function createUpdateUser(api: any, user: any) { const updatedUserConf = existingUser.requiredActions?.includes('UPDATE_PASSWORD') ? userConf : omit(userConf, ['credentials']) - await doApiCall(errors, `Updating user ${username}`, async () => + await doApiCall(errors, `Updating user ${email}`, async () => api.users.realmUsersIdPut(keycloakRealm, existingUser.id as string, updatedUserConf), ) } else { - await doApiCall(errors, `Creating user ${username}`, () => api.users.realmUsersPost(keycloakRealm, userConf)) + await doApiCall(errors, `Creating user ${email}`, () => api.users.realmUsersPost(keycloakRealm, userConf)) } } catch (error) { console.error('Error in internalIDP: ', error) diff --git a/src/tasks/keycloak/config.ts b/src/tasks/keycloak/config.ts index 3b5a0d6..8d27cae 100644 --- a/src/tasks/keycloak/config.ts +++ b/src/tasks/keycloak/config.ts @@ -71,16 +71,14 @@ export const adminUserCfgTpl = (username: string, password: string): Record => ({ - username, + username: email, enabled: true, email, emailVerified: true, @@ -90,13 +88,12 @@ export const teamUserCfgTpl = ( groups: [ ...(isPlatformAdmin ? ['platform-admin'] : []), ...(isTeamAdmin ? ['team-admin'] : []), - `team-${teamId}`, ...(teams.length > 0 ? teams.map((team) => `team-${team}`) : []), ], credentials: [ { type: 'password', - value: `${username}@APL`, + value: `${email}`, temporary: true, }, ], diff --git a/src/tasks/keycloak/realm-factory.ts b/src/tasks/keycloak/realm-factory.ts index f15305e..34e265b 100644 --- a/src/tasks/keycloak/realm-factory.ts +++ b/src/tasks/keycloak/realm-factory.ts @@ -120,18 +120,16 @@ export function createAdminUser(username: string, password: string): UserReprese return userRepresentation } export function createTeamUser( - username: string, email: string, firstName: string, lastName: string, isPlatformAdmin: boolean, isTeamAdmin: boolean, teams: string[], - teamId: string, ): UserRepresentation { const userRepresentation = defaultsDeep( new UserRepresentation(), - teamUserCfgTpl(username, email, firstName, lastName, isPlatformAdmin, isTeamAdmin, teams, teamId), + teamUserCfgTpl(email, firstName, lastName, isPlatformAdmin, isTeamAdmin, teams), ) return userRepresentation }