IntegrationTestUserDisplayName.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 Joas Schilling <coding@schilljs.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\User_LDAP\Tests\Integration\Lib\User;
  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 IntegrationTestUserDisplayName 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. /**
  60. * tests whether a display name consisting of two parts is created correctly
  61. *
  62. * @return bool
  63. */
  64. protected function case1() {
  65. $username = 'alice1337';
  66. $dn = 'uid=alice,ou=Users,' . $this->base;
  67. $this->prepareUser($dn, $username);
  68. $displayName = \OC::$server->getUserManager()->get($username)->getDisplayName();
  69. return str_contains($displayName, '(Alice@example.com)');
  70. }
  71. /**
  72. * tests whether a display name consisting of one part is created correctly
  73. *
  74. * @return bool
  75. */
  76. protected function case2() {
  77. $this->connection->setConfiguration([
  78. 'ldapUserDisplayName2' => '',
  79. ]);
  80. $username = 'boris23421';
  81. $dn = 'uid=boris,ou=Users,' . $this->base;
  82. $this->prepareUser($dn, $username);
  83. $displayName = \OC::$server->getUserManager()->get($username)->getDisplayName();
  84. return !str_contains($displayName, '(Boris@example.com)');
  85. }
  86. /**
  87. * sets up the LDAP configuration to be used for the test
  88. */
  89. protected function initConnection() {
  90. parent::initConnection();
  91. $this->connection->setConfiguration([
  92. 'ldapUserDisplayName' => 'displayName',
  93. 'ldapUserDisplayName2' => 'mail',
  94. ]);
  95. }
  96. }
  97. /** @var string $host */
  98. /** @var int $port */
  99. /** @var string $adn */
  100. /** @var string $apwd */
  101. /** @var string $bdn */
  102. $test = new IntegrationTestUserDisplayName($host, $port, $adn, $apwd, $bdn);
  103. $test->init();
  104. $test->run();