Example #1
0
 public function testUnescapeValues()
 {
     $dnval = '\\20\\20\\16\\20t\\,e\\+s \\"t\\,\\\\v\\<a\\>l\\;u\\#e\\=!\\20\\20\\20\\20';
     $expected = '  ' . chr(22) . ' t,e+s "t,\\v<a>l;u#e=!    ';
     $this->assertEquals($expected, LDAP\DN::unescapeValue($dnval));
     $this->assertEquals($expected, LDAP\DN::unescapeValue(array($dnval)));
     $this->assertEquals(array($expected, $expected, $expected), LDAP\DN::unescapeValue(array($dnval, $dnval, $dnval)));
 }
 public function testSimpleRecursiveIteration()
 {
     $node = $this->_getLDAP()->getBaseNode();
     $ri = new \RecursiveIteratorIterator($node, \RecursiveIteratorIterator::SELF_FIRST);
     $i = 0;
     foreach ($ri as $rdn => $n) {
         $dn = $n->getDn()->toString(LDAP\DN::ATTR_CASEFOLD_LOWER);
         $rdn = LDAP\DN::implodeRdn($n->getRdnArray(), LDAP\DN::ATTR_CASEFOLD_LOWER);
         if ($i == 0) {
             $this->assertEquals(LDAP\DN::fromString(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE)->toString(LDAP\DN::ATTR_CASEFOLD_LOWER), $dn);
         } else {
             if ($i == 1) {
                 $this->assertEquals('ou=Node', $rdn);
                 $this->assertEquals($this->_createDn('ou=Node,'), $dn);
             } else {
                 if ($i < 4) {
                     $j = $i - 1;
                     $base = $this->_createDn('ou=Node,');
                 } else {
                     $j = $i - 3;
                     $base = LDAP\DN::fromString(TESTS_ZEND_LDAP_WRITEABLE_SUBTREE)->toString(LDAP\DN::ATTR_CASEFOLD_LOWER);
                 }
                 $this->assertEquals('ou=Test' . $j, $rdn);
                 $this->assertEquals('ou=Test' . $j . ',' . $base, $dn);
             }
         }
         $i++;
     }
     $this->assertEquals(9, $i);
 }
Example #3
0
 public function testSaveWithDnObject()
 {
     $dn = LDAP\DN::fromString($this->_createDn('ou=TestCreated,'));
     $data = array('ou' => 'TestCreated', 'objectclass' => 'organizationalUnit');
     try {
         $this->_getLDAP()->save($dn, $data);
         $this->assertTrue($this->_getLDAP()->exists($dn));
         $data['l'] = 'mylocation1';
         $this->_getLDAP()->save($dn, $data);
         $this->assertTrue($this->_getLDAP()->exists($dn));
         $entry = $this->_getLDAP()->getEntry($dn);
         $this->_getLDAP()->delete($dn);
         $this->assertEquals('mylocation1', $entry['l'][0]);
     } catch (LDAP\Exception $e) {
         if ($this->_getLDAP()->exists($dn)) {
             $this->_getLDAP()->delete($dn);
         }
         $this->fail($e->getMessage());
     }
 }
Example #4
0
 public function testIsChildOfParentDnLonger()
 {
     $dn1 = 'dc=example,dc=de';
     $dn2 = 'cb=name1,cn=name2,dc=example,dc=org';
     $this->assertFalse(LDAP\DN::isChildOf($dn1, $dn2));
 }
Example #5
0
 protected function _createDn($dn)
 {
     if (substr($dn, -1) !== ',') {
         $dn .= ',';
     }
     $dn = $dn . TESTS_ZEND_LDAP_WRITEABLE_SUBTREE;
     return LDAP\DN::fromString($dn)->toString(LDAP\DN::ATTR_CASEFOLD_LOWER);
 }
Example #6
0
File: LDAP.php Project: stunti/zf2
 /**
  * Copies a LDAP entry from one DN to another DN.
  *
  * @param  string|\Zend\LDAP\DN $from
  * @param  string|\Zend\LDAP\DN $to
  * @param  boolean             $recursively
  * @return \Zend\LDAP\LDAP Provides a fluid interface
  * @throws \Zend\LDAP\Exception
  */
 public function copy($from, $to, $recursively = false)
 {
     $entry = $this->getEntry($from, array(), true);
     if ($to instanceof DN) {
         $toDnParts = $to->toArray();
     } else {
         $toDnParts = DN::explodeDn($to);
     }
     $this->add($to, $entry);
     if ($recursively === true && $this->countChildren($from) > 0) {
         $children = $this->_getChildrenDns($from);
         foreach ($children as $c) {
             $cDnParts = DN::explodeDn($c);
             $newChildParts = array_merge(array(array_shift($cDnParts)), $toDnParts);
             $newChild = DN::implodeDn($newChildParts);
             $this->copy($c, $newChild, true);
         }
     }
     return $this;
 }
