IntegrationTestAttributeDetection.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\user_ldap\tests\Integration\Lib;
  25. use OCA\User_LDAP\Group_LDAP;
  26. use OCA\User_LDAP\GroupPluginManager;
  27. use OCA\User_LDAP\Mapping\GroupMapping;
  28. use OCA\User_LDAP\Mapping\UserMapping;
  29. use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
  30. use OCA\User_LDAP\User\DeletedUsersIndex;
  31. use OCA\User_LDAP\User_LDAP;
  32. use OCA\User_LDAP\UserPluginManager;
  33. use OCP\IConfig;
  34. use Psr\Log\LoggerInterface;
  35. require_once __DIR__ . '/../Bootstrap.php';
  36. class IntegrationTestAttributeDetection extends AbstractIntegrationTest {
  37. public function init() {
  38. require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
  39. require(__DIR__ . '/../setup-scripts/createExplicitGroups.php');
  40. parent::init();
  41. $this->connection->setConfiguration(['ldapGroupFilter' => 'objectClass=groupOfNames']);
  42. $this->connection->setConfiguration(['ldapGroupMemberAssocAttr' => 'member']);
  43. $userMapper = new UserMapping(\OC::$server->getDatabaseConnection());
  44. $userMapper->clear();
  45. $this->access->setUserMapper($userMapper);
  46. $groupMapper = new GroupMapping(\OC::$server->getDatabaseConnection());
  47. $groupMapper->clear();
  48. $this->access->setGroupMapper($groupMapper);
  49. $userBackend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->get(UserPluginManager::class), \OC::$server->get(LoggerInterface::class), \OC::$server->get(DeletedUsersIndex::class));
  50. $userManager = \OC::$server->getUserManager();
  51. $userManager->clearBackends();
  52. $userManager->registerBackend($userBackend);
  53. $groupBackend = new Group_LDAP($this->access, \OC::$server->query(GroupPluginManager::class), \OC::$server->get(IConfig::class));
  54. $groupManger = \OC::$server->getGroupManager();
  55. $groupManger->clearBackends();
  56. $groupManger->addBackend($groupBackend);
  57. }
  58. protected function caseNativeUUIDAttributeUsers() {
  59. // trigger importing of users which also triggers UUID attribute detection
  60. \OC::$server->getUserManager()->search('', 5, 0);
  61. return $this->connection->ldapUuidUserAttribute === 'entryuuid';
  62. }
  63. protected function caseNativeUUIDAttributeGroups() {
  64. // essentially the same as 'caseNativeUUIDAttributeUsers', code paths
  65. // are similar, but we take no chances.
  66. // trigger importing of users which also triggers UUID attribute detection
  67. \OC::$server->getGroupManager()->search('', 5, 0);
  68. return $this->connection->ldapUuidGroupAttribute === 'entryuuid';
  69. }
  70. }
  71. /** @var string $host */
  72. /** @var int $port */
  73. /** @var string $adn */
  74. /** @var string $apwd */
  75. /** @var string $bdn */
  76. $test = new IntegrationTestAttributeDetection($host, $port, $adn, $apwd, $bdn);
  77. $test->init();
  78. $test->run();