Merge pull request #13621 from stonezdj/201127_fail_to_add_ldap_group

Lowercase the LDAP DN in UnderBaseDN
This commit is contained in:
stonezdj(Daojun Zhang) 2020-11-27 11:45:07 +08:00 committed by GitHub
commit dec12308a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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

@ -615,6 +615,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) {