Beispiel #1
0
 /**
  * Retrieve a node knowing its dn
  *
  * @param string $dn         Distinguished name of the node to look for
  * @param array  $attributes Filter attributes to be retrieved (Optional)
  * @param string $filter     Ldap filter according to RFC4515 (Optional)
  *
  * @return Node
  *
  * @throws NodeNotFoundException if node cannot be retrieved
  */
 public function getNode($dn, $attributes = null, $filter = null)
 {
     $this->validateBinding();
     $attributes = is_array($attributes) ? $attributes : null;
     $filter = null === $filter ? '(objectclass=*)' : $filter;
     try {
         $search = $this->connection->search(SearchInterface::SCOPE_BASE, $dn, $filter, $attributes);
     } catch (NoResultException $e) {
         throw new NodeNotFoundException(sprintf('Node %s not found', $dn));
     }
     if (null === ($entry = $search->next())) {
         throw new NodeNotFoundException(sprintf('Node %s not found', $dn));
     }
     $node = new Node();
     $node->hydrateFromEntry($entry);
     return $node;
 }
Beispiel #2
0
 /**
  * Tests setting Dn for a node
  *
  * @return void
  */
 public function testSetDn()
 {
     $node = new Node();
     $this->assertNull($node->getDn());
     $node->setDn('test');
     $this->assertEquals('test', $node->getDn());
     $node = new Node();
     $entry = new Entry('test_dn', array());
     $node->hydrateFromEntry($entry);
     $this->assertEquals('test_dn', $node->getDn());
     try {
         $node->setDn('other_dn');
         $this->fail('Cannot manually set dn when node is bound to an existing entry');
     } catch (\InvalidArgumentException $e) {
         $this->assertRegExp('/Dn cannot be updated manually/', $e->getMessage());
     }
     $this->assertEquals('test_dn', $node->getDn());
     $node->setDn('other_dn', true);
     $this->assertEquals('other_dn', $node->getDn());
 }
