OriginalCanonTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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-2008 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. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../TestHelper.php';
  26. /**
  27. * Zend_Ldap
  28. */
  29. require_once 'Zend/Ldap.php';
  30. /**
  31. * @category Zend
  32. * @package Zend_Ldap
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Ldap_OriginalCanonTest extends PHPUnit_Framework_TestCase
  38. {
  39. protected $_options = null;
  40. protected $_principalName = TESTS_ZEND_LDAP_PRINCIPAL_NAME;
  41. protected $_names = array();
  42. public function setUp()
  43. {
  44. $this->_options = array(
  45. 'host' => TESTS_ZEND_LDAP_HOST,
  46. 'username' => TESTS_ZEND_LDAP_USERNAME,
  47. 'password' => TESTS_ZEND_LDAP_PASSWORD,
  48. 'baseDn' => TESTS_ZEND_LDAP_BASE_DN,
  49. );
  50. if (defined('TESTS_ZEND_LDAP_PORT') && TESTS_ZEND_LDAP_PORT != 389)
  51. $this->_options['port'] = TESTS_ZEND_LDAP_PORT;
  52. if (defined('TESTS_ZEND_LDAP_USE_SSL'))
  53. $this->_options['useSsl'] = TESTS_ZEND_LDAP_USE_SSL;
  54. if (defined('TESTS_ZEND_LDAP_BIND_REQUIRES_DN'))
  55. $this->_options['bindRequiresDn'] = TESTS_ZEND_LDAP_BIND_REQUIRES_DN;
  56. if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME'))
  57. $this->_options['accountDomainName'] = TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME;
  58. if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT'))
  59. $this->_options['accountDomainNameShort'] = TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT;
  60. if (defined('TESTS_ZEND_LDAP_ALT_USERNAME')) {
  61. $this->_names[Zend_Ldap::ACCTNAME_FORM_USERNAME] = TESTS_ZEND_LDAP_ALT_USERNAME;
  62. if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME')) {
  63. $this->_names[Zend_Ldap::ACCTNAME_FORM_PRINCIPAL] =
  64. TESTS_ZEND_LDAP_ALT_USERNAME . '@' . TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME;
  65. }
  66. if (defined('TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT')) {
  67. $this->_names[Zend_Ldap::ACCTNAME_FORM_BACKSLASH] =
  68. TESTS_ZEND_LDAP_ACCOUNT_DOMAIN_NAME_SHORT . '\\' . TESTS_ZEND_LDAP_ALT_USERNAME;
  69. }
  70. }
  71. }
  72. public function testPlainCanon()
  73. {
  74. $ldap = new Zend_Ldap($this->_options);
  75. /* This test tries to canonicalize each name (uname, uname@example.com,
  76. * EXAMPLE\uname) to each of the 3 forms (username, principal and backslash)
  77. * for a total of canonicalizations.
  78. */
  79. foreach ($this->_names as $_form => $name) {
  80. foreach ($this->_names as $form => $_name) {
  81. $ret = $ldap->getCanonicalAccountName($name, $form);
  82. $this->assertTrue($ret === $this->_names[$form]);
  83. }
  84. }
  85. }
  86. public function testInvalidAccountCanon()
  87. {
  88. $ldap = new Zend_Ldap($this->_options);
  89. try {
  90. $ldap->bind('invalid', 'invalid');
  91. } catch (Zend_Ldap_Exception $zle) {
  92. $msg = $zle->getMessage();
  93. $this->assertTrue(strstr($msg, 'Invalid credentials') || strstr($msg, 'No such object'));
  94. }
  95. }
  96. public function testDnCanon()
  97. {
  98. $ldap = new Zend_Ldap($this->_options);
  99. $name = $ldap->getCanonicalAccountName(TESTS_ZEND_LDAP_ALT_DN, Zend_Ldap::ACCTNAME_FORM_DN);
  100. }
  101. public function testMismatchDomainBind()
  102. {
  103. $ldap = new Zend_Ldap($this->_options);
  104. try {
  105. $ldap->bind('BOGUS\\doesntmatter', 'doesntmatter');
  106. } catch (Zend_Ldap_Exception $zle) {
  107. $this->assertTrue($zle->getCode() == Zend_Ldap_Exception::LDAP_X_DOMAIN_MISMATCH);
  108. }
  109. }
  110. public function testBindCanon()
  111. {
  112. /**
  113. * @todo test accountCanonicalForm option
  114. */
  115. }
  116. }