From: Gunnar Wrobel Date: Wed, 1 Dec 2010 20:41:26 +0000 (+0100) Subject: Replace the Kolab tests with a simpler unit test. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=452bb93042bb90d44874dcfc34d0ea3d4d251c59;p=horde.git Replace the Kolab tests with a simpler unit test. --- diff --git a/framework/Auth/test/Horde/Auth/Kolab/Autoload.php b/framework/Auth/test/Horde/Auth/Kolab/Autoload.php deleted file mode 100644 index 28b9fbd81..000000000 --- a/framework/Auth/test/Horde/Auth/Kolab/Autoload.php +++ /dev/null @@ -1,28 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Auth - */ - -if (!spl_autoload_functions()) { - spl_autoload_register( - create_function( - '$class', - '$filename = str_replace(array(\'::\', \'_\'), \'/\', $class);' - . '$err_mask = E_ALL ^ E_WARNING;' - . '$oldErrorReporting = error_reporting($err_mask);' - . 'include "$filename.php";' - . 'error_reporting($oldErrorReporting);' - ) - ); -} - -/** Catch strict standards */ -error_reporting(E_ALL | E_STRICT); diff --git a/framework/Auth/test/Horde/Auth/Kolab/Class/KolabTest.php b/framework/Auth/test/Horde/Auth/Kolab/Class/KolabTest.php deleted file mode 100644 index 529e3b8f0..000000000 --- a/framework/Auth/test/Horde/Auth/Kolab/Class/KolabTest.php +++ /dev/null @@ -1,134 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Session - */ - -/** - * Prepare the test setup. - */ -require_once dirname(__FILE__) . '/../Autoload.php'; - -/** - * Test the Kolab auth handler. - * - * Copyright 2009-2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Kolab - * @package Kolab_Session - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Kolab_Session - */ -class Horde_Auth_Kolab_Class_KolabTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - $this->markTestIncomplete('Needs some love'); - $this->session = $this->getMock('Horde_Kolab_Session'); - $this->factory = $this->getMock('Horde_Kolab_Session_Factory_Interface'); - - if (!defined('HORDE_BASE')) { - define('HORDE_BASE', '/nowhere'); - } - } - - public function testMethodSetsessionHasParameterSession() - { - throw new PHPUnit_Framework_IncompleteTestError('Horde_Auth_Kolab::setSession() does not exist.'); - $auth = new Horde_Auth_Kolab(); - $auth->setSession($this->session); - } - - public function testMethodGetsessionHasResultSession() - { - throw new PHPUnit_Framework_IncompleteTestError('Horde_Auth_Kolab::setSession() does not exist.'); - $auth = new Horde_Auth_Kolab(); - $auth->setSession($this->session); - $this->assertType( - 'Horde_Kolab_Session', - $auth->getSession('user', array('password' => 'test')) - ); - } - - public function testMethodGetsessionHasResultSessionFromTheFactoryIfTheSessionWasUnset() - { - $auth = new Horde_Auth_Kolab(); - throw new PHPUnit_Framework_IncompleteTestError('Horde_Auth_Kolab::setSessionFactory() does not exist.'); - $auth->setSessionFactory($this->factory); - $this->factory->expects($this->once()) - ->method('getSession') - ->with('user', array('password' => 'test')) - ->will($this->returnValue($this->session)); - $this->assertType( - 'Horde_Kolab_Session', - $auth->getSession('user', array('password' => 'test')) - ); - } - - public function testMethodAuthenticateHasResultBooleanTrueIfTheConnectionWasSuccessful() - { - $auth = new Horde_Auth_Kolab(); - throw new PHPUnit_Framework_IncompleteTestError('Horde_Auth_Kolab::setSessionFactory() does not exist.'); - $auth->setSessionFactory($this->factory); - $this->factory->expects($this->once()) - ->method('getSession') - ->with('user', array('password' => 'test')) - ->will($this->returnValue($this->session)); - $this->assertTrue( - $auth->authenticate('user', array('password' => 'test'), false) - ); - } - - public function testMethodAuthenticateHasPostconditionThatTheUserIdIsBeingRewrittenIfRequired() - { - $auth = new Horde_Auth_Kolab(); - throw new PHPUnit_Framework_IncompleteTestError('Horde_Auth_Kolab::setSessionFactory() does not exist.'); - $auth->setSessionFactory($this->factory); - $this->factory->expects($this->once()) - ->method('getSession') - ->with('user', array('password' => 'test')) - ->will($this->returnValue($this->session)); - $this->session->expects($this->once()) - ->method('getMail') - ->will($this->returnValue('mail@example.org')); - /* Untestable with the way the Auth driver is currently structured */ - $auth->authenticate('user', array('password' => 'test'), false); - } - - public function testMethodAuthenticateThrowsExceptionIfTheLoginFailed() - { - $auth = new Horde_Auth_Kolab(); - throw new PHPUnit_Framework_IncompleteTestError('Horde_Auth_Kolab::setSessionFactory() does not exist.'); - $auth->setSessionFactory($this->factory); - $this->factory->expects($this->once()) - ->method('getSession') - ->with('user', array('password' => 'test')) - ->will($this->throwException(new Horde_Kolab_Session_Exception('Error'))); - $auth->authenticate('user', array('password' => 'test'), false); - $this->assertEquals(Horde_Auth::REASON_FAILED, Horde_Auth::getAuthError()); - } - - public function testMethodAuthenticateThrowsExceptionIfTheCredentialsWereInvalid() - { - $auth = new Horde_Auth_Kolab(); - throw new PHPUnit_Framework_IncompleteTestError('Horde_Auth_Kolab::setSessionFactory() does not exist.'); - $auth->setSessionFactory($this->factory); - $this->factory->expects($this->once()) - ->method('getSession') - ->with('user', array('password' => 'test')) - ->will($this->throwException(new Horde_Kolab_Session_Exception_Badlogin('Error'))); - $auth->authenticate('user', array('password' => 'test'), false); - $this->assertEquals(Horde_Auth::REASON_BADLOGIN, Horde_Auth::getAuthError()); - } -} diff --git a/framework/Auth/test/Horde/Auth/Kolab/Integration/AuthTest.php b/framework/Auth/test/Horde/Auth/Kolab/Integration/AuthTest.php deleted file mode 100644 index b09d7f7fd..000000000 --- a/framework/Auth/test/Horde/Auth/Kolab/Integration/AuthTest.php +++ /dev/null @@ -1,253 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Auth - */ - -/** - * Prepare the test setup. - */ -require_once dirname(__FILE__) . '/../Autoload.php'; - -/** - * Kolab authentication tests. - * - * Copyright 2008-2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Auth - * @subpackage UnitTests - * @author Gunnar Wrobel - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Auth - */ -class Horde_Auth_Kolab_Integration_AuthTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - $this->markTestIncomplete('Needs some love'); - /** Provide the mock configuration for the server */ - $config = array(); - $config['ldap']['basedn'] = 'dc=test'; - $config['ldap']['mock'] = true; - $config['ldap']['data'] = array( - 'dn=user,dc=test' => array( - 'dn' => 'dn=user,dc=test', - 'data' => array( - 'uid' => array('user'), - 'mail' => array('user@example.org'), - 'userPassword' => array('pass'), - 'objectClass' => array('top', 'kolabInetOrgPerson'), - ) - ) - ); - //$this->factory = new Horde_Kolab_Session_Factory_Configuration($config); - - if (!defined('HORDE_BASE')) { - define('HORDE_BASE', '/nowhere'); - } - } - - public function testKolabLoginViaUid() - { - $auth = new Horde_Auth_Kolab(); - throw new PHPUnit_Framework_IncompleteTestError('Horde_Auth_Kolab::setSessionFactory() does not exist.'); - $auth->setSessionFactory($this->factory); - $this->assertTrue( - $auth->authenticate('user', array('password' => 'pass'), false) - ); - } - - public function testKolabLoginViaMail() - { - $auth = new Horde_Auth_Kolab(); - throw new PHPUnit_Framework_IncompleteTestError('Horde_Auth_Kolab::setSessionFactory() does not exist.'); - $auth->setSessionFactory($this->factory); - $this->assertTrue( - $auth->authenticate( - 'user@example.org', array('password' => 'pass'), false - ) - ); - } - - public function testKolabLoginFailureViaUid() - { - $auth = new Horde_Auth_Kolab(); - throw new PHPUnit_Framework_IncompleteTestError('Horde_Auth_Kolab::setSessionFactory() does not exist.'); - $auth->setSessionFactory($this->factory); - $auth->authenticate('user', array('password' => 'invalid'), false); - $this->assertEquals( - Horde_Auth::REASON_BADLOGIN, - Horde_Auth::getAuthError() - ); - } - - public function testKolabLoginFailureViaMail() - { - $auth = new Horde_Auth_Kolab(); - throw new PHPUnit_Framework_IncompleteTestError('Horde_Auth_Kolab::setSessionFactory() does not exist.'); - $auth->setSessionFactory($this->factory); - $auth->authenticate( - 'user@example.org', array('password' => 'invalid'), false - ); - $this->assertEquals( - Horde_Auth::REASON_BADLOGIN, - Horde_Auth::getAuthError() - ); - } - - public function testKolabLoginIdRewrite() - { - $auth = new Horde_Auth_Kolab_Dummy(); - throw new PHPUnit_Framework_IncompleteTestError('Horde_Auth_Kolab::setSessionFactory() does not exist.'); - $auth->setSessionFactory($this->factory); - $this->assertTrue( - $auth->authenticate('user', array('password' => 'pass'), false) - ); - $this->assertEquals('user@example.org', $auth->getId()); - } - - /** - * !!! This test has side effects !!! - * - * The Horde_Kolab_Session_Singleton will be set. - */ - public function testKolabLoginViaSessionSingleton() - { - $this->markTestIncomplete('Needs correct kolab session setup.'); - - global $conf; - - $conf['kolab']['ldap']['basedn'] = 'dc=test'; - $conf['kolab']['ldap']['mock'] = true; - $conf['kolab']['ldap']['data'] = array( - 'dn=user,dc=test' => array( - 'dn' => 'dn=user,dc=test', - 'data' => array( - 'uid' => array('user'), - 'mail' => array('user@example.org'), - 'userPassword' => array('pass'), - 'objectClass' => array('top', 'kolabInetOrgPerson'), - ) - ) - ); - - $auth = new Horde_Auth_Kolab(); - $this->assertTrue( - $auth->authenticate('user', array('password' => 'pass'), false) - ); - } - - /* /\** */ - /* * Test group based login allow implemention. */ - /* * */ - /* * @return NULL */ - /* *\/ */ - /* public function testLoginAllow() */ - /* { */ - /* global $conf; */ - /* $conf['kolab']['server']['allow_group'] = 'group2@example.org'; */ - /* $conf['kolab']['server']['deny_group'] = null; */ - - /* $this->markTestSkipped(); */ - /* $server = &$this->prepareEmptyKolabServer(); */ - /* $result = $server->add($this->provideBasicUserOne()); */ - /* $this->assertNoError($result); */ - /* $result = $server->add($this->provideBasicUserTwo()); */ - /* $this->assertNoError($result); */ - /* $groups = $this->validGroups(); */ - /* foreach ($groups as $group) { */ - /* $result = $server->add($group[0]); */ - /* $this->assertNoError($result); */ - /* } */ - - /* $session = Horde_Kolab_Session::singleton( */ - /* 'wrobel', */ - /* array('password' => 'none'), */ - /* true */ - /* ); */ - - /* $this->assertNoError($session->auth); */ - /* $this->assertEquals('wrobel@example.org', $session->user_mail); */ - - /* try { */ - /* $session = Horde_Kolab_Session::singleton( */ - /* 'test', */ - /* array('password' => 'test'), */ - /* true */ - /* ); */ - /* } catch (Horde_Kolab_Session_Exception $e) { */ - /* $this->assertError( */ - /* $e, 'You are no member of a group that may login on this server.' */ - /* ); */ - /* } */ - /* // FIXME: Ensure that the session gets overwritten */ - /* //$this->assertTrue(empty($session->user_mail)); */ - /* } */ - - /* /\** */ - /* * Test group based login deny implemention. */ - /* * */ - /* * @return NULL */ - /* *\/ */ - /* public function testLoginDeny() */ - /* { */ - /* global $conf; */ - /* $conf['kolab']['server']['deny_group'] = 'group2@example.org'; */ - /* unset($conf['kolab']['server']['allow_group']); */ - - /* $this->markTestSkipped(); */ - /* $server = &$this->prepareEmptyKolabServer(); */ - /* $result = $server->add($this->provideBasicUserOne()); */ - /* $this->assertNoError($result); */ - /* $result = $server->add($this->provideBasicUserTwo()); */ - /* $this->assertNoError($result); */ - /* $groups = $this->validGroups(); */ - /* foreach ($groups as $group) { */ - /* $result = $server->add($group[0]); */ - /* $this->assertNoError($result); */ - /* } */ - - /* $session = Horde_Kolab_Session::singleton( */ - /* 'test', */ - /* array('password' => 'test'), */ - /* true */ - /* ); */ - - /* $this->assertNoError($session->auth); */ - /* $this->assertEquals('test@example.org', $session->user_mail); */ - - /* try { */ - /* $session = Horde_Kolab_Session::singleton( */ - /* 'wrobel', */ - /* array('password' => 'none'), */ - /* true */ - /* ); */ - /* } catch (Horde_Kolab_Session_Exception $e) { */ - /* $this->assertError( */ - /* $e, 'You are member of a group that may not login on this server.' */ - /* ); */ - /* } */ - /* // FIXME: Ensure that the session gets overwritten */ - /* //$this->assertTrue(empty($session->user_mail)); */ - /* } */ -} - -class Horde_Auth_Kolab_Dummy extends Horde_Auth_Kolab -{ - public function getId() - { - return $this->_credentials['userId']; - } -} diff --git a/framework/Auth/test/Horde/Auth/Unit/KolabTest.php b/framework/Auth/test/Horde/Auth/Unit/KolabTest.php new file mode 100644 index 000000000..703dfe124 --- /dev/null +++ b/framework/Auth/test/Horde/Auth/Unit/KolabTest.php @@ -0,0 +1,80 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Auth + */ + +/** + * Prepare the test setup. + */ +require_once dirname(__FILE__) . '/../Autoload.php'; + +/** + * Test the Horde_Auth_Kolab:: class. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Auth + * @subpackage UnitTests + * @author Gunnar Wrobel + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Auth + */ +class Horde_Auth_Unit_KolabTest extends Horde_Auth_TestCase +{ + public function setUp() + { + if (!interface_exists('Horde_Kolab_Session')) { + $this->markTestSkipped('The Kolab_Session package is apparently not installed (Interface Horde_Kolab_Session is unavailable).'); + } + $this->kolab = $this->getMock('Horde_Kolab_Session'); + $this->driver = new Horde_Auth_Kolab(array('kolab' => $this->kolab)); + } + + public function testAuthenticate() + { + $this->kolab->expects($this->once()) + ->method('connect') + ->with('user', array('password' => 'password')) + ->will($this->returnValue(null)); + $this->assertTrue($this->driver->authenticate('user', array('password' => 'password'))); + } + + public function testBadLogin() + { + $this->kolab->expects($this->once()) + ->method('connect') + ->with('user', array('password' => 'incorrect')) + ->will($this->throwException(new Horde_Kolab_Session_Exception_Badlogin())); + try { + $this->driver->authenticate('user', array('password' => 'incorrect')); + } catch (Horde_Auth_Exception $e) { + $this->assertEquals(Horde_Auth::REASON_BADLOGIN, $e->getCode()); + } + } + + public function testFailure() + { + $this->kolab->expects($this->once()) + ->method('connect') + ->with('user', array('password' => '')) + ->will($this->throwException(new Horde_Kolab_Session_Exception())); + try { + $this->driver->authenticate('user', array('password' => '')); + } catch (Horde_Auth_Exception $e) { + $this->assertEquals(Horde_Auth::REASON_FAILED, $e->getCode()); + } + } +} \ No newline at end of file