/** * @param LdapConnectionInterface $connection * @param EventDispatcherInterface $dispatcher */ public function __construct(LdapConnectionInterface $connection, EventDispatcherInterface $dispatcher) { $this->connection = $connection; $this->dispatcher = $dispatcher; $cache = CacheFactory::get(CacheFactory::TYPE_NONE, []); $parser = SchemaParserFactory::get(SchemaParserFactory::TYPE_YML, self::SCHEMA_DIR); $this->schemaFactory = new LdapObjectSchemaFactory($cache, $parser, $dispatcher); }
public function let(LdapConnectionInterface $connection) { $config = new Configuration(); $config->setCacheType('none'); $connection->execute(Argument::any())->willReturn($this->ldapEntries); $connection->getConfig()->willReturn(new DomainConfiguration('example.local')); $cache = CacheFactory::get($config->getCacheType(), $config->getCacheOptions()); $parser = SchemaParserFactory::get($config->getSchemaFormat(), $config->getSchemaFolder()); $dispatcher = new SymfonyEventDispatcher(); $schemaFactory = new LdapObjectSchemaFactory($cache, $parser, $dispatcher); $this->beConstructedWith($schemaFactory->get('ad', 'user'), $connection); }
function let(LdapConnectionInterface $connection) { $config = (new DomainConfiguration('example.com'))->setSchemaName('example'); $connection->getConfig()->willReturn($config); $config = new Configuration(); $parserTest = SchemaParserFactory::get($config->getSchemaFormat(), __DIR__ . '/../resources/schema'); $parser = SchemaParserFactory::get($config->getSchemaFormat(), __DIR__ . '/../../resources/schema'); $cache = CacheFactory::get('none', []); $this->dispatcherTest = new SymfonyEventDispatcher(); $this->dispatcher = new SymfonyEventDispatcher(); $this->objectSchemaFactoryTest = new LdapObjectSchemaFactory($cache, $parserTest, $this->dispatcherTest); $this->objectSchemaFactory = new LdapObjectSchemaFactory($cache, $parser, $this->dispatcher); $this->beConstructedWith($connection, $this->objectSchemaFactory, $this->dispatcher); }
function let(LdapConnectionInterface $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); $this->fb = new FilterBuilder(); $this->schema = $schemaFactory; $this->objectSchema = $schema = new LdapObjectSchema('ad', 'user'); $this->objectSchema->setFilter($this->fb->bAnd($this->fb->eq('objectCategory', 'person'), $this->fb->eq('objectClass', 'user'))); $this->beConstructedWith($connection, $schemaFactory); }
public function let(LdapConnectionInterface $connection) { $this->config = (new DomainConfiguration('example.com'))->setSchemaName('example'); $this->config->setUseTls(true); $ldapObject = new LdapObject(['defaultNamingContext' => 'dc=example,dc=com'], ['*'], '', 'ad'); $connection->getConfig()->willReturn($this->config); $connection->getRootDse()->willReturn($ldapObject); $config = new Configuration(); $parser = SchemaParserFactory::get($config->getSchemaFormat(), $config->getSchemaFolder()); $parserTest = SchemaParserFactory::get($config->getSchemaFormat(), __DIR__ . '/../../resources/schema'); $cache = CacheFactory::get('none', []); $this->dispatcher = new SymfonyEventDispatcher(); $this->schemaFactoryTest = new LdapObjectSchemaFactory($cache, $parserTest, $this->dispatcher); $this->schemaFactory = new LdapObjectSchemaFactory($cache, $parser, $this->dispatcher); $this->attributes['unicodePwd'] = (new EncodeWindowsPassword())->toLdap('12345'); $this->addOperation = (new AddOperation('foo'))->setDn("cn=somedude,dc=foo,dc=bar")->setAttributes($this->attributes); $this->beConstructedWith($connection, $this->schemaFactoryTest, $this->dispatcher); }
/** * Retrieve the schema parser instance. * * @return Schema\Parser\SchemaParserInterface */ public function getSchemaParser() { if (!$this->schemaParser) { $this->schemaParser = SchemaParserFactory::get($this->config->getSchemaFormat(), $this->config->getSchemaFolder()); } return $this->schemaParser; }
function it_should_call_the_load_schema_event($dispatcher) { $config = new Configuration(); $parser = SchemaParserFactory::get('yml', $config->getSchemaFolder()); $cache = CacheFactory::get('none', []); new LdapObjectSchemaEvent(Event::LDAP_SCHEMA_LOAD, new LdapObjectSchema('ad', 'user')); $dispatcher->dispatch(Argument::type('\\LdapTools\\Event\\LdapObjectSchemaEvent'))->shouldBeCalled(); $this->beConstructedWith($cache, $parser, $dispatcher); $this->get('ad', LdapObjectType::USER); }
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'); }