Skip to content

Commit 1c8daf8

Browse files
committed
add test
1 parent 3b1e8a4 commit 1c8daf8

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

providers/directory/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ func sidToBytes(sid string) ([]byte, error) {
584584
for i, part := range parts[2:] {
585585
val, valErr := strconv.ParseUint(part, 10, 32)
586586
if valErr != nil {
587-
return nil, fmt.Errorf("invalid uint value '%v' at position: %v", part, i)
587+
return nil, fmt.Errorf("invalid uint value '%v' at position: %v", part, i+2)
588588
}
589589
b := make([]byte, 4)
590590
binary.LittleEndian.PutUint32(b, uint32(val))

providers/directory/search_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,36 @@ attributeTypes: ( 1.2.3.4.5.6.7.8 NAME 'objectSid' DESC 'objectSid' EQUALITY act
341341
require.Equal(t, "ldap: filter syntax error: invalid SID 'S-1-300-21-1234567890-1234567890-1234567890-1001': IdentifierAuthority value '300' out of byte range (0-255) at position: 1", log.Entries[1].Message)
342342
},
343343
},
344+
{
345+
name: "ldap filter objectSid using AD style wrong format",
346+
input: `{ "files": [ "./users.ldif" ] }`,
347+
reader: &dynamictest.Reader{Data: map[string]*dynamic.Config{
348+
"file:/users.ldif": {Raw: []byte(`
349+
dn:
350+
namingContexts: dc=example_domain_name
351+
subschemaSubentry: cn=schema
352+
353+
dn: cn=schema
354+
objectClass: top
355+
objectClass: subschema
356+
attributeTypes: ( 1.2.3.4.5.6.7.8 NAME 'objectSid' DESC 'objectSid' EQUALITY activeDirectoryObjectSidMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
357+
`)},
358+
}},
359+
test: func(t *testing.T, h ldap.Handler, log *test.Hook, err error) {
360+
require.NoError(t, err)
361+
362+
rr := ldaptest.NewRecorder()
363+
h.ServeLDAP(rr, ldaptest.NewRequest(0, &ldap.SearchRequest{
364+
Scope: ldap.ScopeWholeSubtree,
365+
Filter: fmt.Sprintf("(objectSid=S-1-5-21-foo-1234567890-1234567890-1001)"),
366+
}))
367+
res := rr.Message.(*ldap.SearchResponse)
368+
369+
require.Len(t, res.Results, 0)
370+
require.Len(t, log.Entries, 2)
371+
require.Equal(t, "ldap: filter syntax error: invalid SID 'S-1-5-21-foo-1234567890-1234567890-1001': invalid uint value 'foo' at position: 3", log.Entries[1].Message)
372+
},
373+
},
344374
}
345375

346376
for _, tc := range testcases {

0 commit comments

Comments
 (0)