SchemaTest.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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-2012 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_OnlineTestCase
  24. */
  25. require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'OnlineTestCase.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Ldap
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2012 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. * @group Zend_Ldap_Node
  34. */
  35. class Zend_Ldap_Node_SchemaTest extends Zend_Ldap_OnlineTestCase
  36. {
  37. /**
  38. * @var Zend_Ldap_Node_Schema
  39. */
  40. private $_schema;
  41. protected function setUp()
  42. {
  43. parent::setUp();
  44. $this->_schema=$this->_getLdap()->getSchema();
  45. }
  46. public function testSchemaNode()
  47. {
  48. $schema=$this->_getLdap()->getSchema();
  49. $this->assertEquals($this->_schema, $schema);
  50. $this->assertSame($this->_schema, $schema);
  51. $serial=serialize($this->_schema);
  52. $schemaUn=unserialize($serial);
  53. $this->assertEquals($this->_schema, $schemaUn);
  54. $this->assertNotSame($this->_schema, $schemaUn);
  55. }
  56. public function testGetters()
  57. {
  58. $this->assertTrue(is_array($this->_schema->getAttributeTypes()));
  59. $this->assertTrue(is_array($this->_schema->getObjectClasses()));
  60. switch ($this->_getLdap()->getRootDse()->getServerType()) {
  61. case Zend_Ldap_Node_RootDse::SERVER_TYPE_ACTIVEDIRECTORY:
  62. break;
  63. case Zend_Ldap_Node_RootDse::SERVER_TYPE_EDIRECTORY:
  64. break;
  65. case Zend_Ldap_Node_RootDse::SERVER_TYPE_OPENLDAP:
  66. $this->assertTrue(is_array($this->_schema->getLdapSyntaxes()));
  67. $this->assertTrue(is_array($this->_schema->getMatchingRules()));
  68. $this->assertTrue(is_array($this->_schema->getMatchingRuleUse()));
  69. break;
  70. }
  71. }
  72. /**
  73. * @expectedException BadMethodCallException
  74. */
  75. public function testSetterWillThrowException()
  76. {
  77. $this->_schema->objectClass='illegal';
  78. }
  79. /**
  80. * @expectedException BadMethodCallException
  81. */
  82. public function testOffsetSetWillThrowException()
  83. {
  84. $this->_schema['objectClass']='illegal';
  85. }
  86. /**
  87. * @expectedException BadMethodCallException
  88. */
  89. public function testUnsetterWillThrowException()
  90. {
  91. unset($this->_schema->objectClass);
  92. }
  93. /**
  94. * @expectedException BadMethodCallException
  95. */
  96. public function testOffsetUnsetWillThrowException()
  97. {
  98. unset($this->_schema['objectClass']);
  99. }
  100. public function testOpenLdapSchema()
  101. {
  102. if ($this->_getLdap()->getRootDse()->getServerType() !==
  103. Zend_Ldap_Node_RootDse::SERVER_TYPE_OPENLDAP) {
  104. $this->markTestSkipped('Test can only be run on an OpenLDAP server');
  105. }
  106. $objectClasses=$this->_schema->getObjectClasses();
  107. $attributeTypes=$this->_schema->getAttributeTypes();
  108. $this->assertArrayHasKey('organizationalUnit', $objectClasses);
  109. $ou=$objectClasses['organizationalUnit'];
  110. $this->assertTrue($ou instanceof Zend_Ldap_Node_Schema_ObjectClass_OpenLdap);
  111. $this->assertEquals('organizationalUnit', $ou->getName());
  112. $this->assertEquals('2.5.6.5', $ou->getOid());
  113. $this->assertEquals(array('objectClass', 'ou'), $ou->getMustContain());
  114. $this->assertEquals(array('businessCategory', 'description', 'destinationIndicator',
  115. 'facsimileTelephoneNumber', 'internationaliSDNNumber', 'l',
  116. 'physicalDeliveryOfficeName', 'postOfficeBox', 'postalAddress', 'postalCode',
  117. 'preferredDeliveryMethod', 'registeredAddress', 'searchGuide', 'seeAlso', 'st',
  118. 'street', 'telephoneNumber', 'teletexTerminalIdentifier', 'telexNumber',
  119. 'userPassword', 'x121Address'), $ou->getMayContain());
  120. $this->assertEquals('RFC2256: an organizational unit', $ou->getDescription());
  121. $this->assertEquals(Zend_Ldap_Node_Schema::OBJECTCLASS_TYPE_STRUCTURAL, $ou->getType());
  122. $this->assertEquals(array('top'), $ou->getParentClasses());
  123. $this->assertEquals('2.5.6.5', $ou->oid);
  124. $this->assertEquals('organizationalUnit', $ou->name);
  125. $this->assertEquals('RFC2256: an organizational unit', $ou->desc);
  126. $this->assertFalse($ou->obsolete);
  127. $this->assertEquals(array('top'), $ou->sup);
  128. $this->assertFalse($ou->abstract);
  129. $this->assertTrue($ou->structural);
  130. $this->assertFalse($ou->auxiliary);
  131. $this->assertEquals(array('ou'), $ou->must);
  132. $this->assertEquals(array('userPassword', 'searchGuide', 'seeAlso', 'businessCategory',
  133. 'x121Address', 'registeredAddress', 'destinationIndicator', 'preferredDeliveryMethod',
  134. 'telexNumber', 'teletexTerminalIdentifier', 'telephoneNumber',
  135. 'internationaliSDNNumber', 'facsimileTelephoneNumber', 'street', 'postOfficeBox',
  136. 'postalCode', 'postalAddress', 'physicalDeliveryOfficeName', 'st', 'l',
  137. 'description'), $ou->may);
  138. $this->assertEquals("( 2.5.6.5 NAME 'organizationalUnit' " .
  139. "DESC 'RFC2256: an organizational unit' SUP top STRUCTURAL MUST ou " .
  140. "MAY ( userPassword $ searchGuide $ seeAlso $ businessCategory $ x121Address $ " .
  141. "registeredAddress $ destinationIndicator $ preferredDeliveryMethod $ telexNumber $ " .
  142. "teletexTerminalIdentifier $ telephoneNumber $ internationaliSDNNumber $ " .
  143. "facsimileTelephoneNumber $ street $ postOfficeBox $ postalCode $ postalAddress $ " .
  144. "physicalDeliveryOfficeName $ st $ l $ description ) )", $ou->_string);
  145. $this->assertEquals(array(), $ou->aliases);
  146. $this->assertSame($objectClasses['top'], $ou->_parents[0]);
  147. $this->assertArrayHasKey('ou', $attributeTypes);
  148. $ou=$attributeTypes['ou'];
  149. $this->assertTrue($ou instanceof Zend_Ldap_Node_Schema_AttributeType_OpenLdap);
  150. $this->assertEquals('ou', $ou->getName());
  151. $this->assertEquals('2.5.4.11', $ou->getOid());
  152. $this->assertEquals('1.3.6.1.4.1.1466.115.121.1.15', $ou->getSyntax());
  153. $this->assertEquals(32768, $ou->getMaxLength());
  154. $this->assertFalse($ou->isSingleValued());
  155. $this->assertEquals('RFC2256: organizational unit this object belongs to', $ou->getDescription());
  156. $this->assertEquals('2.5.4.11', $ou->oid);
  157. $this->assertEquals('ou', $ou->name);
  158. $this->assertEquals('RFC2256: organizational unit this object belongs to', $ou->desc);
  159. $this->assertFalse($ou->obsolete);
  160. $this->assertEquals(array('name'), $ou->sup);
  161. $this->assertNull($ou->equality);
  162. $this->assertNull($ou->ordering);
  163. $this->assertNull($ou->substr);
  164. $this->assertNull($ou->syntax);
  165. $this->assertNull($ou->{'max-length'});
  166. $this->assertFalse($ou->{'single-value'});
  167. $this->assertFalse($ou->collective);
  168. $this->assertFalse($ou->{'no-user-modification'});
  169. $this->assertEquals('userApplications', $ou->usage);
  170. $this->assertEquals("( 2.5.4.11 NAME ( 'ou' 'organizationalUnitName' ) " .
  171. "DESC 'RFC2256: organizational unit this object belongs to' SUP name )", $ou->_string);
  172. $this->assertEquals(array('organizationalUnitName'), $ou->aliases);
  173. $this->assertSame($attributeTypes['name'], $ou->_parents[0]);
  174. }
  175. public function testActiveDirectorySchema()
  176. {
  177. if ($this->_getLdap()->getRootDse()->getServerType() !==
  178. Zend_Ldap_Node_RootDse::SERVER_TYPE_ACTIVEDIRECTORY) {
  179. $this->markTestSkipped('Test can only be run on an Active Directory server');
  180. }
  181. $objectClasses=$this->_schema->getObjectClasses();
  182. $attributeTypes=$this->_schema->getAttributeTypes();
  183. }
  184. public function testeDirectorySchema()
  185. {
  186. if ($this->_getLdap()->getRootDse()->getServerType() !==
  187. Zend_Ldap_Node_RootDse::SERVER_TYPE_EDIRECTORY) {
  188. $this->markTestSkipped('Test can only be run on an eDirectory server');
  189. }
  190. $this->markTestIncomplete("Novell eDirectory schema parsing is incomplete");
  191. }
  192. public function testOpenLdapSchemaAttributeTypeInheritance()
  193. {
  194. if ($this->_getLdap()->getRootDse()->getServerType() !==
  195. Zend_Ldap_Node_RootDse::SERVER_TYPE_OPENLDAP) {
  196. $this->markTestSkipped('Test can only be run on an OpenLDAP server');
  197. }
  198. $attributeTypes=$this->_schema->getAttributeTypes();
  199. $name=$attributeTypes['name'];
  200. $cn=$attributeTypes['cn'];
  201. $this->assertEquals('2.5.4.41', $name->getOid());
  202. $this->assertEquals('2.5.4.3', $cn->getOid());
  203. $this->assertNull($name->sup);
  204. $this->assertEquals(array('name'), $cn->sup);
  205. $this->assertEquals('caseIgnoreMatch', $name->equality);
  206. $this->assertNull($name->ordering);
  207. $this->assertEquals('caseIgnoreSubstringsMatch', $name->substr);
  208. $this->assertEquals('1.3.6.1.4.1.1466.115.121.1.15', $name->syntax);
  209. $this->assertEquals('1.3.6.1.4.1.1466.115.121.1.15', $name->getSyntax());
  210. $this->assertEquals(32768, $name->{'max-length'});
  211. $this->assertEquals(32768, $name->getMaxLength());
  212. $this->assertNull($cn->equality);
  213. $this->assertNull($cn->ordering);
  214. $this->assertNull($cn->substr);
  215. $this->assertNull($cn->syntax);
  216. $this->assertEquals('1.3.6.1.4.1.1466.115.121.1.15', $cn->getSyntax());
  217. $this->assertNull($cn->{'max-length'});
  218. $this->assertEquals(32768, $cn->getMaxLength());
  219. }
  220. public function testOpenLdapSchemaObjectClassInheritance()
  221. {
  222. if ($this->_getLdap()->getRootDse()->getServerType() !==
  223. Zend_Ldap_Node_RootDse::SERVER_TYPE_OPENLDAP) {
  224. $this->markTestSkipped('Test can only be run on an OpenLDAP server');
  225. }
  226. $objectClasses=$this->_schema->getObjectClasses();
  227. if (!array_key_exists('certificationAuthority', $objectClasses) ||
  228. !array_key_exists('certificationAuthority-V2', $objectClasses)) {
  229. $this->markTestSkipped('This requires OpenLDAP core schema');
  230. }
  231. $ca=$objectClasses['certificationAuthority'];
  232. $ca2=$objectClasses['certificationAuthority-V2'];
  233. $this->assertEquals('2.5.6.16', $ca->getOid());
  234. $this->assertEquals('2.5.6.16.2', $ca2->getOid());
  235. $this->assertEquals(array('top'), $ca->sup);
  236. $this->assertEquals(array('certificationAuthority'), $ca2->sup);
  237. $this->assertEquals(array('authorityRevocationList', 'certificateRevocationList',
  238. 'cACertificate'), $ca->must);
  239. $this->assertEquals(array('authorityRevocationList', 'cACertificate',
  240. 'certificateRevocationList', 'objectClass'), $ca->getMustContain());
  241. $this->assertEquals(array('crossCertificatePair'), $ca->may);
  242. $this->assertEquals(array('crossCertificatePair'), $ca->getMayContain());
  243. $this->assertEquals(array(), $ca2->must);
  244. $this->assertEquals(array('authorityRevocationList', 'cACertificate',
  245. 'certificateRevocationList', 'objectClass'), $ca2->getMustContain());
  246. $this->assertEquals(array('deltaRevocationList'), $ca2->may);
  247. $this->assertEquals(array('crossCertificatePair', 'deltaRevocationList'),
  248. $ca2->getMayContain());
  249. }
  250. public function testOpenLdapSchemaAttributeTypeAliases()
  251. {
  252. if ($this->_getLdap()->getRootDse()->getServerType() !==
  253. Zend_Ldap_Node_RootDse::SERVER_TYPE_OPENLDAP) {
  254. $this->markTestSkipped('Test can only be run on an OpenLDAP server');
  255. }
  256. $attributeTypes=$this->_schema->getAttributeTypes();
  257. $this->assertArrayHasKey('cn', $attributeTypes);
  258. $this->assertArrayHasKey('commonName', $attributeTypes);
  259. $ob1=$attributeTypes['cn'];
  260. $ob2=$attributeTypes['commonName'];
  261. $this->assertSame($ob1, $ob2);
  262. }
  263. public function testOpenLdapSchemaObjectClassAliases()
  264. {
  265. if ($this->_getLdap()->getRootDse()->getServerType() !==
  266. Zend_Ldap_Node_RootDse::SERVER_TYPE_OPENLDAP) {
  267. $this->markTestSkipped('Test can only be run on an OpenLDAP server');
  268. }
  269. $objectClasses=$this->_schema->getObjectClasses();
  270. $this->assertArrayHasKey('OpenLDAProotDSE', $objectClasses);
  271. $this->assertArrayHasKey('LDAProotDSE', $objectClasses);
  272. $ob1=$objectClasses['OpenLDAProotDSE'];
  273. $ob2=$objectClasses['LDAProotDSE'];
  274. $this->assertSame($ob1, $ob2);
  275. }
  276. }