public function testFailedSearch() { if ($this->skipIfNoLdap()) { return; } $mock = $this->getMock('Bart\\PHPLDAP'); $mock->expects($this->exactly(2))->method('ldap_bind')->will($this->returnValueMap(array(array('conn', 'binduser', 'bindpw', true), array('conn', $this->brayDN, 'jbraynardpwd', false)))); $this->stubSearchSequence($mock); Diesel::registerInstantiator('Bart\\PHPLDAP', function () use($mock) { return $mock; }); $ldap = new Ldap($this->config); $ldap->connect(); $this->assertThrows('\\Bart\\LdapException', "LDAP Auth: failure, username/password did not match for {$this->brayDN}", function () use($mock, $ldap) { $ldap->auth_user('jbraynard', 'jbraynardpwd'); }); }
<?php /** * Setup the test accounts on the ldap server. * * Assumes the username entries are 'uid'. * Note that all tests will crash horribly if any new trilogy characters are introduced here ;) * * @copyright Copyright (C) 1999-2013 eZ Systems AS. All rights reserved. * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 * @version //autogentag// * @package tests */ $dc = "dc=phpuc,dc=ez,dc=no"; $host = "phpuc.ez.no"; $connection = Ldap::connect("ldap://{$host}", "cn=%s,{$dc}", 'admin', 'wee123'); Ldap::delete($connection, 'yoda', "ou=StarWars,{$dc}"); Ldap::delete($connection, 'boba.fett', "ou=StarWars,{$dc}"); Ldap::delete($connection, 'obi.wan', "ou=StarWars,{$dc}"); Ldap::delete($connection, 'jabba.thehutt', "ou=StarWars,{$dc}"); Ldap::delete($connection, 'darth.vader', "ou=StarWars,{$dc}"); Ldap::delete($connection, 'leia', "ou=StarWars,{$dc}"); Ldap::delete($connection, 'han.solo', "ou=StarWars,{$dc}"); Ldap::delete($connection, 'chewbacca', "ou=StarWars,{$dc}"); Ldap::deleteGroup($connection, 'Jedi', "ou=RebelAlliance,ou=StarWars,{$dc}"); Ldap::deleteGroup($connection, 'RebelAlliance', "ou=StarWars,{$dc}"); Ldap::deleteGroup($connection, 'Sith', "ou=GalacticEmpire,ou=StarWars,{$dc}"); Ldap::deleteGroup($connection, 'GalacticEmpire', "ou=StarWars,{$dc}"); Ldap::deleteGroup($connection, 'Rogues', "ou=StarWars,{$dc}"); Ldap::deleteGroup($connection, 'StarWars', $dc); Ldap::addGroup($connection, 'StarWars', $dc);
<?php /** * Setup the test accounts on the ldap server. * * Assumes the username entries are 'uid'. * */ $dc = "dc=foo,dc=bar"; $connection = Ldap::connect('ldap://localhost', "cn=%s,{$dc}", 'admin', 'wee123'); Ldap::delete($connection, 'john.doe', $dc); Ldap::delete($connection, 'jan.modaal', $dc); Ldap::delete($connection, 'zhang.san', $dc); Ldap::delete($connection, 'hans.mustermann', $dc); Ldap::delete($connection, 'Ruşinică Piţigoi', $dc); Ldap::add($connection, 'john.doe', '{CRYPT}' . crypt('foobar'), $dc); Ldap::add($connection, 'jan.modaal', '{SHA}' . base64_encode(pack('H*', sha1('qwerty'))), $dc); Ldap::add($connection, 'zhang.san', '{MD5}' . base64_encode(pack('H*', md5('asdfgh'))), $dc); //Ldap::add( $connection, 'jan.modaal', '{SHA}' . base64_encode( sha1( 'qwerty' ) ), $dc ); //Ldap::add( $connection, 'zhang.san', '{MD5}' . base64_encode( md5( 'asdfgh' ) ), $dc ); Ldap::add($connection, 'hans.mustermann', 'abcdef', $dc); Ldap::add($connection, 'Ruşinică Piţigoi', '12345', $dc); Ldap::fetchAll($connection, $dc); Ldap::close($connection); /** * Support for LDAP functions connect, add, delete and get_entries. */ class Ldap { /** * Connects to an LDAP server specified by $uri, with admin $user and $password.