This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
lnldap/tests/classes/LDAPConnection.php
2013-07-13 22:42:02 +10:00

104 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 = Arr::merge(Kohana::$config->load('database.default'),array(
'connection'=>array('hostname'=>$host,'port'=>$port),
));
$x = 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 = Arr::merge(Kohana::$config->load('database.default'),array(
'login_attr'=>'uid',
'connection'=>array(
'hostname'=>'localhost',
'port'=>389,
'username'=>$user,
'password'=>$password
),
));
// Ensure we start with a clean auth connection.
LDAP::factory('auth')->disconnect();
LDAP::factory('default')->disconnect();
$x = LDAP::factory('default',NULL,$connection);
$x->bind('bart','eatmyshorts');
if ($expect)
$this->assertTrue($x->connected());
else
$this->assertFalse($x->connected());
}
}