ConfigurationTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\User_LDAP\Tests;
  24. class ConfigurationTest extends \Test\TestCase {
  25. public function configurationDataProvider() {
  26. $inputWithDN = array(
  27. 'cn=someUsers,dc=example,dc=org',
  28. ' ',
  29. ' cn=moreUsers,dc=example,dc=org '
  30. );
  31. $expectWithDN = array(
  32. 'cn=someUsers,dc=example,dc=org',
  33. 'cn=moreUsers,dc=example,dc=org'
  34. );
  35. $inputNames = array(
  36. ' uid ',
  37. 'cn ',
  38. ' ',
  39. '',
  40. ' whats my name',
  41. ' '
  42. );
  43. $expectedNames = array('uid', 'cn', 'whats my name');
  44. $inputString = ' alea iacta est ';
  45. $expectedString = 'alea iacta est';
  46. $inputHomeFolder = array(
  47. ' homeDirectory ',
  48. ' attr:homeDirectory ',
  49. ' '
  50. );
  51. $expectedHomeFolder = array(
  52. 'attr:homeDirectory', 'attr:homeDirectory', ''
  53. );
  54. $password = ' such a passw0rd ';
  55. return array(
  56. 'set general base' => array('ldapBase', $inputWithDN, $expectWithDN),
  57. 'set user base' => array('ldapBaseUsers', $inputWithDN, $expectWithDN),
  58. 'set group base' => array('ldapBaseGroups', $inputWithDN, $expectWithDN),
  59. 'set search attributes users' => array('ldapAttributesForUserSearch', $inputNames, $expectedNames),
  60. 'set search attributes groups' => array('ldapAttributesForGroupSearch', $inputNames, $expectedNames),
  61. 'set user filter objectclasses' => array('ldapUserFilterObjectclass', $inputNames, $expectedNames),
  62. 'set user filter groups' => array('ldapUserFilterGroups', $inputNames, $expectedNames),
  63. 'set group filter objectclasses' => array('ldapGroupFilterObjectclass', $inputNames, $expectedNames),
  64. 'set group filter groups' => array('ldapGroupFilterGroups', $inputNames, $expectedNames),
  65. 'set login filter attributes' => array('ldapLoginFilterAttributes', $inputNames, $expectedNames),
  66. 'set agent password' => array('ldapAgentPassword', $password, $password),
  67. 'set home folder, variant 1' => array('homeFolderNamingRule', $inputHomeFolder[0], $expectedHomeFolder[0]),
  68. 'set home folder, variant 2' => array('homeFolderNamingRule', $inputHomeFolder[1], $expectedHomeFolder[1]),
  69. 'set home folder, empty' => array('homeFolderNamingRule', $inputHomeFolder[2], $expectedHomeFolder[2]),
  70. // default behaviour, one case is enough, special needs must be tested
  71. // individually
  72. 'set string value' => array('ldapHost', $inputString, $expectedString),
  73. );
  74. }
  75. /**
  76. * @dataProvider configurationDataProvider
  77. */
  78. public function testSetValue($key, $input, $expected) {
  79. $configuration = new \OCA\User_LDAP\Configuration('t01', false);
  80. $configuration->setConfiguration([$key => $input]);
  81. $this->assertSame($configuration->$key, $expected);
  82. }
  83. }