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); }
function let(LdapConnectionInterface $connection, LdapObject $rootdse) { $domain = new DomainConfiguration('example.local'); $domain->setUseTls(true); $connection->getConfig()->willReturn($domain); $connection->getRootDse()->willReturn($rootdse); $config = new Configuration(); $this->parser = new SchemaYamlParser($config->getSchemaFolder()); $this->schema = $this->parser->parse('ad', 'user'); }
function it_should_throw_an_exception_if_ssl_or_tls_is_not_enabled(\LdapTools\Connection\LdapConnectionInterface $connection) { $this->toLdap('test')->shouldNotThrow('\\LdapTools\\Exception\\LdapConnectionException'); $config = new DomainConfiguration('example.local'); $config->setUseTls(true); $connection->getConfig()->willReturn($config); $this->setLdapConnection($connection); $this->toLdap('test')->shouldNotThrow('\\LdapTools\\Exception\\LdapConnectionException'); $config->setUseTls(false); $this->shouldThrow('\\LdapTools\\Exception\\LdapConnectionException')->duringToLdap('test'); $config->setUseSsl(true); $this->toLdap('test')->shouldNotThrow('\\LdapTools\\Exception\\LdapConnectionException'); }
function it_should_get_the_ldif_string_representation_in_the_context_of_a_type_and_a_schema(LdapConnectionInterface $connection, LdapObject $rootdse) { $domain = new DomainConfiguration('example.local'); $domain->setUseTls(true); $connection->getConfig()->willReturn($domain); $connection->getRootDse()->willReturn($rootdse); $config = new Configuration(); $parser = new SchemaYamlParser($config->getSchemaFolder()); $schema = $parser->parse('ad', 'user'); $dn = 'cn=foo,dc=foo,dc=bar'; $this->beConstructedWith($dn); $this->setLdapObjectSchema($schema); $this->setLdapConnection($connection); $this->add('phoneNumber', '555-5555'); $this->reset('lastName'); $this->replace('firstName', 'bar'); $this->delete('password', 'foo'); $this->add('password', 'bar'); $ldif = "dn: {$dn}\r\n" . "changetype: modify\r\n" . "add: telephoneNumber\r\n" . "telephoneNumber: 555-5555\r\n" . "-\r\n" . "delete: sn\r\n" . "-\r\n" . "replace: givenName\r\n" . "givenName: bar\r\n" . "-\r\n" . "delete: unicodePwd\r\n" . "unicodePwd: IgBmAG8AbwAiAA==\r\n" . "-\r\n" . "add: unicodePwd\r\n" . "unicodePwd: IgBiAGEAcgAiAA==\r\n" . "-\r\n"; $this->toString()->shouldBeEqualTo($ldif); }
function it_should_get_the_ldif_representation_in_the_context_of_a_type_and_schema(LdapConnectionInterface $connection, LdapObject $rootdse) { $domain = new DomainConfiguration('example.local'); $domain->setUseTls(true); $connection->getConfig()->willReturn($domain); $connection->getRootDse()->willReturn($rootdse); $config = new Configuration(); $parser = new SchemaYamlParser($config->getSchemaFolder()); $schema = $parser->parse('ad', 'user'); $this->beConstructedWith(null); $this->setLdapObjectSchema($schema); $this->setLdapConnection($connection); $this->setAttributes(['username' => 'John', 'password' => '12345']); $this->setLocation('ou=employees,dc=example,dc=local'); $ldif = "dn: cn=John,ou=employees,dc=example,dc=local\r\n" . "changetype: add\r\n" . "cn: John\r\n" . "displayname: John\r\n" . "givenName: John\r\n" . "userPrincipalName: John@example.local\r\n" . "objectclass: top\r\n" . "objectclass: person\r\n" . "objectclass: organizationalPerson\r\n" . "objectclass: user\r\n" . "sAMAccountName: John\r\n" . "unicodePwd: IgAxADIAMwA0ADUAIgA=\r\n" . "userAccountControl: 512\r\n"; $this->toString()->shouldBeEqualTo($ldif); }