OriginalCanonTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Ldap
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Zend_Ldap
  24. */
  25. require_once 'Zend/Ldap.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Ldap
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Ldap
  33. */
  34. class Zend_Ldap_OriginalCanonTest extends PHPUnit_Framework_TestCase
  35. {
  36. protected $_options = null;
  37. protected $_principalName = TESTS_ZEND_LDAP_PRINCIPAL_NAME;
  38. protected $_names = array();
  39. public function setUp()
  40. {
  41. $this->_options = array(
  42. 'host' => TESTS_ZEND_LDAP_HOST,
  43. 'username' => TESTS_ZEND_LDAP_USERNAME,
  44. 'password' => TESTS_ZEND_LDAP_PASSWORD,
  45. 'baseDn' => TESTS_ZEND_LDAP_BASE_DN,
  46. );
  47. if (defined('TESTS_ZEND_LDAP_PORT') && TESTS_ZEND_LDAP_PORT != 389)
  48. $this->_options['port'] = TESTS_ZEND_LDAP_PORT;
  49. if (defined('TESTS_ZEND_LDAP_USE_SSL'))
  50. $this->_options['useSsl'] = TESTS_ZEND_LDAP_USE_SSL;
  51. if (defined('TESTS_ZEND_LDAP_BIND_REQUIRES_DN'))
  52. $this->_options['bindRequiresDn'] = TESTS_ZEND_LDAP_BIND_REQUIRES_DN;
  53. if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME'))
  54. $this->_options['accountDomainName'] = TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME;
  55. if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT'))
  56. $this->_options['accountDomainNameShort'] = TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT;
  57. if (defined('TESTS_ZEND_LDAP_ALT_USERNAME')) {
  58. $this->_names[Zend_Ldap::ACCTNAME_FORM_USERNAME] = TESTS_ZEND_LDAP_ALT_USERNAME;
  59. if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME')) {
  60. $this->_names[Zend_Ldap::ACCTNAME_FORM_PRINCIPAL] =
  61. TESTS_ZEND_LDAP_ALT_USERNAME . '@' . TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME;
  62. }
  63. if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT')) {
  64. $this->_names[Zend_Ldap::ACCTNAME_FORM_BACKSLASH] =
  65. TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT . '\\' . TESTS_ZEND_LDAP_ALT_USERNAME;
  66. }
  67. }
  68. }
  69. public function testPlainCanon()
  70. {
  71. $ldap = new Zend_Ldap($this->_options);
  72. /* This test tries to canonicalize each name (uname, uname@example.com,
  73. * EXAMPLE\uname) to each of the 3 forms (username, principal and backslash)
  74. * for a total of canonicalizations.
  75. */
  76. foreach ($this->_names as $_form => $name) {
  77. foreach ($this->_names as $form => $_name) {
  78. $ret = $ldap->getCanonicalAccountName($name, $form);
  79. $this->assertTrue($ret === $this->_names[$form]);
  80. }
  81. }
  82. }
  83. public function testInvalidAccountCanon()
  84. {
  85. $ldap = new Zend_Ldap($this->_options);
  86. try {
  87. $ldap->bind('invalid', 'invalid');
  88. } catch (Zend_Ldap_Exception $zle) {
  89. $msg = $zle->getMessage();
  90. $this->assertTrue(strstr($msg, 'Invalid credentials') || strstr($msg, 'No such object'));
  91. }
  92. }
  93. public function testDnCanon()
  94. {
  95. $ldap = new Zend_Ldap($this->_options);
  96. $name = $ldap->getCanonicalAccountName(TESTS_ZEND_LDAP_ALT_DN, Zend_Ldap::ACCTNAME_FORM_DN);
  97. }
  98. public function testMismatchDomainBind()
  99. {
  100. $ldap = new Zend_Ldap($this->_options);
  101. try {
  102. $ldap->bind('BOGUS\\doesntmatter', 'doesntmatter');
  103. } catch (Zend_Ldap_Exception $zle) {
  104. $this->assertTrue($zle->getCode() == Zend_Ldap_Exception::LDAP_X_DOMAIN_MISMATCH);
  105. }
  106. }
  107. public function testBindCanon()
  108. {
  109. /**
  110. * @todo test accountCanonicalForm option
  111. */
  112. }
  113. }