SchemaTest.php 13 KB

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