You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

access.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Arthur Schiwon
  6. * @copyright 2013 Arthur Schiwon blizzz@owncloud.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. namespace OCA\user_ldap\tests;
  23. use \OCA\user_ldap\lib\Access;
  24. use \OCA\user_ldap\lib\Connection;
  25. use \OCA\user_ldap\lib\ILDAPWrapper;
  26. class Test_Access extends \PHPUnit_Framework_TestCase {
  27. private function getConnecterAndLdapMock() {
  28. static $conMethods;
  29. static $accMethods;
  30. if(is_null($conMethods) || is_null($accMethods)) {
  31. $conMethods = get_class_methods('\OCA\user_ldap\lib\Connection');
  32. $accMethods = get_class_methods('\OCA\user_ldap\lib\Access');
  33. }
  34. $lw = $this->getMock('\OCA\user_ldap\lib\ILDAPWrapper');
  35. $connector = $this->getMock('\OCA\user_ldap\lib\Connection',
  36. $conMethods,
  37. array($lw, null, null));
  38. return array($lw, $connector);
  39. }
  40. public function testEscapeFilterPartValidChars() {
  41. list($lw, $con) = $this->getConnecterAndLdapMock();
  42. $access = new Access($con, $lw);
  43. $input = 'okay';
  44. $this->assertTrue($input === $access->escapeFilterPart($input));
  45. }
  46. public function testEscapeFilterPartEscapeWildcard() {
  47. list($lw, $con) = $this->getConnecterAndLdapMock();
  48. $access = new Access($con, $lw);
  49. $input = '*';
  50. $expected = '\\\\*';
  51. $this->assertTrue($expected === $access->escapeFilterPart($input));
  52. }
  53. public function testEscapeFilterPartEscapeWildcard2() {
  54. list($lw, $con) = $this->getConnecterAndLdapMock();
  55. $access = new Access($con, $lw);
  56. $input = 'foo*bar';
  57. $expected = 'foo\\\\*bar';
  58. $this->assertTrue($expected === $access->escapeFilterPart($input));
  59. }
  60. }