Skip to content

Commit

Permalink
return non-empty value if trimming is not required
Browse files Browse the repository at this point in the history
Signed-off-by: pgbv <[email protected]>
  • Loading branch information
pgbv authored and drakkan committed Aug 21, 2024
1 parent 1513afd commit bbb7149
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions authenticator/ldap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ func TestGetCNFromDN(t *testing.T) {
res = getCNFromDN("cn=test")
assert.Equal(t, "test", res)
res = getCNFromDN("test")
assert.Equal(t, "test", res)
res = getCNFromDN("")
assert.Empty(t, res)
res = getCNFromDN("cn=admin ,ou=users,dc=mylab,dc=local")
assert.Equal(t, "admin", res)
Expand Down
1 change: 1 addition & 0 deletions authenticator/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func getCNFromDN(dn string) string {
if strings.HasPrefix(cn, "cn=") || strings.HasPrefix(cn, "ou=") {
return strings.TrimSpace(cn[3:])
}
return cn
}
return ""
}

0 comments on commit bbb7149

Please sign in to comment.