IntegrationTestAttributeDetection.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 Vinicius Cubas Brand <vinicius@eita.org.br>
  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\Mapping\GroupMapping;
  27. use OCA\User_LDAP\Mapping\UserMapping;
  28. use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
  29. use OCA\User_LDAP\User_LDAP;
  30. require_once __DIR__ . '/../Bootstrap.php';
  31. class IntegrationTestAttributeDetection extends AbstractIntegrationTest {
  32. public function init() {
  33. require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
  34. require(__DIR__ . '/../setup-scripts/createExplicitGroups.php');
  35. parent::init();
  36. $this->connection->setConfiguration(['ldapGroupFilter' => 'objectClass=groupOfNames']);
  37. $this->connection->setConfiguration(['ldapGroupMemberAssocAttr' => 'member']);
  38. $userMapper = new UserMapping(\OC::$server->getDatabaseConnection());
  39. $userMapper->clear();
  40. $this->access->setUserMapper($userMapper);
  41. $groupMapper = new GroupMapping(\OC::$server->getDatabaseConnection());
  42. $groupMapper->clear();
  43. $this->access->setGroupMapper($groupMapper);
  44. $userBackend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query('LDAPUserPluginManager'));
  45. $userManager = \OC::$server->getUserManager();
  46. $userManager->clearBackends();
  47. $userManager->registerBackend($userBackend);
  48. $groupBackend = new Group_LDAP($this->access, \OC::$server->query('LDAPGroupPluginManager'));
  49. $groupManger = \OC::$server->getGroupManager();
  50. $groupManger->clearBackends();
  51. $groupManger->addBackend($groupBackend);
  52. }
  53. protected function caseNativeUUIDAttributeUsers() {
  54. // trigger importing of users which also triggers UUID attribute detection
  55. \OC::$server->getUserManager()->search('', 5, 0);
  56. return $this->connection->ldapUuidUserAttribute === 'entryuuid';
  57. }
  58. protected function caseNativeUUIDAttributeGroups() {
  59. // essentially the same as 'caseNativeUUIDAttributeUsers', code paths
  60. // are similar, but we take no chances.
  61. // trigger importing of users which also triggers UUID attribute detection
  62. \OC::$server->getGroupManager()->search('', 5, 0);
  63. return $this->connection->ldapUuidGroupAttribute === 'entryuuid';
  64. }
  65. }
  66. /** @var string $host */
  67. /** @var int $port */
  68. /** @var string $adn */
  69. /** @var string $apwd */
  70. /** @var string $bdn */
  71. $test = new IntegrationTestAttributeDetection($host, $port, $adn, $apwd, $bdn);
  72. $test->init();
  73. $test->run();