fix: typos, naming clashes, error messages and deprecations

This commit is contained in:
Thomas Müller
2024-04-03 15:34:36 +02:00
parent 48da9cfbee
commit 07f0cd5574
107 changed files with 298 additions and 310 deletions
+5 -5
View File
@@ -50,7 +50,7 @@ type Backend interface {
type EducationBackend interface {
// CreateEducationSchool creates the supplied school in the identity backend.
CreateEducationSchool(ctx context.Context, group libregraph.EducationSchool) (*libregraph.EducationSchool, error)
// DeleteSchool deletes a given school, identified by id
// DeleteEducationSchool deletes a given school, identified by id
DeleteEducationSchool(ctx context.Context, id string) error
// GetEducationSchool reads a given school by id
GetEducationSchool(ctx context.Context, nameOrID string) (*libregraph.EducationSchool, error)
@@ -65,7 +65,7 @@ type EducationBackend interface {
// RemoveUserFromEducationSchool removes a single member (by ID) from a school
RemoveUserFromEducationSchool(ctx context.Context, schoolID string, memberID string) error
// GetEducationSchoolClasses lists all classes in a chool
// GetEducationSchoolClasses lists all classes in a school
GetEducationSchoolClasses(ctx context.Context, schoolNumberOrID string) ([]*libregraph.EducationClass, error)
// AddClassesToEducationSchool adds new classes (referenced by a slice of IDs) to supplied school in the identity backend.
AddClassesToEducationSchool(ctx context.Context, schoolNumberOrID string, memberIDs []string) error
@@ -74,7 +74,7 @@ type EducationBackend interface {
// GetEducationClasses lists all classes
GetEducationClasses(ctx context.Context) ([]*libregraph.EducationClass, error)
// GetEducationClasses reads a given class by id
// GetEducationClass reads a given class by id
GetEducationClass(ctx context.Context, namedOrID string) (*libregraph.EducationClass, error)
// CreateEducationClass creates the supplied education class in the identity backend.
CreateEducationClass(ctx context.Context, class libregraph.EducationClass) (*libregraph.EducationClass, error)
@@ -87,7 +87,7 @@ type EducationBackend interface {
// CreateEducationUser creates a given education user in the identity backend.
CreateEducationUser(ctx context.Context, user libregraph.EducationUser) (*libregraph.EducationUser, error)
// DeleteEducationUser deletes a given educationuser, identified by username or id, from the backend
// DeleteEducationUser deletes a given education user, identified by username or id, from the backend
DeleteEducationUser(ctx context.Context, nameOrID string) error
// UpdateEducationUser applies changes to given education user, identified by username or id
UpdateEducationUser(ctx context.Context, nameOrID string, user libregraph.EducationUser) (*libregraph.EducationUser, error)
@@ -98,7 +98,7 @@ type EducationBackend interface {
// GetEducationClassTeachers returns the EducationUser teachers for an EducationClass
GetEducationClassTeachers(ctx context.Context, classID string) ([]*libregraph.EducationUser, error)
// AddTeacherToEducationclass adds a teacher (by ID) to class in the identity backend.
// AddTeacherToEducationClass adds a teacher (by ID) to class in the identity backend.
AddTeacherToEducationClass(ctx context.Context, classID string, teacherID string) error
// RemoveTeacherFromEducationClass removes teacher (by ID) from a class
RemoveTeacherFromEducationClass(ctx context.Context, classID string, teacherID string) error
+12 -12
View File
@@ -28,7 +28,7 @@ type identityCacheOptions struct {
groupsTTL time.Duration
}
// IdentityCacheOptiondefines a single option function.
// IdentityCacheOption defines a single option function.
type IdentityCacheOption func(o *identityCacheOptions)
// IdentityCacheWithGatewaySelector set the gatewaySelector for the Identity Cache
@@ -60,7 +60,7 @@ func newOptions(opts ...IdentityCacheOption) identityCacheOptions {
return opt
}
// NewIdentityCache instanciates a new IdentityCache and sets the supplied options
// NewIdentityCache instantiates a new IdentityCache and sets the supplied options
func NewIdentityCache(opts ...IdentityCacheOption) IdentityCache {
opt := newOptions(opts...)
@@ -83,7 +83,7 @@ func NewIdentityCache(opts ...IdentityCacheOption) IdentityCache {
return cache
}
// GetUser looks up a user by id, if the user is not cached yet it will do a lookup via the CS3 API
// GetUser looks up a user by id, if the user is not cached, yet it will do a lookup via the CS3 API
func (cache IdentityCache) GetUser(ctx context.Context, userid string) (libregraph.User, error) {
var user libregraph.User
if item := cache.users.Get(userid); item == nil {
@@ -91,14 +91,14 @@ func (cache IdentityCache) GetUser(ctx context.Context, userid string) (libregra
cs3UserID := &cs3User.UserId{
OpaqueId: userid,
}
cs3User, err := revautils.GetUser(cs3UserID, gatewayClient)
u, err := revautils.GetUserWithContext(ctx, cs3UserID, gatewayClient)
if err != nil {
if revautils.IsErrNotFound(err) {
return libregraph.User{}, ErrNotFound
}
return libregraph.User{}, errorcode.New(errorcode.GeneralException, err.Error())
}
user = *CreateUserModelFromCS3(cs3User)
user = *CreateUserModelFromCS3(u)
cache.users.Set(userid, user, ttlcache.DefaultTTL)
} else {
@@ -107,13 +107,13 @@ func (cache IdentityCache) GetUser(ctx context.Context, userid string) (libregra
return user, nil
}
// GetUser looks up a group by id, if the group is not cached yet it will do a lookup via the CS3 API
func (cache IdentityCache) GetGroup(ctx context.Context, groupid string) (libregraph.Group, error) {
// GetGroup looks up a group by id, if the group is not cached, yet it will do a lookup via the CS3 API
func (cache IdentityCache) GetGroup(ctx context.Context, groupID string) (libregraph.Group, error) {
var group libregraph.Group
if item := cache.groups.Get(groupid); item == nil {
if item := cache.groups.Get(groupID); item == nil {
gatewayClient, err := cache.gatewaySelector.Next()
cs3GroupID := &cs3Group.GroupId{
OpaqueId: groupid,
OpaqueId: groupID,
}
req := cs3Group.GetGroupRequest{
GroupId: cs3GroupID,
@@ -124,9 +124,9 @@ func (cache IdentityCache) GetGroup(ctx context.Context, groupid string) (libreg
}
switch res.Status.Code {
case rpc.Code_CODE_OK:
cs3Group := res.GetGroup()
group = *CreateGroupModelFromCS3(cs3Group)
cache.groups.Set(groupid, group, ttlcache.DefaultTTL)
g := res.GetGroup()
group = *CreateGroupModelFromCS3(g)
cache.groups.Set(groupID, group, ttlcache.DefaultTTL)
case rpc.Code_CODE_NOT_FOUND:
return group, ErrNotFound
default:
+1 -1
View File
@@ -36,7 +36,7 @@ func (i *CS3) DeleteUser(ctx context.Context, nameOrID string) error {
return errNotImplemented
}
// UpdateUser implements the Backend Interface. It's currently not suported for the CS3 backend
// UpdateUser implements the Backend Interface. It's currently not supported for the CS3 backend
func (i *CS3) UpdateUser(ctx context.Context, nameOrID string, user libregraph.User) (*libregraph.User, error) {
return nil, errNotImplemented
}
+2 -2
View File
@@ -89,7 +89,7 @@ func (i *ErrEducationBackend) GetEducationClassMembers(ctx context.Context, name
return nil, errNotImplemented
}
// UpdateEducationClass implments the EducationBackend interface
// UpdateEducationClass implements the EducationBackend interface
func (i *ErrEducationBackend) UpdateEducationClass(ctx context.Context, id string, class libregraph.EducationClass) (*libregraph.EducationClass, error) {
return nil, errNotImplemented
}
@@ -99,7 +99,7 @@ func (i *ErrEducationBackend) CreateEducationUser(ctx context.Context, user libr
return nil, errNotImplemented
}
// DeleteEducationUser deletes a given educationuser, identified by username or id, from the backend
// DeleteEducationUser deletes a given education user, identified by username or id, from the backend
func (i *ErrEducationBackend) DeleteEducationUser(ctx context.Context, nameOrID string) error {
return errNotImplemented
}
+11 -11
View File
@@ -203,7 +203,7 @@ func (i *LDAP) CreateUser(ctx context.Context, user libregraph.User) (*libregrap
}
if i.usePwModifyExOp && user.PasswordProfile != nil && user.PasswordProfile.Password != nil {
if err := i.updateUserPassowrd(ctx, ar.DN, user.PasswordProfile.GetPassword()); err != nil {
if err := i.updateUserPassword(ctx, ar.DN, user.PasswordProfile.GetPassword()); err != nil {
return nil, err
}
}
@@ -265,7 +265,7 @@ func (i *LDAP) UpdateUser(ctx context.Context, nameOrID string, user libregraph.
logger := i.logger.SubloggerWithRequestID(ctx)
logger.Debug().Str("backend", "ldap").Msg("UpdateUser")
if !i.writeEnabled {
// still allow eanble/disable User when using DisableMechanismGroup
// still allow to enable/disable user when using DisableMechanismGroup
if i.disableUserMechanism == DisableMechanismGroup && isUserEnabledUpdate(user) {
logger.Error().Str("backend", "ldap").Msg("Allowing accountEnabled Update on read-only backend")
} else {
@@ -319,7 +319,7 @@ func (i *LDAP) UpdateUser(ctx context.Context, nameOrID string, user libregraph.
if user.PasswordProfile != nil && user.PasswordProfile.GetPassword() != "" {
if i.usePwModifyExOp {
if err := i.updateUserPassowrd(ctx, e.DN, user.PasswordProfile.GetPassword()); err != nil {
if err := i.updateUserPassword(ctx, e.DN, user.PasswordProfile.GetPassword()); err != nil {
msg := "error updating user password"
logger.Error().Err(err).Msg(msg)
errMap := ldapResultToErrMap{
@@ -376,7 +376,7 @@ func (i *LDAP) UpdateUser(ctx context.Context, nameOrID string, user libregraph.
returnUser := i.createUserModelFromLDAP(e)
// To avoid an ldap lookup for group membership, set the enabled flag to same as input value
// To avoid a ldap lookup for group membership, set the enabled flag to same as input value
// since this would have been updated with group membership from the input anyway.
if user.AccountEnabled != nil && i.disableUserMechanism == DisableMechanismGroup {
returnUser.AccountEnabled = user.AccountEnabled
@@ -490,7 +490,7 @@ func filterEscapeUUID(binary bool, id string) (string, error) {
func (i *LDAP) getLDAPUserByID(id string) (*ldap.Entry, error) {
idString, err := filterEscapeUUID(i.userIDisOctetString, id)
if err != nil {
return nil, fmt.Errorf("Invalid User id: %w", err)
return nil, fmt.Errorf("invalid User id: %w", err)
}
filter := fmt.Sprintf("(%s=%s)", i.userAttributeMap.id, idString)
return i.getLDAPUserByFilter(filter)
@@ -498,7 +498,7 @@ func (i *LDAP) getLDAPUserByID(id string) (*ldap.Entry, error) {
func (i *LDAP) getLDAPUserByNameOrID(nameOrID string) (*ldap.Entry, error) {
idString, err := filterEscapeUUID(i.userIDisOctetString, nameOrID)
// err != nil just means that this is not a uuid so we can skip the uuid filterpart
// err != nil just means that this is not an uuid, so we can skip the uuid filter part
// and just filter by name
filter := ""
if err == nil {
@@ -738,9 +738,9 @@ func (i *LDAP) renameMemberInGroup(ctx context.Context, group *ldap.Entry, oldMe
return nil
}
func (i *LDAP) updateUserPassowrd(ctx context.Context, dn, password string) error {
func (i *LDAP) updateUserPassword(ctx context.Context, dn, password string) error {
logger := i.logger.SubloggerWithRequestID(ctx)
logger.Debug().Str("backend", "ldap").Msg("updateUserPassowrd")
logger.Debug().Str("backend", "ldap").Msg("updateUserPassword")
pwMod := ldap.PasswordModifyRequest{
UserIdentity: dn,
NewPassword: password,
@@ -915,7 +915,7 @@ func stringToScope(scope string) (int, error) {
return s, nil
}
// removeEntryByDNAndAttributeFromEntry creates a request to remove a single member entry by attribute and DN from an ldap entry
// removeEntryByDNAndAttributeFromEntry creates a request to remove a single member entry by attribute and DN from a ldap entry
func (i *LDAP) removeEntryByDNAndAttributeFromEntry(entry *ldap.Entry, dn string, attribute string) error {
nOldDN, err := ldapdn.ParseNormalize(dn)
if err != nil {
@@ -982,7 +982,7 @@ func (i *LDAP) removeEntryByDNAndAttributeFromEntry(entry *ldap.Entry, dn string
return nil
}
// expandLDAPAttributeEntries reads an attribute from an ldap entry and expands to users
// expandLDAPAttributeEntries reads an attribute from a ldap entry and expands to users
func (i *LDAP) expandLDAPAttributeEntries(ctx context.Context, e *ldap.Entry, attribute string) ([]*ldap.Entry, error) {
logger := i.logger.SubloggerWithRequestID(ctx)
logger.Debug().Str("backend", "ldap").Msg("ExpandLDAPAttributeEntries")
@@ -1007,7 +1007,7 @@ func (i *LDAP) expandLDAPAttributeEntries(ctx context.Context, e *ldap.Entry, at
func replaceDN(fullDN *ldap.DN, newDN string) (string, error) {
if len(fullDN.RDNs) == 0 {
return "", fmt.Errorf("Can't operate on an empty dn")
return "", fmt.Errorf("can't operate on an empty dn")
}
if len(fullDN.RDNs) == 1 {
@@ -24,7 +24,7 @@ type ldapConnection struct {
Error error
}
// Implements the ldap.CLient interface
// ConnWithReconnect implements the ldap.Client interface
type ConnWithReconnect struct {
conn chan ldapConnection
reset chan *ldap.Conn
@@ -66,7 +66,7 @@ func (i *LDAP) GetEducationClasses(ctx context.Context) ([]*libregraph.Education
// CreateEducationClass implements the EducationBackend interface for the LDAP backend.
// An EducationClass is mapped to an LDAP entry of the "groupOfNames" structural ObjectClass.
// With a few additional Attributes added on top via the "ocEducationClass" auxiallary ObjectClass.
// With a few additional Attributes added on top via the "ocEducationClass" auxiliary ObjectClass.
func (i *LDAP) CreateEducationClass(ctx context.Context, class libregraph.EducationClass) (*libregraph.EducationClass, error) {
logger := i.logger.SubloggerWithRequestID(ctx)
logger.Debug().Str("backend", "ldap").Msg("create educationClass")
@@ -56,15 +56,15 @@ func TestCreateEducationClass(t *testing.T) {
class := libregraph.NewEducationClass("Math", "course")
class.SetExternalId("Math0123")
class.SetId("abcd-defg")
res_class, err := b.CreateEducationClass(context.Background(), *class)
resClass, err := b.CreateEducationClass(context.Background(), *class)
lm.AssertNumberOfCalls(t, "Add", 1)
lm.AssertNumberOfCalls(t, "Search", 1)
assert.Nil(t, err)
assert.NotNil(t, res_class)
assert.Equal(t, res_class.GetDisplayName(), class.GetDisplayName())
assert.Equal(t, res_class.GetId(), class.GetId())
assert.Equal(t, res_class.GetExternalId(), class.GetExternalId())
assert.Equal(t, res_class.GetClassification(), class.GetClassification())
assert.NotNil(t, resClass)
assert.Equal(t, resClass.GetDisplayName(), class.GetDisplayName())
assert.Equal(t, resClass.GetId(), class.GetId())
assert.Equal(t, resClass.GetExternalId(), class.GetExternalId())
assert.Equal(t, resClass.GetClassification(), class.GetClassification())
}
func TestGetEducationClasses(t *testing.T) {
@@ -268,7 +268,7 @@ func TestGetEducationClassMembers(t *testing.T) {
for _, tt := range tests {
lm := &mocks.Client{}
user_sr := &ldap.SearchRequest{
userSr := &ldap.SearchRequest{
BaseDN: "uid=user",
Scope: 0,
SizeLimit: 1,
@@ -276,7 +276,7 @@ func TestGetEducationClassMembers(t *testing.T) {
Attributes: []string{"displayname", "entryUUID", "mail", "uid", "sn", "givenname", "userEnabledAttribute", "userTypeAttribute"},
Controls: []ldap.Control(nil),
}
lm.On("Search", user_sr).Return(&ldap.SearchResult{Entries: []*ldap.Entry{userEntry}}, nil)
lm.On("Search", userSr).Return(&ldap.SearchResult{Entries: []*ldap.Entry{userEntry}}, nil)
sr := &ldap.SearchRequest{
BaseDN: "ou=groups,dc=test",
Scope: 2,
@@ -50,7 +50,7 @@ const (
const ldapDateFormat = "20060102150405Z0700"
var (
errNotSet = errors.New("Attribute not set")
errNotSet = errors.New("attribute not set")
errSchoolNameExists = errorcode.New(errorcode.NameAlreadyExists, "A school with that name is already present")
errSchoolNumberExists = errorcode.New(errorcode.NameAlreadyExists, "A school with that number is already present")
)
@@ -761,7 +761,7 @@ func (i *LDAP) getTerminationDate(e *ldap.Entry) (*time.Time, error) {
}
t, err := time.Parse(ldapDateFormat, dateString)
if err != nil {
err = fmt.Errorf("Error parsing LDAP date: '%s': %w", dateString, err)
err = fmt.Errorf("error parsing LDAP date: '%s': %w", dateString, err)
return nil, err
}
return &t, nil
@@ -184,18 +184,18 @@ func TestCreateEducationSchool(t *testing.T) {
school.SetDisplayName(tt.schoolName)
school.SetSchoolNumber(tt.schoolNumber)
school.SetId("abcd-defg")
res_school, err := b.CreateEducationSchool(context.Background(), *school)
resSchool, err := b.CreateEducationSchool(context.Background(), *school)
if tt.expectedError == nil {
assert.Nil(t, err)
lm.AssertNumberOfCalls(t, "Add", 1)
assert.NotNil(t, res_school)
assert.Equal(t, res_school.GetDisplayName(), school.GetDisplayName())
assert.Equal(t, res_school.GetId(), school.GetId())
assert.Equal(t, res_school.GetSchoolNumber(), school.GetSchoolNumber())
assert.False(t, res_school.HasTerminationDate())
assert.NotNil(t, resSchool)
assert.Equal(t, resSchool.GetDisplayName(), school.GetDisplayName())
assert.Equal(t, resSchool.GetId(), school.GetId())
assert.Equal(t, resSchool.GetSchoolNumber(), school.GetSchoolNumber())
assert.False(t, resSchool.HasTerminationDate())
} else {
assert.Equal(t, err, tt.expectedError)
assert.Nil(t, res_school)
assert.Nil(t, resSchool)
}
}
}
@@ -238,15 +238,15 @@ func TestUpdateEducationSchoolTerminationDate(t *testing.T) {
school := libregraph.NewEducationSchool()
terminationTime := time.Date(2042, time.January, 31, 12, 0, 0, 0, time.UTC)
school.SetTerminationDate(terminationTime)
res_school, err := b.UpdateEducationSchool(context.Background(), "abcd-defg", *school)
resSchool, err := b.UpdateEducationSchool(context.Background(), "abcd-defg", *school)
lm.AssertNumberOfCalls(t, "Search", 2)
assert.Nil(t, err)
assert.NotNil(t, res_school)
assert.Equal(t, "Test School", res_school.GetDisplayName())
assert.Equal(t, "abcd-defg", res_school.GetId())
assert.Equal(t, "0123", res_school.GetSchoolNumber())
assert.True(t, res_school.HasTerminationDate())
assert.True(t, terminationTime.Equal(res_school.GetTerminationDate()))
assert.NotNil(t, resSchool)
assert.Equal(t, "Test School", resSchool.GetDisplayName())
assert.Equal(t, "abcd-defg", resSchool.GetId())
assert.Equal(t, "0123", resSchool.GetSchoolNumber())
assert.True(t, resSchool.HasTerminationDate())
assert.True(t, terminationTime.Equal(resSchool.GetTerminationDate()))
}
func TestUpdateEducationSchoolOperation(t *testing.T) {
@@ -55,7 +55,7 @@ func (i *LDAP) CreateEducationUser(ctx context.Context, user libregraph.Educatio
return i.createEducationUserModelFromLDAP(e), nil
}
// DeleteEducationUser deletes a given educationuser, identified by username or id, from the backend
// DeleteEducationUser deletes a given education user, identified by username or id, from the backend
func (i *LDAP) DeleteEducationUser(ctx context.Context, nameOrID string) error {
logger := i.logger.SubloggerWithRequestID(ctx)
logger.Debug().Str("backend", "ldap").Msg("DeleteEducationUser")
@@ -145,7 +145,7 @@ func (i *LDAP) UpdateEducationUser(ctx context.Context, nameOrID string, user li
}
if user.PasswordProfile != nil && user.PasswordProfile.GetPassword() != "" {
if i.usePwModifyExOp {
if err := i.updateUserPassowrd(ctx, e.DN, user.PasswordProfile.GetPassword()); err != nil {
if err := i.updateUserPassword(ctx, e.DN, user.PasswordProfile.GetPassword()); err != nil {
return nil, err
}
} else {
@@ -182,7 +182,7 @@ func (i *LDAP) UpdateEducationUser(ctx context.Context, nameOrID string, user li
returnUser := i.createEducationUserModelFromLDAP(e)
// To avoid an ldap lookup for group membership, set the enabled flag to same as input value
// To avoid a ldap lookup for group membership, set the enabled flag to same as input value
// since this would have been updated with group membership from the input anyway.
if user.AccountEnabled != nil && i.disableUserMechanism == DisableMechanismGroup {
returnUser.AccountEnabled = user.AccountEnabled
+8 -8
View File
@@ -280,7 +280,7 @@ func (i *LDAP) UpdateGroupName(ctx context.Context, groupID string, groupName st
}
// AddMembersToGroup implements the Backend Interface for the LDAP backend.
// Currently it is limited to adding Users as Group members. Adding other groups
// Currently, it is limited to adding Users as Group members. Adding other groups
// as members is not yet implemented
func (i *LDAP) AddMembersToGroup(ctx context.Context, groupID string, memberIDs []string) error {
logger := i.logger.SubloggerWithRequestID(ctx)
@@ -340,17 +340,17 @@ func (i *LDAP) AddMembersToGroup(ctx context.Context, groupID string, memberIDs
if len(newMemberDN) > 0 {
// Small retry loop. It might be that, when reading the group we found the empty group member ("",
// line 289 above). Our modify operation tries to delete that value. However another go-routine
// line 289 above). Our modify operation tries to delete that value. However, another go-routine
// might have done that in parallel. In that case
// (LDAPResultNoSuchAttribute) we need to retry the modification
// without the delete.
// without to delete.
for j := 0; j < 2; j++ {
mr.Add(i.groupAttributeMap.member, newMemberDN)
if err := i.conn.Modify(&mr); err != nil {
if lerr, ok := err.(*ldap.Error); ok {
switch lerr.ResultCode {
case ldap.LDAPResultAttributeOrValueExists:
err = fmt.Errorf("Duplicate member entries in request")
err = fmt.Errorf("duplicate member entries in request")
case ldap.LDAPResultNoSuchAttribute:
if len(mr.Changes) == 2 {
// We tried the special case for adding the first group member, but some
@@ -363,7 +363,7 @@ func (i *LDAP) AddMembersToGroup(ctx context.Context, groupID string, memberIDs
}
default:
logger.Info().Err(err).Msg("Failed to modify group member entries on PATCH group")
err = fmt.Errorf("Unknown error when trying to modify group member entries")
err = fmt.Errorf("unknown error when trying to modify group member entries")
}
}
return err
@@ -437,7 +437,7 @@ func (i *LDAP) groupToLDAPAttrValues(group libregraph.Group) (map[string][]strin
// as required attribute for groupOfNames/groupOfUniqueNames. So we
// add an empty string (which is a valid DN) as the initial member.
// It will be replaced once real members are added.
// We might wanna use the newer, but not so broadly used "groupOfMembers"
// We might want to use the newer, but not so broadly used "groupOfMembers"
// objectclass (RFC2307bis-02) where "member" is optional.
i.groupAttributeMap.member: {""},
}
@@ -452,7 +452,7 @@ func (i *LDAP) groupToLDAPAttrValues(group libregraph.Group) (map[string][]strin
func (i *LDAP) getLDAPGroupByID(id string, requestMembers bool) (*ldap.Entry, error) {
idString, err := filterEscapeUUID(i.groupIDisOctetString, id)
if err != nil {
return nil, fmt.Errorf("Invalid group id: %w", err)
return nil, fmt.Errorf("invalid group id: %w", err)
}
filter := fmt.Sprintf("(%s=%s)", i.groupAttributeMap.id, idString)
return i.getLDAPGroupByFilter(filter, requestMembers)
@@ -460,7 +460,7 @@ func (i *LDAP) getLDAPGroupByID(id string, requestMembers bool) (*ldap.Entry, er
func (i *LDAP) getLDAPGroupByNameOrID(nameOrID string, requestMembers bool) (*ldap.Entry, error) {
idString, err := filterEscapeUUID(i.groupIDisOctetString, nameOrID)
// err != nil just means that this is not a uuid so we can skip the uuid filterpart
// err != nil just means that this is not an uuid, so we can skip the uuid filter part
// and just filter by name
filter := ""
if err == nil {
@@ -45,7 +45,7 @@ var groupLookupSearchRequest = &ldap.SearchRequest{
Controls: []ldap.Control(nil),
}
var groupListSeachRequest = &ldap.SearchRequest{
var groupListSearchRequest = &ldap.SearchRequest{
BaseDN: "ou=groups,dc=test",
Scope: 2,
Filter: "(&(objectClass=groupOfNames))",
@@ -273,7 +273,7 @@ func TestGetGroups(t *testing.T) {
if err != nil {
t.Errorf("Expected success, got '%s'", err.Error())
}
lm.On("Search", groupListSeachRequest).Return(&ldap.SearchResult{Entries: []*ldap.Entry{groupEntry}}, nil)
lm.On("Search", groupListSearchRequest).Return(&ldap.SearchResult{Entries: []*ldap.Entry{groupEntry}}, nil)
lm.On("Search", sr2).Return(&ldap.SearchResult{Entries: []*ldap.Entry{userEntry}}, nil)
lm.On("Search", sr3).Return(&ldap.SearchResult{Entries: []*ldap.Entry{invalidUserEntry}}, nil)
b, _ = getMockedBackend(lm, lconfig, &logger)
@@ -439,8 +439,8 @@ func TestUpdateGroupName(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
lm := &mocks.Client{}
for _, mock := range tt.ldapMocks {
lm.On(mock.funcName, mock.args...).Return(mock.returns...)
for _, ldapMock := range tt.ldapMocks {
lm.On(ldapMock.funcName, ldapMock.args...).Return(ldapMock.returns...)
}
ldapConfig := lconfig
+5 -5
View File
@@ -1431,8 +1431,8 @@ func TestUpdateUser(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
lm := &mocks.Client{}
for _, mock := range tt.ldapMocks {
lm.On(mock.funcName, mock.args...).Return(mock.returns...)
for _, ldapMock := range tt.ldapMocks {
lm.On(ldapMock.funcName, ldapMock.args...).Return(ldapMock.returns...)
}
ldapConfig := lconfig
@@ -1659,7 +1659,7 @@ func TestUsersEnabledState(t *testing.T) {
returns: []interface{}{
nil,
&ldap.Error{
Err: fmt.Errorf("Very Problematic Problems"),
Err: fmt.Errorf("very problematic problems"),
},
},
},
@@ -1669,8 +1669,8 @@ func TestUsersEnabledState(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
lm := &mocks.Client{}
for _, mock := range tt.ldapMocks {
lm.On(mock.funcName, mock.args...).Return(mock.returns...)
for _, ldapMock := range tt.ldapMocks {
lm.On(ldapMock.funcName, ldapMock.args...).Return(ldapMock.returns...)
}
ldapConfig := lconfig