Fix so that userType is not returned if not available.

This commit is contained in:
Daniel Swärd
2023-03-14 14:10:13 +01:00
committed by Ralf Haferkamp
parent b12b2d2bac
commit 6f7bd454b2
2 changed files with 8 additions and 7 deletions

View File

@@ -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)),
}
}

View File

@@ -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 {