mirror of
https://github.com/netauth/ldap.git
synced 2026-11-03 11:43:44 -06:00
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package ldap
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/ps78674/goldap/message"
|
|
)
|
|
|
|
func testServer() *server {
|
|
return &server{
|
|
nc: []string{"dc=netauth", "dc=example", "dc=com"},
|
|
}
|
|
}
|
|
|
|
func TestEntityIDFromDN(t *testing.T) {
|
|
s := testServer()
|
|
|
|
valid := []struct {
|
|
dn string
|
|
id string
|
|
}{
|
|
{"uid=jsmith,ou=entities,dc=netauth,dc=example,dc=com", "jsmith"},
|
|
{"uid=jsmith, ou=entities, dc=netauth, dc=example, dc=com", "jsmith"},
|
|
}
|
|
for _, tc := range valid {
|
|
id, err := s.entityIDFromDN(message.LDAPDN(tc.dn))
|
|
if err != nil {
|
|
t.Errorf("%q: unexpected error %q", tc.dn, err)
|
|
continue
|
|
}
|
|
if id != tc.id {
|
|
t.Errorf("%q: got id %q, want %q", tc.dn, id, tc.id)
|
|
}
|
|
}
|
|
|
|
invalid := []string{
|
|
"",
|
|
"uid=jsmith",
|
|
"cn=jsmith,ou=entities,dc=netauth,dc=example,dc=com",
|
|
"uid=jsmith,ou=groups,dc=netauth,dc=example,dc=com",
|
|
"uid=jsmith,ou=entities,dc=netauth",
|
|
"uid=jsmith,ou=entities,dc=netauth,dc=example,dc=com,dc=extra",
|
|
"uid=jsmith,ou=entities,dc=netauth,dc=other,dc=com",
|
|
}
|
|
for _, dn := range invalid {
|
|
if id, err := s.entityIDFromDN(message.LDAPDN(dn)); err == nil {
|
|
t.Errorf("%q: expected an error, got id %q", dn, id)
|
|
}
|
|
}
|
|
}
|