Example #7
0
 public function testRecursiveCopyWithDnObjects()
 {
     $orgSubTreeDn = LDAP\DN::fromString($this->_orgSubTreeDn);
     $newSubTreeDn = LDAP\DN::fromString($this->_newSubTreeDn);
     $this->_getLDAP()->copy($orgSubTreeDn, $newSubTreeDn, true);
     $this->assertTrue($this->_getLDAP()->exists($orgSubTreeDn));
     $this->assertTrue($this->_getLDAP()->exists($newSubTreeDn));
     $this->assertEquals(3, $this->_getLDAP()->countChildren($orgSubTreeDn));
     $this->assertEquals(3, $this->_getLDAP()->countChildren('ou=Subtree1,' . $orgSubTreeDn->toString()));
     $this->assertEquals(3, $this->_getLDAP()->countChildren($newSubTreeDn));
     $this->assertEquals(3, $this->_getLDAP()->countChildren('ou=Subtree1,' . $newSubTreeDn->toString()));
 }
Example #8
0
File: DN.php Project: stunti/zf2
 /**
  * Checks if given $childDn is beneath $parentDn subtree.
  *
  * @param  string|\Zend\LDAP\DN $childDn
  * @param  string|\Zend\LDAP\DN $parentDn
  * @return boolean
  */
 public static function isChildOf($childDn, $parentDn)
 {
     try {
         $keys = array();
         $vals = array();
         if ($childDn instanceof DN) {
             $cdn = $childDn->toArray(DN::ATTR_CASEFOLD_LOWER);
         } else {
             $cdn = self::explodeDn($childDn, $keys, $vals, DN::ATTR_CASEFOLD_LOWER);
         }
         if ($parentDn instanceof DN) {
             $pdn = $parentDn->toArray(DN::ATTR_CASEFOLD_LOWER);
         } else {
             $pdn = self::explodeDn($parentDn, $keys, $vals, DN::ATTR_CASEFOLD_LOWER);
         }
     } catch (Exception $e) {
         return false;
     }
     $startIndex = count($cdn) - count($pdn);
     if ($startIndex < 0) {
         return false;
     }
     for ($i = 0; $i < count($pdn); $i++) {
         if ($cdn[$i + $startIndex] != $pdn[$i]) {
             return false;
         }
     }
     return true;
 }
Example #9
0
 public function testGetSingleEntryWithDnObject()
 {
     $dn = LDAP\DN::fromString($this->_createDn('ou=Test1,'));
     $entry = $this->_getLDAP()->getEntry($dn);
     $this->assertEquals($dn->toString(), $entry["dn"]);
 }
Example #10
0
 public function testDnObjectCloning()
 {
     $node1 = $this->_createTestNode();
     $dn1 = LDAP\DN::fromString('cn=name2,dc=example,dc=org');
     $node1->setDn($dn1);
     $dn1->prepend(array('cn' => 'name'));
     $this->assertNotEquals($dn1->toString(), $node1->getDn()->toString());
     $dn2 = LDAP\DN::fromString('cn=name2,dc=example,dc=org');
     $node2 = Node\Node::create($dn2);
     $dn2->prepend(array('cn' => 'name'));
     $this->assertNotEquals($dn2->toString(), $node2->getDn()->toString());
     $dn3 = LDAP\DN::fromString('cn=name2,dc=example,dc=org');
     $node3 = Node\Node::fromArray(array('dn' => $dn3, 'ou' => 'Test'), false);
     $dn3->prepend(array('cn' => 'name'));
     $this->assertNotEquals($dn3->toString(), $node3->getDn()->toString());
 }
Example #11
0
 /**
  * Sets the new DN for this node
  *
  * This is an offline method.
  *
  * @param  \Zend\LDAP\DN|string|array $newDn
  * @throws \Zend\LDAP\Exception
  * @return \Zend\LDAP\Node\Node Provides a fluid interface
  */
 public function setDn($newDn)
 {
     if ($newDn instanceof LDAP\DN) {
         $this->_newDn = clone $newDn;
     } else {
         $this->_newDn = LDAP\DN::factory($newDn);
     }
     $this->_ensureRdnAttributeValues();
     return $this;
 }
