ConfigurationTest.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 Roeland Jago Douma <roeland@famdouma.nl>
  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;
  26. use OCA\User_LDAP\Configuration;
  27. class ConfigurationTest extends \Test\TestCase {
  28. /** @var Configuration */
  29. protected $configuration;
  30. protected function setUp(): void {
  31. parent::setUp();
  32. $this->configuration = new Configuration('t01', false);
  33. }
  34. public function configurationDataProvider() {
  35. $inputWithDN = [
  36. 'cn=someUsers,dc=example,dc=org',
  37. ' ',
  38. ' cn=moreUsers,dc=example,dc=org '
  39. ];
  40. $expectWithDN = [
  41. 'cn=someUsers,dc=example,dc=org',
  42. 'cn=moreUsers,dc=example,dc=org'
  43. ];
  44. $inputNames = [
  45. ' uid ',
  46. 'cn ',
  47. ' ',
  48. '',
  49. ' whats my name',
  50. ' '
  51. ];
  52. $expectedNames = ['uid', 'cn', 'whats my name'];
  53. $inputString = ' alea iacta est ';
  54. $expectedString = 'alea iacta est';
  55. $inputHomeFolder = [
  56. ' homeDirectory ',
  57. ' attr:homeDirectory ',
  58. ' '
  59. ];
  60. $expectedHomeFolder = [
  61. 'attr:homeDirectory', 'attr:homeDirectory', ''
  62. ];
  63. $password = ' such a passw0rd ';
  64. return [
  65. 'set general base' => ['ldapBase', $inputWithDN, $expectWithDN],
  66. 'set user base' => ['ldapBaseUsers', $inputWithDN, $expectWithDN],
  67. 'set group base' => ['ldapBaseGroups', $inputWithDN, $expectWithDN],
  68. 'set search attributes users' => ['ldapAttributesForUserSearch', $inputNames, $expectedNames],
  69. 'set search attributes groups' => ['ldapAttributesForGroupSearch', $inputNames, $expectedNames],
  70. 'set user filter objectclasses' => ['ldapUserFilterObjectclass', $inputNames, $expectedNames],
  71. 'set user filter groups' => ['ldapUserFilterGroups', $inputNames, $expectedNames],
  72. 'set group filter objectclasses' => ['ldapGroupFilterObjectclass', $inputNames, $expectedNames],
  73. 'set group filter groups' => ['ldapGroupFilterGroups', $inputNames, $expectedNames],
  74. 'set login filter attributes' => ['ldapLoginFilterAttributes', $inputNames, $expectedNames],
  75. 'set agent password' => ['ldapAgentPassword', $password, $password],
  76. 'set home folder, variant 1' => ['homeFolderNamingRule', $inputHomeFolder[0], $expectedHomeFolder[0]],
  77. 'set home folder, variant 2' => ['homeFolderNamingRule', $inputHomeFolder[1], $expectedHomeFolder[1]],
  78. 'set home folder, empty' => ['homeFolderNamingRule', $inputHomeFolder[2], $expectedHomeFolder[2]],
  79. // default behaviour, one case is enough, special needs must be tested
  80. // individually
  81. 'set string value' => ['ldapHost', $inputString, $expectedString],
  82. 'set avatar rule, default' => ['ldapUserAvatarRule', 'default', 'default'],
  83. 'set avatar rule, none' => ['ldapUserAvatarRule', 'none', 'none'],
  84. 'set avatar rule, data attribute' => ['ldapUserAvatarRule', 'data:jpegPhoto', 'data:jpegPhoto'],
  85. 'set external storage home attribute' => ['ldapExtStorageHomeAttribute', 'homePath', 'homePath'],
  86. ];
  87. }
  88. /**
  89. * @dataProvider configurationDataProvider
  90. */
  91. public function testSetValue($key, $input, $expected) {
  92. $this->configuration->setConfiguration([$key => $input]);
  93. $this->assertSame($this->configuration->$key, $expected);
  94. }
  95. public function avatarRuleValueProvider() {
  96. return [
  97. ['none', []],
  98. ['data:selfie', ['selfie']],
  99. ['data:sELFie', ['selfie']],
  100. ['data:', ['jpegphoto', 'thumbnailphoto']],
  101. ['default', ['jpegphoto', 'thumbnailphoto']],
  102. ['invalid#', ['jpegphoto', 'thumbnailphoto']],
  103. ];
  104. }
  105. /**
  106. * @dataProvider avatarRuleValueProvider
  107. */
  108. public function testGetAvatarAttributes($setting, $expected) {
  109. $this->configuration->setConfiguration(['ldapUserAvatarRule' => $setting]);
  110. $this->assertSame($expected, $this->configuration->getAvatarAttributes());
  111. }
  112. /**
  113. * @dataProvider avatarRuleValueProvider
  114. */
  115. public function testResolveRule($setting, $expected) {
  116. $this->configuration->setConfiguration(['ldapUserAvatarRule' => $setting]);
  117. // so far the only thing that can get resolved :)
  118. $this->assertSame($expected, $this->configuration->resolveRule('avatar'));
  119. }
  120. }