Author: Chad Sikorra (Chad.Sikorra@gmail.com)
Inheritance: implements LdapTools\Operation\LdapOperationInterface, use trait LdapOperationTrait
 function it_should_NOT_enable_paging_when_executing_an_operation_that_disables_paging($pager)
 {
     $operation = new QueryOperation('(sAMAccountName=foo)', ['cn']);
     $operation->setUsePaging(false)->setBaseDn('example.local');
     $pager->setIsEnabled(false)->shouldBeCalled();
     $pager->start(null, 0)->shouldBeCalled();
     $pager->next()->shouldBeCalled();
     // Cannot simulate this without a connection. But the above control logic will be validated anyway.
     $this->shouldThrow('\\LdapTools\\Exception\\LdapConnectionException')->duringExecute($operation);
     $operation = new QueryOperation('(sAMAccountName=foo)', ['cn']);
     $operation->setScope(QueryOperation::SCOPE['BASE'])->setUsePaging(true)->setBaseDn('example.local');
     // Cannot simulate this without a connection. But the above control logic will be validated anyway.
     $this->shouldThrow('\\LdapTools\\Exception\\LdapConnectionException')->duringExecute($operation);
 }
Exemplo n.º 2
0
 /**
  * Get all the attributes that were selected for the query taking into account all of the aliases used.
  * 
  * @param array $aliases
  * @return array
  */
 protected function getSelectedForAllAliases(array $aliases)
 {
     if (empty($aliases)) {
         $selected = $this->mergeOrderByAttributes($this->getSelectedQueryAttributes($this->operation->getAttributes()));
     } else {
         // If there are aliases, then we need to loop through each one to determine was was actually selected for each.
         $selected = [];
         foreach ($aliases as $alias => $schema) {
             $selected = array_replace($selected, $this->mergeOrderByAttributes($this->getSelectedQueryAttributes($this->operation->getAttributes(), $schema), $alias));
         }
     }
     return $selected;
 }
Exemplo n.º 3
0
 function it_should_sort_case_sensitive_if_specified($connection)
 {
     $this->setIsCaseSensitiveSort(true)->shouldReturnAnInstanceOf('LdapTools\\Query\\LdapQuery');
     $this->operation->setAttributes(['givenName', 'sn', 'whenCreated']);
     $this->setOrderBy(['givenName' => 'ASC']);
     $entries = $this->sortEntries;
     $entries[1]['givenname'][0] = 'archie';
     $connection->execute(Argument::that(function ($op) {
         return $op->getAttributes() == ['givenName', 'sn', 'whenCreated'];
     }))->willReturn($entries);
     $this->getResult()->shouldHaveFirstValue('givenName', 'archie');
     $this->setOrderBy(['givenName' => 'DESC']);
     $this->getResult()->shouldHaveFirstValue('givenName', 'Archie');
 }
Exemplo n.º 4
0
 /**
  * @param QueryOperation $operation
  */
 protected function hydrateQueryOperation(QueryOperation $operation)
 {
     $operation->setAttributes($this->getAttributesToLdap($operation->getAttributes(), true, $this->schema, $this->alias));
     // Only want it set if it wasn't explicitly set...
     if ($this->schema && is_null($operation->getBaseDn())) {
         $operation->setBaseDn($this->schema->getBaseDn());
     }
     // Empty check instead of null due to the way the BaseDN is set for a RootDSE query...
     if (!empty($operation->getBaseDn()) && ParameterResolver::hasParameters($operation->getBaseDn())) {
         $this->setDefaultParameters();
         $operation->setBaseDn($this->resolveParameters(['baseDn' => $operation->getBaseDn()])['baseDn']);
     }
     // If null then we default to the domain config or the explicitly set value...
     if ($this->schema && !is_null($this->schema->getUsePaging())) {
         $operation->setUsePaging($this->schema->getUsePaging());
     }
     if ($this->schema && !is_null($this->schema->getScope())) {
         $operation->setScope($this->schema->getScope());
     }
     if ($this->schema) {
         $operation->addControl(...$this->schema->getControls());
     }
     if ($operation->getFilter() instanceof OperatorCollection) {
         $this->convertValuesToLdap($operation->getFilter());
         $operation->setFilter($operation->getFilter()->toLdapFilter($this->alias));
     }
 }
Exemplo n.º 5
0
 /**
  * Based on the query operation, determine whether paging should be used.
  *
  * @param QueryOperation $operation
  * @return bool
  */
 protected function shouldUsePaging(QueryOperation $operation)
 {
     return $operation->getUsePaging() && $operation->getScope() != QueryOperation::SCOPE['BASE'];
 }
Exemplo n.º 6
0
 public function let()
 {
     $this->operation = new QueryOperation('(foo=bar)');
     $this->operation->setAttributes(['foo'])->setBaseDn('foo')->setPageSize(2000)->setScope(QueryOperation::SCOPE['SUBTREE']);
     $this->beConstructedWith($this->operation);
 }
Exemplo n.º 7
0
 function it_should_correctly_add_attributes_to_select_based_off_aliases_in_the_order_by_selection($connection)
 {
     $this->setLdapConnection($connection);
     $gSchema = $this->parser->parse('ad', 'group');
     $operators = new OperatorCollection();
     $operators->addLdapObjectSchema($this->schema, 'u');
     $operators->addLdapObjectSchema($gSchema, 'g');
     $operationSelect = new QueryOperation($operators);
     $operationDefault = clone $operationSelect;
     $operationSelect->setAttributes(['u.firstName', 'u.lastName', 'name', 'g.description', 'g.members']);
     $operationDefault->setAttributes(['g.name', 'g.description']);
     $this->setOrderBy(['g.sid' => LdapQuery::ORDER['DESC'], 'u.department' => LdapQuery::ORDER['ASC'], 'guid' => LdapQuery::ORDER['ASC'], 'u.lastName' => LdapQuery::ORDER['DESC']]);
     // Any specifically selected attributes + specifically aliased attributes in the order by + generic in the order by.
     // Should also avoid adding duplicates.
     $this->setLdapObjectSchema($this->schema);
     $this->setAlias('u');
     $this->hydrateToLdap(clone $operationSelect)->getAttributes()->shouldBeEqualTo(['givenName', 'sn', 'cn', 'department', 'objectGuid']);
 }