OriginalCanonTest.php 4.5 KB

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