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()); } }