Skip to content

Commit 159d759

Browse files
authored
Merge pull request #12292 from nextcloud/fix/2947/lapse-sizelimit-error
avoid logging of "Partial search results returned: Sizelimit exceeded…"
2 parents d70b010 + deec5a7 commit 159d759

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

apps/user_ldap/lib/LDAP.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,24 @@ public function read($link, $baseDN, $filter, $attr) {
189189
* @param int $attrsOnly
190190
* @param int $limit
191191
* @return mixed
192+
* @throws \Exception
192193
*/
193194
public function search($link, $baseDN, $filter, $attr, $attrsOnly = 0, $limit = 0) {
194-
return $this->invokeLDAPMethod('search', $link, $baseDN, $filter, $attr, $attrsOnly, $limit);
195+
$oldHandler = set_error_handler(function($no, $message, $file, $line) use (&$oldHandler) {
196+
if(strpos($message, 'Partial search results returned: Sizelimit exceeded') !== false) {
197+
return true;
198+
}
199+
$oldHandler($no, $message, $file, $line);
200+
return true;
201+
});
202+
try {
203+
$result = $this->invokeLDAPMethod('search', $link, $baseDN, $filter, $attr, $attrsOnly, $limit);
204+
restore_error_handler();
205+
return $result;
206+
} catch (\Exception $e) {
207+
restore_error_handler();
208+
throw $e;
209+
}
195210
}
196211

197212
/**
@@ -342,6 +357,7 @@ private function processLDAPError($resource) {
342357

343358
/**
344359
* Called after an ldap method is run to act on LDAP error if necessary
360+
* @throw \Exception
345361
*/
346362
private function postFunctionCall() {
347363
if($this->isResource($this->curArgs[0])) {

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)