From 6f7bd454b2e3103756b041d9f6afb0adcd07ccde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sw=C3=A4rd?= Date: Tue, 14 Mar 2023 14:10:13 +0100 Subject: [PATCH] Fix so that userType is not returned if not available. --- services/graph/pkg/identity/ldap.go | 4 ++-- services/graph/pkg/identity/ldap_test.go | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/services/graph/pkg/identity/ldap.go b/services/graph/pkg/identity/ldap.go index a18e07c0c..dbe899bdb 100644 --- a/services/graph/pkg/identity/ldap.go +++ b/services/graph/pkg/identity/ldap.go @@ -557,6 +557,7 @@ func (i *LDAP) GetUsers(ctx context.Context, oreq *godata.GoDataRequest) ([]*lib i.userAttributeMap.surname, i.userAttributeMap.givenName, i.userAttributeMap.accountEnabled, + i.userAttributeMap.userType, }, nil, ) @@ -717,7 +718,6 @@ func (i *LDAP) createUserModelFromLDAP(e *ldap.Entry) *libregraph.User { id := e.GetEqualFoldAttributeValue(i.userAttributeMap.id) givenName := e.GetEqualFoldAttributeValue(i.userAttributeMap.givenName) surname := e.GetEqualFoldAttributeValue(i.userAttributeMap.surname) - userType := e.GetEqualFoldAttributeValue(i.userAttributeMap.userType) if id != "" && opsan != "" { return &libregraph.User{ @@ -727,7 +727,7 @@ func (i *LDAP) createUserModelFromLDAP(e *ldap.Entry) *libregraph.User { Id: &id, GivenName: &givenName, Surname: &surname, - UserType: &userType, + UserType: pointerOrNil(e.GetEqualFoldAttributeValue(i.userAttributeMap.userType)), AccountEnabled: booleanOrNil(e.GetEqualFoldAttributeValue(i.userAttributeMap.accountEnabled)), } } diff --git a/services/graph/pkg/identity/ldap_test.go b/services/graph/pkg/identity/ldap_test.go index 27623832d..1364c0c3c 100644 --- a/services/graph/pkg/identity/ldap_test.go +++ b/services/graph/pkg/identity/ldap_test.go @@ -300,6 +300,7 @@ func TestGetUsers(t *testing.T) { func TestUpdateUser(t *testing.T) { falseBool := false trueBool := true + memberType := "Member" type userProps struct { id string @@ -307,7 +308,7 @@ func TestUpdateUser(t *testing.T) { displayName string onPremisesSamAccountName string accountEnabled *bool - userType string + userType *string } type args struct { nameOrID string @@ -1277,7 +1278,7 @@ func TestUpdateUser(t *testing.T) { args: args{ nameOrID: "testUser", userProps: userProps{ - userType: "Member", + userType: &memberType, }, disableUserMechanism: "group", }, @@ -1286,7 +1287,7 @@ func TestUpdateUser(t *testing.T) { mail: "testuser@example.org", displayName: "testUser", onPremisesSamAccountName: "testUser", - userType: "Member", + userType: &memberType, }, assertion: func(t assert.TestingT, err error, args ...interface{}) bool { return assert.Nil(t, err, args...) @@ -1428,7 +1429,7 @@ func TestUpdateUser(t *testing.T) { DisplayName: &tt.args.userProps.displayName, OnPremisesSamAccountName: &tt.args.userProps.onPremisesSamAccountName, AccountEnabled: tt.args.userProps.accountEnabled, - UserType: &tt.args.userProps.userType, + UserType: tt.args.userProps.userType, } emptyString := "" @@ -1441,7 +1442,7 @@ func TestUpdateUser(t *testing.T) { OnPremisesSamAccountName: &tt.want.onPremisesSamAccountName, Surname: &emptyString, GivenName: &emptyString, - UserType: &tt.want.userType, + UserType: tt.want.userType, } if tt.want.accountEnabled != nil {