IntegrationTestAttributeDetection.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\user_ldap\tests\Integration\Lib;
  7. use OCA\User_LDAP\Group_LDAP;
  8. use OCA\User_LDAP\GroupPluginManager;
  9. use OCA\User_LDAP\Mapping\GroupMapping;
  10. use OCA\User_LDAP\Mapping\UserMapping;
  11. use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
  12. use OCA\User_LDAP\User\DeletedUsersIndex;
  13. use OCA\User_LDAP\User_LDAP;
  14. use OCA\User_LDAP\UserPluginManager;
  15. use OCP\IConfig;
  16. use Psr\Log\LoggerInterface;
  17. require_once __DIR__ . '/../Bootstrap.php';
  18. class IntegrationTestAttributeDetection extends AbstractIntegrationTest {
  19. public function init() {
  20. require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
  21. require(__DIR__ . '/../setup-scripts/createExplicitGroups.php');
  22. parent::init();
  23. $this->connection->setConfiguration(['ldapGroupFilter' => 'objectClass=groupOfNames']);
  24. $this->connection->setConfiguration(['ldapGroupMemberAssocAttr' => 'member']);
  25. $userMapper = new UserMapping(\OC::$server->getDatabaseConnection());
  26. $userMapper->clear();
  27. $this->access->setUserMapper($userMapper);
  28. $groupMapper = new GroupMapping(\OC::$server->getDatabaseConnection());
  29. $groupMapper->clear();
  30. $this->access->setGroupMapper($groupMapper);
  31. $userBackend = new User_LDAP($this->access, \OC::$server->getNotificationManager(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class));
  32. $userManager = \OC::$server->getUserManager();
  33. $userManager->clearBackends();
  34. $userManager->registerBackend($userBackend);
  35. $groupBackend = new Group_LDAP($this->access, \OC::$server->query(GroupPluginManager::class), \OC::$server->get(IConfig::class));
  36. $groupManger = \OC::$server->getGroupManager();
  37. $groupManger->clearBackends();
  38. $groupManger->addBackend($groupBackend);
  39. }
  40. protected function caseNativeUUIDAttributeUsers() {
  41. // trigger importing of users which also triggers UUID attribute detection
  42. \OC::$server->getUserManager()->search('', 5, 0);
  43. return $this->connection->ldapUuidUserAttribute === 'entryuuid';
  44. }
  45. protected function caseNativeUUIDAttributeGroups() {
  46. // essentially the same as 'caseNativeUUIDAttributeUsers', code paths
  47. // are similar, but we take no chances.
  48. // trigger importing of users which also triggers UUID attribute detection
  49. \OC::$server->getGroupManager()->search('', 5, 0);
  50. return $this->connection->ldapUuidGroupAttribute === 'entryuuid';
  51. }
  52. }
  53. /** @var string $host */
  54. /** @var int $port */
  55. /** @var string $adn */
  56. /** @var string $apwd */
  57. /** @var string $bdn */
  58. $test = new IntegrationTestAttributeDetection($host, $port, $adn, $apwd, $bdn);
  59. $test->init();
  60. $test->run();