Beispiel #3
0
 /**
  * Tests deletion of nodes
  *
  * @return void
  */
 public function testDelete()
 {
     $manager = new Manager($this->minimal, $this->driver);
     $node = $this->buildNode('ent1', array());
     $this->assertBindingFirst($manager, 'delete', array($node));
     $manager->connect();
     $this->assertBindingFirst($manager, 'delete', array($node));
     $manager->bind();
     $this->assertNull($this->driver->getConnection()->shiftLog(), 'Nothing happenned yet');
     // No corresponding entry in the Ldap
     try {
         $manager->delete($node);
         $this->fail('This entry is not in the Ldap store');
     } catch (NodeNotFoundException $e) {
         $this->assertRegExp('/ent1 not found/', $e->getMessage());
     }
     $this->assertSearchLog($this->driver->getConnection()->shiftLog(), 'ent1', '(objectclass=*)', SearchInterface::SCOPE_BASE);
     $this->assertNull($this->driver->getConnection()->shiftLog(), 'Nothing else');
     // Basic deletion
     $set = array(new Entry('ent1'));
     $this->driver->getConnection()->stackResults($set);
     $manager->delete($node);
     $this->assertNull($this->driver->getConnection()->shiftResults(), 'Node got pulled');
     $this->assertSearchLog($this->driver->getConnection()->shiftLog(), 'ent1', '(objectclass=*)', SearchInterface::SCOPE_BASE, null, $set);
     // Deleted node search
     $this->assertSearchLog($this->driver->getConnection()->shiftLog(), 'ent1', '(objectclass=*)', SearchInterface::SCOPE_ONE);
     // Deleted node children search
     $this->assertActionLog($this->driver->getConnection()->shiftLog(), 'delete', 'ent1');
     $this->assertNull($this->driver->getConnection()->shiftLog(), 'nothing else');
     // Deletion does not search for the entry if the node is already hydrated
     $node = new Node();
     $node->hydrateFromEntry(new Entry('ent1', array()));
     $this->assertNull($this->driver->getConnection()->shiftResults(), 'No node in the stack');
     $manager->delete($node);
     $this->assertSearchLog($this->driver->getConnection()->shiftLog(), 'ent1', '(objectclass=*)', SearchInterface::SCOPE_ONE);
     // Only one children search
     $this->assertActionLog($this->driver->getConnection()->shiftLog(), 'delete', 'ent1');
     $this->assertNull($this->driver->getConnection()->shiftLog(), 'nothing else');
     // Exception with node children and no recursion configured
     $node = $this->buildNode('ref', array());
     $sets = array();
     $sets[] = array(new Entry('ref'));
     $sets[] = array(new Entry('a-ref'), new Entry('b-ref'), new Entry('c-ref'));
     $this->driver->getConnection()->stackResults($sets[0]);
     // The node we want to delete
     $this->driver->getConnection()->stackResults($sets[1]);
     // Search for children nodes
     try {
         $manager->delete($node);
         $this->fail('Cannot delete the node, it has children');
     } catch (DeleteException $e) {
         $this->assertRegExp('/ref cannot be deleted/', $e->getMessage());
         $this->assertRegExp('/it has some children left/', $e->getMessage());
     }
     $this->assertSearchLog($this->driver->getConnection()->shiftLog(), 'ref', '(objectclass=*)', SearchInterface::SCOPE_BASE, null, $sets[0]);
     $this->assertSearchLog($this->driver->getConnection()->shiftLog(), 'ref', '(objectclass=*)', SearchInterface::SCOPE_ONE, null, $sets[1]);
     $this->assertNull($this->driver->getConnection()->shiftLog(), 'nothing else');
     // Recursive mode deletion
     $node = $this->buildNode('tst', array());
     $sets = array(array(new Entry('tst')), array(new Entry('a-tst'), new Entry('b-tst'), new Entry('c-tst')), array(), array(new Entry('a-b-tst')), array(), array());
     for ($i = 0; $i < count($sets); $i++) {
         $this->driver->getConnection()->stackResults($sets[$i]);
     }
     $manager->delete($node, true);
     $this->assertSearchLog($this->driver->getConnection()->shiftLog(), 'tst', '(objectclass=*)', SearchInterface::SCOPE_BASE, null, $sets[0]);
     // Deleted node search
     $this->assertSearchLog($this->driver->getConnection()->shiftLog(), 'tst', '(objectclass=*)', SearchInterface::SCOPE_ONE, null, $sets[1]);
     // Deleted node children search
     $this->assertSearchLog($this->driver->getConnection()->shiftLog(), 'a-tst', '(objectclass=*)', SearchInterface::SCOPE_ONE, null, $sets[2]);
     // a-tst node children search
     $this->assertActionLog($this->driver->getConnection()->shiftLog(), 'delete', 'a-tst');
     $this->assertSearchLog($this->driver->getConnection()->shiftLog(), 'b-tst', '(objectclass=*)', SearchInterface::SCOPE_ONE, null, $sets[3]);
     // b-tst node children search
     $this->assertSearchLog($this->driver->getConnection()->shiftLog(), 'a-b-tst', '(objectclass=*)', SearchInterface::SCOPE_ONE, null, $sets[4]);
     // a-b-tst node children search
     $this->assertActionLog($this->driver->getConnection()->shiftLog(), 'delete', 'a-b-tst');
     $this->assertActionLog($this->driver->getConnection()->shiftLog(), 'delete', 'b-tst');
     $this->assertSearchLog($this->driver->getConnection()->shiftLog(), 'c-tst', '(objectclass=*)', SearchInterface::SCOPE_ONE, null, $sets[5]);
     // b-tst node children search
     $this->assertActionLog($this->driver->getConnection()->shiftLog(), 'delete', 'c-tst');
     $this->assertActionLog($this->driver->getConnection()->shiftLog(), 'delete', 'tst');
     $this->assertNull($this->driver->getConnection()->shiftLog(), 'nothing else');
 }