From c097317a07740a62311bc2d4cca24d25bcd88a0f Mon Sep 17 00:00:00 2001 From: Sebastian Widmer Date: Thu, 12 Oct 2023 15:38:23 +0200 Subject: [PATCH] Fix teams synced as top-level organization #57 changed the `keycloak.NewGroup` signature to take the first argument as the display name. The teams controller was forgotten and the organization name 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{