From c297733dc613a8bed4db2fb9f44cd2f1648f3d6d Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Thu, 12 Oct 2023 15:46:55 +0200 Subject: [PATCH] Fix teams synced as top-level organization (#59) #57 changed the `keycloak.NewGroup` signature to take the first argument as the display name. The teams controller was forgotten. The organization of the team was used as the display name and removed from the path. This made the team look like an organization after syncing them to Keycloak. --- controllers/team_controller.go | 2 +- controllers/team_controller_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/controllers/team_controller.go b/controllers/team_controller.go index c395e83..65a187e 100644 --- a/controllers/team_controller.go +++ b/controllers/team_controller.go @@ -110,7 +110,7 @@ func buildTeamKeycloakGroup(team *controlv1.Team) keycloak.Group { groupMem = append(groupMem, u.Name) } - return keycloak.NewGroup(team.Namespace, team.Name).WithMemberNames(groupMem...) + return keycloak.NewGroup(team.Spec.DisplayName, team.Namespace, team.Name).WithMemberNames(groupMem...) } // SetupWithManager sets up the controller with the Manager. diff --git a/controllers/team_controller_test.go b/controllers/team_controller_test.go index c143112..20b7bb0 100644 --- a/controllers/team_controller_test.go +++ b/controllers/team_controller_test.go @@ -22,7 +22,7 @@ func Test_TeamController_Reconcile_Success(t *testing.T) { ctx := context.Background() c, keyMock, _ := prepareTest(t, barTeam) - group := keycloak.NewGroup(barTeam.Namespace, barTeam.Name).WithMemberNames("baz", "qux") + group := keycloak.NewGroup(barTeam.Spec.DisplayName, barTeam.Namespace, barTeam.Name).WithMemberNames("baz", "qux") keyMock.EXPECT(). PutGroup(gomock.Any(), group). Return(group, nil). @@ -50,7 +50,7 @@ func Test_TeamController_Reconcile_Failure(t *testing.T) { ctx := context.Background() c, keyMock, erMock := prepareTest(t, barTeam) - group := keycloak.NewGroup(barTeam.Namespace, barTeam.Name).WithMemberNames("baz", "qux") + group := keycloak.NewGroup(barTeam.Spec.DisplayName, barTeam.Namespace, barTeam.Name).WithMemberNames("baz", "qux") keyMock.EXPECT(). PutGroup(gomock.Any(), group). Return(keycloak.Group{}, errors.New("create failed")). @@ -83,7 +83,7 @@ func Test_TeamController_Reconcile_Member_Failure(t *testing.T) { ctx := context.Background() c, keyMock, erMock := prepareTest(t, barTeam) - group := keycloak.NewGroup(barTeam.Namespace, barTeam.Name).WithMemberNames("baz", "qux") + group := keycloak.NewGroup(barTeam.Spec.DisplayName, barTeam.Namespace, barTeam.Name).WithMemberNames("baz", "qux") keyMock.EXPECT(). PutGroup(gomock.Any(), group). Return(keycloak.Group{}, &keycloak.MembershipSyncErrors{