106 lines
2.5 KiB
PHP
106 lines
2.5 KiB
PHP
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||
|
|
||
|
/**
|
||
|
* This should test all our connection methods to the LDAP server
|
||
|
* and return success and failures.
|
||
|
*
|
||
|
* @package Kohana/LDAP
|
||
|
* @category Test
|
||
|
* @author Deon George
|
||
|
* @copyright (c) 2013 phpLDAPadmin Development Team
|
||
|
* @license http://dev.phpldapadmin.org/license.html
|
||
|
* @group ldap
|
||
|
* @group ldap.server
|
||
|
*/
|
||
|
Class LDAPConnection extends Unittest_TestCase {
|
||
|
function hosts() {
|
||
|
return array(
|
||
|
array('localhost','389','a',TRUE),
|
||
|
array('localhost','389','b',TRUE),
|
||
|
array('localhost','390','a',FALSE),
|
||
|
array('localhost','390','b',FALSE),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Test that we can connect to an LDAP server
|
||
|
* @dataProvider hosts
|
||
|
*/
|
||
|
function testConnect($host,$port,$instance,$expect) {
|
||
|
$connection = array(
|
||
|
'type'=>'ldap',
|
||
|
'connection'=>array('hostname'=>$host,'port'=>$port),
|
||
|
);
|
||
|
|
||
|
$x = Database_LDAP::factory($instance,NULL,$connection);
|
||
|
$x->connect();
|
||
|
|
||
|
if ($expect)
|
||
|
$this->assertAttributeInternalType('resource','_connection',$x);
|
||
|
// In OpenLDAP, this still returns a resource, even though it should be a failure.
|
||
|
else
|
||
|
$this->assertAttributeInternalType('resource','_connection',$x);
|
||
|
|
||
|
$x->disconnect();
|
||
|
}
|
||
|
|
||
|
function auths() {
|
||
|
return array(
|
||
|
array('bart','eatmyshorts',TRUE),
|
||
|
array('bart','Eatmyshorts',FALSE),
|
||
|
array('nobart','Eatmyshorts',FALSE),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @dataProvider auths
|
||
|
* @depends testConnect
|
||
|
*/
|
||
|
function testAuth($user,$password,$expect) {
|
||
|
if ($expect)
|
||
|
$this->assertTrue(Auth::instance()->login($user,$password));
|
||
|
else
|
||
|
$this->assertFalse(Auth::instance()->login($user,$password));
|
||
|
|
||
|
Auth::instance()->logout();
|
||
|
}
|
||
|
|
||
|
function authconfig() {
|
||
|
return array(
|
||
|
array('','',TRUE),
|
||
|
array('bart','x',FALSE),
|
||
|
array('cn=Manager','Eatmyshorts',FALSE),
|
||
|
array('cn=Manager,dc=example.com','NotAllowed',TRUE),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @dataProvider authconfig
|
||
|
* @depends testConnect
|
||
|
*/
|
||
|
function testAuthConfiguration($user,$password,$expect) {
|
||
|
$connection = array(
|
||
|
'type'=>'ldap',
|
||
|
'login_attr'=>'uid',
|
||
|
'connection'=>array(
|
||
|
'hostname'=>'localhost',
|
||
|
'port'=>389,
|
||
|
'username'=>$user,
|
||
|
'password'=>$password
|
||
|
),
|
||
|
);
|
||
|
|
||
|
// Ensure we start with a clean auth connection.
|
||
|
Database_LDAP::factory('auth')->disconnect();
|
||
|
Database_LDAP::factory('default')->disconnect();
|
||
|
|
||
|
$x = Database_LDAP::factory('default',NULL,$connection);
|
||
|
$x->bind('bart','eatmyshorts');
|
||
|
|
||
|
if ($expect)
|
||
|
$this->assertTrue($x->connected());
|
||
|
else
|
||
|
$this->assertFalse($x->connected());
|
||
|
}
|
||
|
}
|