IntegrationTestUserDisplayName.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_LDAP;
  29. use OCA\User_LDAP\UserPluginManager;
  30. require_once __DIR__ . '/../../Bootstrap.php';
  31. class IntegrationTestUserDisplayName extends AbstractIntegrationTest {
  32. /** @var UserMapping */
  33. protected $mapping;
  34. /**
  35. * prepares the LDAP environment and sets up a test configuration for
  36. * the LDAP backend.
  37. */
  38. public function init() {
  39. require(__DIR__ . '/../../setup-scripts/createExplicitUsers.php');
  40. parent::init();
  41. $this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
  42. $this->mapping->clear();
  43. $this->access->setUserMapper($this->mapping);
  44. $userBackend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), \OC::$server->query(UserPluginManager::class));
  45. \OC_User::useBackend($userBackend);
  46. }
  47. /**
  48. * adds a map entry for the user, so we know the username
  49. *
  50. * @param $dn
  51. * @param $username
  52. */
  53. private function prepareUser($dn, $username) {
  54. // assigns our self-picked oc username to the dn
  55. $this->mapping->map($dn, $username, 'fakeUUID-' . $username);
  56. }
  57. /**
  58. * tests whether a display name consisting of two parts is created correctly
  59. *
  60. * @return bool
  61. */
  62. protected function case1() {
  63. $username = 'alice1337';
  64. $dn = 'uid=alice,ou=Users,' . $this->base;
  65. $this->prepareUser($dn, $username);
  66. $displayName = \OC::$server->getUserManager()->get($username)->getDisplayName();
  67. return strpos($displayName, '(Alice@example.com)') !== false;
  68. }
  69. /**
  70. * tests whether a display name consisting of one part is created correctly
  71. *
  72. * @return bool
  73. */
  74. protected function case2() {
  75. $this->connection->setConfiguration([
  76. 'ldapUserDisplayName2' => '',
  77. ]);
  78. $username = 'boris23421';
  79. $dn = 'uid=boris,ou=Users,' . $this->base;
  80. $this->prepareUser($dn, $username);
  81. $displayName = \OC::$server->getUserManager()->get($username)->getDisplayName();
  82. return strpos($displayName, '(Boris@example.com)') === false;
  83. }
  84. /**
  85. * sets up the LDAP configuration to be used for the test
  86. */
  87. protected function initConnection() {
  88. parent::initConnection();
  89. $this->connection->setConfiguration([
  90. 'ldapUserDisplayName' => 'displayName',
  91. 'ldapUserDisplayName2' => 'mail',
  92. ]);
  93. }
  94. }
  95. /** @var string $host */
  96. /** @var int $port */
  97. /** @var string $adn */
  98. /** @var string $apwd */
  99. /** @var string $bdn */
  100. $test = new IntegrationTestUserDisplayName($host, $port, $adn, $apwd, $bdn);
  101. $test->init();
  102. $test->run();