Example #12
0
 public function testArrayAccessImplementation()
 {
     $dnString = 'cn=Baker\\, Alice,cn=Users,dc=example,dc=com';
     $dn = LDAP\DN::fromString($dnString);
     $this->assertEquals(array('cn' => 'Baker, Alice'), $dn[0]);
     $this->assertEquals(array('cn' => 'Users'), $dn[1]);
     $this->assertEquals(array('dc' => 'example'), $dn[2]);
     $this->assertEquals(array('dc' => 'com'), $dn[3]);
     $this->assertTrue(isset($dn[0]));
     $this->assertTrue(isset($dn[1]));
     $this->assertTrue(isset($dn[2]));
     $this->assertTrue(isset($dn[3]));
     $this->assertFalse(isset($dn[-1]));
     $this->assertFalse(isset($dn[4]));
     $dn = LDAP\DN::fromString($dnString);
     unset($dn[0]);
     $this->assertEquals('cn=Users,dc=example,dc=com', $dn->toString());
     $dn = LDAP\DN::fromString($dnString);
     unset($dn[1]);
     $this->assertEquals('cn=Baker\\, Alice,dc=example,dc=com', $dn->toString());
     $dn = LDAP\DN::fromString($dnString);
     unset($dn[2]);
     $this->assertEquals('cn=Baker\\, Alice,cn=Users,dc=com', $dn->toString());
     $dn = LDAP\DN::fromString($dnString);
     unset($dn[3]);
     $this->assertEquals('cn=Baker\\, Alice,cn=Users,dc=example', $dn->toString());
     $dn = LDAP\DN::fromString($dnString);
     $dn[0] = array('uid' => 'abaker');
     $this->assertEquals('uid=abaker,cn=Users,dc=example,dc=com', $dn->toString());
     $dn = LDAP\DN::fromString($dnString);
     $dn[1] = array('ou' => 'Lab');
     $this->assertEquals('cn=Baker\\, Alice,ou=Lab,dc=example,dc=com', $dn->toString());
     $dn = LDAP\DN::fromString($dnString);
     $dn[2] = array('dc' => 'example', 'ou' => 'Test');
     $this->assertEquals('cn=Baker\\, Alice,cn=Users,dc=example+ou=Test,dc=com', $dn->toString());
     $dn = LDAP\DN::fromString($dnString);
     $dn[3] = array('dc' => 'de+fr');
     $this->assertEquals('cn=Baker\\, Alice,cn=Users,dc=example,dc=de\\+fr', $dn->toString());
 }
Example #13
0
 public function testEmptyStringDn()
 {
     $dnString = '';
     $dn = LDAP\DN::fromString($dnString);
     $this->assertEquals($dnString, $dn->toString());
 }
Example #14
0
 /**
  * @expectedException Zend\LDAP\Exception
  */
 public function testImplodeRdnInvalidThree()
 {
     $a = array('cn' => 'value', 'ou');
     LDAP\DN::implodeRdn($a);
 }
Example #15
0
 /**
  * @dataProvider rfc2253DnProvider
  */
 public function testExplodeDnsProvidedByRFC2253($input, $expected)
 {
     $dnArray = LDAP\DN::explodeDn($input);
     $this->assertEquals($expected, $dnArray);
 }
Example #16
0
 /**
  * Returns the schema DN
  *
  * @return \Zend\LDAP\DN
  */
 public function getSchemaDn()
 {
     $schemaDn = $this->getSchemaNamingContext();
     return \Zend\LDAP\DN::fromString($schemaDn);
 }
Example #17
0
 /**
  * Returns the schema DN
  *
  * @return \Zend\LDAP\DN
  */
 public function getSchemaDn()
 {
     $schemaDn = $this->getSubschemaSubentry();
     return LDAP\DN::fromString($schemaDn);
 }
Example #18
0
 public function testLoadFromLDAPWithDnObject()
 {
     $dn = LDAP\DN::fromString($this->_createDn('ou=Test1,'));
     $node = Node\Node::fromLDAP($dn, $this->_getLDAP());
     $this->assertType('Zend\\LDAP\\Node\\Node', $node);
     $this->assertTrue($node->isAttached());
 }