function it_should_have_a_page_size_as_specified_from_the_config() { $config = new DomainConfiguration('example.com'); $config->setServers(['test'])->setBaseDn('dc=example,dc=local')->setLazyBind(true)->setPageSize(250); $this->beConstructedWith($config); $this->getConfig()->getPageSize()->shouldBeEqualTo(250); }
function it_should_adjust_the_port_if_it_changes_in_the_domain_config(TcpSocket $tcp) { $tcp->connect('foo', 389, 1)->shouldBeCalled()->willReturn(true); $tcp->close()->shouldBeCalled(); $config = new DomainConfiguration('example.com'); $config->setServers(['foo']); $this->beConstructedWith($config, $tcp); $this->getServer()->shouldReturn('foo'); $config->setPort(9001); $tcp->connect('foo', 9001, 1)->shouldBeCalled()->willReturn(true); $this->getServer()->shouldReturn('foo'); }
function it_should_return_FilterBuilder_when_calling_filter_and_the_ldap_type_is_not_ActiveDirectory() { $domain = new DomainConfiguration('example.com'); $domain->setServers(['example'])->setBaseDn('dc=example,dc=com')->setLazyBind(true)->setPageSize(500)->setLdapType(LdapConnection::TYPE_OPENLDAP); $connection = new LdapConnection($domain); $this->beConstructedWith($connection); $this->filter()->shouldBeLike(new FilterBuilder()); }
function it_should_register_converters_listed_in_the_config() { $config = new Configuration(); $config->setSchemaFolder(__DIR__ . '/../resources/schema'); $config->setAttributeConverters(['my_bool' => '\\LdapTools\\AttributeConverter\\ConvertBoolean']); $domain = new DomainConfiguration('example.com'); $domain->setServers(['example'])->setLazyBind(true)->setBaseDn('dc=example,dc=com')->setSchemaName('example'); $config->addDomain($domain); $this->beConstructedWith($config); $this->buildLdapQuery()->from('custom_converter')->where(['foo' => true])->toLdapFilter()->shouldBeEqualTo('(&(objectClass=foo)(&(bar=TRUE)))'); }
function it_should_sort_results_for_multiple_aliases($connection) { $config = new Configuration(); $domain = new DomainConfiguration('example.com'); $domain->setServers(['example'])->setBaseDn('dc=example,dc=com')->setLazyBind(true)->setPageSize(500); $connection->getConfig()->willReturn($domain); $config->setCacheType('none'); $parser = SchemaParserFactory::get($config->getSchemaFormat(), $config->getSchemaFolder()); $cache = CacheFactory::get($config->getCacheType(), []); $dispatcher = new SymfonyEventDispatcher(); $schemaFactory = new LdapObjectSchemaFactory($cache, $parser, $dispatcher); $ou = $schemaFactory->get('ad', 'ou'); $container = $schemaFactory->get('ad', 'container'); $filter = new OperatorCollection(); $filter->addLdapObjectSchema($ou); $filter->addLdapObjectSchema($container); $this->operation->setFilter($filter); $this->operation->setAttributes([]); $connection->execute(Argument::that(function ($op) { return $op->getFilter() == '(objectClass=organizationalUnit)'; }))->shouldBeCalled()->willReturn($this->ous); $connection->execute(Argument::that(function ($op) { return $op->getFilter() == '(&(objectCategory=container))'; }))->shouldBeCalled()->willReturn($this->containers); $this->setOrderBy(['Name' => LdapQuery::ORDER['ASC'], 'ou.Description' => LdapQuery::ORDER['DESC']]); $this->getResult()->shouldHavePlaceKeyAndValue(0, 'name', 'Computers'); $this->getResult()->shouldHavePlaceKeyAndValue(1, 'name', 'Employees'); $this->getResult()->shouldHavePlaceKeyAndValue(2, 'name', 'Users'); $this->getResult()->shouldHavePlaceKeyAndValue(3, 'name', 'West'); }