IntegrationTestPaging.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\User_LDAP\Tests\Integration\Lib;
  8. use OCA\User_LDAP\Mapping\UserMapping;
  9. use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
  10. use OCA\User_LDAP\User\DeletedUsersIndex;
  11. use OCA\User_LDAP\User_LDAP;
  12. use OCA\User_LDAP\UserPluginManager;
  13. use Psr\Log\LoggerInterface;
  14. require_once __DIR__ . '/../Bootstrap.php';
  15. class IntegrationTestPaging extends AbstractIntegrationTest {
  16. /** @var UserMapping */
  17. protected $mapping;
  18. /** @var User_LDAP */
  19. protected $backend;
  20. /** @var int */
  21. protected $pagingSize = 2;
  22. /**
  23. * prepares the LDAP environment and sets up a test configuration for
  24. * the LDAP backend.
  25. */
  26. public function init() {
  27. require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
  28. parent::init();
  29. $this->backend = new User_LDAP($this->access, \OC::$server->getNotificationManager(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class));
  30. }
  31. public function initConnection() {
  32. parent::initConnection();
  33. $this->connection->setConfiguration([
  34. 'ldapPagingSize' => $this->pagingSize
  35. ]);
  36. }
  37. /**
  38. * fetch first three, afterwards all users
  39. *
  40. * @return bool
  41. */
  42. protected function case1() {
  43. $filter = 'objectclass=inetorgperson';
  44. $attributes = ['cn', 'dn'];
  45. $result = $this->access->searchUsers($filter, $attributes, 4);
  46. // beware, under circumstances, the result set can be larger then
  47. // the specified limit! In this case, if we specify a limit of 3,
  48. // the result will be 4, because the highest possible paging size
  49. // is 2 (as configured).
  50. // But also with more than one search base, the limit can be outpaced.
  51. if (count($result) !== 4) {
  52. return false;
  53. }
  54. $result = $this->access->searchUsers($filter, $attributes);
  55. if (count($result) !== 7) {
  56. return false;
  57. }
  58. return true;
  59. }
  60. }
  61. /** @var string $host */
  62. /** @var int $port */
  63. /** @var string $adn */
  64. /** @var string $apwd */
  65. /** @var string $bdn */
  66. $test = new IntegrationTestPaging($host, $port, $adn, $apwd, $bdn);
  67. $test->init();
  68. $test->run();