Skip to content

Commit

Permalink
Added search SizeLimit support
Browse files Browse the repository at this point in the history
  • Loading branch information
ned committed Jun 2, 2015
1 parent 469fe5a commit 4237472
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
10 changes: 5 additions & 5 deletions server_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ func HandleSearchRequest(req *ber.Packet, controls *[]Control, messageID uint64,

for i, entry := range searchResp.Entries {
if server.EnforceLDAP {
// size limit
if searchReq.SizeLimit > 0 && i >= searchReq.SizeLimit {
break
}

// filter
keep, resultCode := ServerApplyFilter(filterPacket, entry)
if resultCode != LDAPResultSuccess {
Expand All @@ -77,6 +72,11 @@ func HandleSearchRequest(req *ber.Packet, controls *[]Control, messageID uint64,
}
}

// size limit
if searchReq.SizeLimit > 0 && i >= searchReq.SizeLimit {
break
}

// attributes
if len(searchReq.Attributes) > 1 || (len(searchReq.Attributes) == 1 && len(searchReq.Attributes[0]) > 0) {
entry, err = filterAttributes(entry, searchReq.Attributes)
Expand Down
36 changes: 33 additions & 3 deletions server_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,23 @@ func TestSearchSizelimit(t *testing.T) {

go func() {
cmd := exec.Command("ldapsearch", "-H", ldapURL, "-x",
"-b", serverBaseDN, "-D", "cn=testy,"+serverBaseDN, "-w", "iLike2test", "-z", "9") // effectively no limit for this test
"-b", serverBaseDN, "-D", "cn=testy,"+serverBaseDN, "-w", "iLike2test") // no limit for this test
out, _ := cmd.CombinedOutput()
if !strings.Contains(string(out), "result: 0 Success") {
t.Errorf("ldapsearch failed: %v", string(out))
}
if !strings.Contains(string(out), "numEntries: 3") {
t.Errorf("ldapsearch sizelimit failed - not enough entries: %v", string(out))
t.Errorf("ldapsearch sizelimit unlimited failed - not enough entries: %v", string(out))
}

cmd = exec.Command("ldapsearch", "-H", ldapURL, "-x",
"-b", serverBaseDN, "-D", "cn=testy,"+serverBaseDN, "-w", "iLike2test", "-z", "9") // effectively no limit for this test
out, _ = cmd.CombinedOutput()
if !strings.Contains(string(out), "result: 0 Success") {
t.Errorf("ldapsearch failed: %v", string(out))
}
if !strings.Contains(string(out), "numEntries: 3") {
t.Errorf("ldapsearch sizelimit 9 failed - not enough entries: %v", string(out))
}

cmd = exec.Command("ldapsearch", "-H", ldapURL, "-x",
Expand All @@ -82,7 +92,27 @@ func TestSearchSizelimit(t *testing.T) {
t.Errorf("ldapsearch failed: %v", string(out))
}
if !strings.Contains(string(out), "numEntries: 2") {
t.Errorf("ldapsearch sizelimit failed - too many entries: %v", string(out))
t.Errorf("ldapsearch sizelimit 2 failed - too many entries: %v", string(out))
}

cmd = exec.Command("ldapsearch", "-H", ldapURL, "-x",
"-b", serverBaseDN, "-D", "cn=testy,"+serverBaseDN, "-w", "iLike2test", "-z", "1")
out, _ = cmd.CombinedOutput()
if !strings.Contains(string(out), "result: 0 Success") {
t.Errorf("ldapsearch failed: %v", string(out))
}
if !strings.Contains(string(out), "numEntries: 1") {
t.Errorf("ldapsearch sizelimit 1 failed - too many entries: %v", string(out))
}

cmd = exec.Command("ldapsearch", "-H", ldapURL, "-x",
"-b", serverBaseDN, "-D", "cn=testy,"+serverBaseDN, "-w", "iLike2test", "-z", "0")
out, _ = cmd.CombinedOutput()
if !strings.Contains(string(out), "result: 0 Success") {
t.Errorf("ldapsearch failed: %v", string(out))
}
if !strings.Contains(string(out), "numEntries: 3") {
t.Errorf("ldapsearch sizelimit 0 failed - wrong number of entries: %v", string(out))
}
done <- true
}()
Expand Down
2 changes: 1 addition & 1 deletion server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func TestSearchStats(t *testing.T) {

stats := s.GetStats()
log.Println(stats)
if stats.Conns != 2 || stats.Binds != 1 {
if stats.Conns != 1 || stats.Binds != 1 {
t.Errorf("Stats data missing or incorrect: %v", w.buffer.String())
}
quit <- true
Expand Down

0 comments on commit 4237472

Please sign in to comment.