Lowercase the LDAP DN in UnderBaseDN

Fixes #13362: Unable to add LDAP group with different letter case in DN

Signed-off-by: stonezdj <stonezdj@gmail.com>
This commit is contained in:
stonezdj 2020-11-27 10:30:19 +08:00
parent d55f55aeb9
commit ca245d3545
2 changed files with 8 additions and 2 deletions

View File

@ -434,11 +434,11 @@ func (session *Session) searchGroup(groupDN, filter, gName, groupNameAttribute s
// UnderBaseDN - check if the childDN is under the baseDN, if the baseDN equals current DN, return true
func UnderBaseDN(baseDN, childDN string) (bool, error) {
base, err := goldap.ParseDN(baseDN)
base, err := goldap.ParseDN(strings.ToLower(baseDN))
if err != nil {
return false, err
}
child, err := goldap.ParseDN(childDN)
child, err := goldap.ParseDN(strings.ToLower(childDN))
if err != nil {
return false, err
}

View File

@ -517,6 +517,12 @@ func TestUnderBaseDN(t *testing.T) {
wantError: true,
want: false,
},
{
name: `should be case-insensitive`,
in: args{"CN=Users,CN=harbor,DC=com", "cn=harbor_group_1,cn=users,cn=harbor,dc=com"},
wantError: false,
want: true,
},
}
for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {