Skip to content

Commit 931946f

Browse files
committed
avoid logging of "Partial search results returned: Sizelimit exceeded at"
LDAP servers respond with that even if a limit was passed with the request. Having this statement logged causes a lot of confusion. Signed-off-by: Arthur Schiwon <[email protected]>
1 parent 9ea6573 commit 931946f

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

apps/user_ldap/lib/LDAP.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,16 @@ public function read($link, $baseDN, $filter, $attr) {
191191
* @return mixed
192192
*/
193193
public function search($link, $baseDN, $filter, $attr, $attrsOnly = 0, $limit = 0) {
194-
return $this->invokeLDAPMethod('search', $link, $baseDN, $filter, $attr, $attrsOnly, $limit);
194+
$oldHandler = set_error_handler(function($no, $message, $file, $line) use (&$oldHandler) {
195+
if(strpos($message, 'Partial search results returned: Sizelimit exceeded') !== false) {
196+
return true;
197+
}
198+
$oldHandler($no, $message, $file, $line);
199+
return true;
200+
});
201+
$result = $this->invokeLDAPMethod('search', $link, $baseDN, $filter, $attr, $attrsOnly, $limit);
202+
restore_error_handler();
203+
return $result;
195204
}
196205

197206
/**

apps/user_ldap/tests/LDAPTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,46 @@ public function setUp() {
3737
->getMock();
3838
}
3939

40+
public function errorProvider() {
41+
return [
42+
[
43+
'ldap_search(): Partial search results returned: Sizelimit exceeded at /srv/http/nextcloud/master/apps/user_ldap/lib/LDAP.php#292',
44+
false
45+
],
46+
[
47+
'Some other error', true
48+
]
49+
];
50+
}
51+
52+
/**
53+
* @param string $errorMessage
54+
* @param bool $passThrough
55+
* @dataProvider errorProvider
56+
*/
57+
public function testSearchWithErrorHandler(string $errorMessage, bool $passThrough) {
58+
59+
$wasErrorHandlerCalled = false;
60+
$errorHandler = function($number, $message, $file, $line) use (&$wasErrorHandlerCalled) {
61+
$wasErrorHandlerCalled = true;
62+
};
63+
64+
set_error_handler($errorHandler);
65+
66+
$this->ldap
67+
->expects($this->once())
68+
->method('invokeLDAPMethod')
69+
->with('search', $this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything())
70+
->willReturnCallback(function() use($errorMessage) {
71+
trigger_error($errorMessage);
72+
});
73+
74+
$this->ldap->search('pseudo-resource', 'base', 'filter', []);
75+
$this->assertSame($wasErrorHandlerCalled, $passThrough);
76+
77+
restore_error_handler();
78+
}
79+
4080
public function testModReplace() {
4181
$link = $this->createMock(LDAP::class);
4282
$userDN = 'CN=user';

0 commit comments

Comments
 (0)