IntegrationTestUserCleanUp.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  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, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\User_LDAP\Tests\Integration\Lib\User;
  25. use OCA\User_LDAP\Jobs\CleanUp;
  26. use OCA\User_LDAP\Mapping\UserMapping;
  27. use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
  28. use OCA\User_LDAP\User\DeletedUsersIndex;
  29. use OCA\User_LDAP\User_LDAP;
  30. use OCA\User_LDAP\UserPluginManager;
  31. use Psr\Log\LoggerInterface;
  32. require_once __DIR__ . '/../../Bootstrap.php';
  33. class IntegrationTestUserCleanUp extends AbstractIntegrationTest {
  34. /** @var UserMapping */
  35. protected $mapping;
  36. /**
  37. * prepares the LDAP environment and sets up a test configuration for
  38. * the LDAP backend.
  39. */
  40. public function init() {
  41. require(__DIR__ . '/../../setup-scripts/createExplicitUsers.php');
  42. parent::init();
  43. $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
  44. $this->mapping->clear();
  45. $this->access->setUserMapper($this->mapping);
  46. $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));
  47. \OC_User::useBackend($userBackend);
  48. }
  49. /**
  50. * adds a map entry for the user, so we know the username
  51. *
  52. * @param $dn
  53. * @param $username
  54. */
  55. private function prepareUser($dn, $username) {
  56. // assigns our self-picked oc username to the dn
  57. $this->mapping->map($dn, $username, 'fakeUUID-' . $username);
  58. }
  59. private function deleteUserFromLDAP($dn) {
  60. $cr = $this->connection->getConnectionResource();
  61. ldap_delete($cr, $dn);
  62. }
  63. /**
  64. * tests whether a display name consisting of two parts is created correctly
  65. *
  66. * @return bool
  67. */
  68. protected function case1() {
  69. $username = 'alice1337';
  70. $dn = 'uid=alice,ou=Users,' . $this->base;
  71. $this->prepareUser($dn, $username);
  72. $this->deleteUserFromLDAP($dn);
  73. $job = new CleanUp();
  74. $job->run([]);
  75. // user instance must not be requested from global user manager, before
  76. // it is deleted from the LDAP server. The instance will be returned
  77. // from cache and may false-positively confirm the correctness.
  78. $user = \OC::$server->getUserManager()->get($username);
  79. if ($user === null) {
  80. return false;
  81. }
  82. $user->delete();
  83. return \OC::$server->getUserManager()->get($username) === null;
  84. }
  85. }
  86. /** @var string $host */
  87. /** @var int $port */
  88. /** @var string $adn */
  89. /** @var string $apwd */
  90. /** @var string $bdn */
  91. $test = new IntegrationTestUserCleanUp($host, $port, $adn, $apwd, $bdn);
  92. $test->init();
  93. $test->run();