From 05bab2772cf00f4b0475d20c060f93d3345aed9f Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel
Date: Thu, 5 Nov 2009 21:44:58 +0100 Subject: [PATCH] Remove the isConnected() call again and ensure we get a connected session once we create it. --- framework/Kolab_Session/lib/Horde/Kolab/Session.php | 7 ------- .../lib/Horde/Kolab/Session/Anonymous.php | 10 ---------- .../Kolab_Session/lib/Horde/Kolab/Session/Base.php | 21 ++------------------- .../lib/Horde/Kolab/Session/Factory.php | 6 ++++-- .../lib/Horde/Kolab/Session/Factory/Anonymous.php | 8 +++++--- .../lib/Horde/Kolab/Session/Factory/Base.php | 10 +++++++--- .../Horde/Kolab/Session/Factory/Configuration.php | 8 +++++--- .../lib/Horde/Kolab/Session/Factory/Logged.php | 8 +++++--- .../lib/Horde/Kolab/Session/Logged.php | 10 ---------- .../lib/Horde/Kolab/Session/Singleton.php | 5 +---- .../lib/Horde/Kolab/Session/Stored.php | 10 ---------- .../test/Horde/Kolab/Session/Class/BaseTest.php | 12 ------------ .../Horde/Kolab/Session/Class/Factory/BaseTest.php | 21 +++++++++++++++++++++ .../Session/Class/Factory/ConfigurationTest.php | 14 +++++++++++++- 14 files changed, 63 insertions(+), 87 deletions(-) diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session.php b/framework/Kolab_Session/lib/Horde/Kolab/Session.php index 45a7c0273..f36a04ade 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session.php @@ -106,11 +106,4 @@ interface Horde_Kolab_Session * @return Horde_Kolab_Storage The storage connection. */ public function getStorage(); - - /** - * Return the connection status of this session. - * - * @return boolean True if the session has been successfully connected. - */ - public function isConnected(); } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Anonymous.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Anonymous.php index ef31e5590..9c046a6b2 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Anonymous.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Anonymous.php @@ -179,14 +179,4 @@ class Horde_Kolab_Session_Anonymous implements Horde_Kolab_Session { return $this->_session->getStorage(); } - - /** - * Return the connection status of this session. - * - * @return boolean True if the session has been successfully connected. - */ - public function isConnected() - { - return $this->_session->isConnected(); - } } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php index a2ec45562..f9b82303d 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Base.php @@ -104,13 +104,6 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session private $_storage; /** - * Indicate if this session was successfully connected. - * - * @var array - */ - private $_connected = false; - - /** * Constructor. * * @param string $user_id The session will be setup for the user @@ -144,12 +137,12 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session if (isset($credentials['password'])) { $password = $credentials['password']; } else { - throw new Horde_Kolab_Session_Exception('Missing password!'); + $password = ''; } try { $this->_server->connect($this->_user_id, $password); - $user_object = $this->_server->objects->fetch(); + $user_object = $this->_server->objects->fetch(); } catch (Horde_Kolab_Server_Exception_Bindfailed $e) { throw new Horde_Kolab_Session_Exception_Badlogin($e); } catch (Horde_Kolab_Server_Exception $e) { @@ -375,14 +368,4 @@ class Horde_Kolab_Session_Base implements Horde_Kolab_Session } return $this->_storage; } - - /** - * Return the connection status of this session. - * - * @return boolean True if the session has been successfully connected. - */ - public function isConnected() - { - return $this->_connected; - } } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory.php index 3dca47c3a..9fdba64f3 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory.php @@ -94,9 +94,11 @@ interface Horde_Kolab_Session_Factory * Returns either a reference to a session handler with data retrieved from * the session or a new session handler. * - * @param string $user The session will be setup for the user with this ID. + * @param string $user The session will be setup for the user with + * this ID. + * @param array $credentials An array of login credentials. * * @return Horde_Kolab_Session The concrete Kolab session reference. */ - public function getSession($user = null); + public function getSession($user = null, array $credentials = null); } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Anonymous.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Anonymous.php index 9f8be47b9..85f5081ca 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Anonymous.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Anonymous.php @@ -158,12 +158,14 @@ implements Horde_Kolab_Session_Factory * Returns either a reference to a session handler with data retrieved from * the session or a new session handler. * - * @param string $user The session will be setup for the user with this ID. + * @param string $user The session will be setup for the user with + * this ID. + * @param array $credentials An array of login credentials. * * @return Horde_Kolab_Session The concrete Kolab session reference. */ - public function getSession($user = null) + public function getSession($user = null, array $credentials = null) { - return $this->_factory->getSession($user); + return $this->_factory->getSession($user, $credentials); } } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Base.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Base.php index 309357e10..e9951070f 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Base.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Base.php @@ -91,11 +91,13 @@ implements Horde_Kolab_Session_Factory * Returns either a reference to a session handler with data retrieved from * the session or a new session handler. * - * @param string $user The session will be setup for the user with this ID. + * @param string $user The session will be setup for the user with + * this ID. + * @param array $credentials An array of login credentials. * * @return Horde_Kolab_Session The concrete Kolab session reference. */ - public function getSession($user = null) + public function getSession($user = null, array $credentials = null) { $storage = $this->getSessionStorage(); $session = $storage->load(); @@ -103,6 +105,8 @@ implements Horde_Kolab_Session_Factory if (!empty($session) && $this->validate($session, $user)) { return $session; } - return $this->createSession($user); + $session = $this->createSession($user); + $session->connect($credentials); + return $session; } } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Configuration.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Configuration.php index 0458c6684..8fa9930ab 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Configuration.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Configuration.php @@ -173,12 +173,14 @@ implements Horde_Kolab_Session_Factory * Returns either a reference to a session handler with data retrieved from * the session or a new session handler. * - * @param string $user The session will be setup for the user with this ID. + * @param string $user The session will be setup for the user with + * this ID. + * @param array $credentials An array of login credentials. * * @return Horde_Kolab_Session The concrete Kolab session reference. */ - public function getSession($user = null) + public function getSession($user = null, array $credentials = null) { - return $this->_factory->getSession($user); + return $this->_factory->getSession($user, $credentials); } } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Logged.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Logged.php index 513d92eb9..c398ebf69 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Logged.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Factory/Logged.php @@ -143,12 +143,14 @@ implements Horde_Kolab_Session_Factory * Returns either a reference to a session handler with data retrieved from * the session or a new session handler. * - * @param string $user The session will be setup for the user with this ID. + * @param string $user The session will be setup for the user with + * this ID. + * @param array $credentials An array of login credentials. * * @return Horde_Kolab_Session The concrete Kolab session reference. */ - public function getSession($user = null) + public function getSession($user = null, array $credentials = null) { - return $this->_factory->getSession($user); + return $this->_factory->getSession($user, $credentials); } } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Logged.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Logged.php index d99dd32d3..bba8424bd 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Logged.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Logged.php @@ -168,14 +168,4 @@ class Horde_Kolab_Session_Logged implements Horde_Kolab_Session { return $this->_session->getStorage(); } - - /** - * Return the connection status of this session. - * - * @return boolean True if the session has been successfully connected. - */ - public function isConnected() - { - return $this->_session->isConnected(); - } } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Singleton.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Singleton.php index 033f70b09..06cbc010d 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Singleton.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Singleton.php @@ -59,10 +59,7 @@ class Horde_Kolab_Session_Singleton $config = $conf['kolab']; $config['logger'] = Horde::getLogger(); $factory = new Horde_Kolab_Session_Factory_Configuration($config); - self::$_instance = $factory->getSession($user); - if (!self::$_instance->isConnected()) { - self::$_instance->connect($credentials); - } + self::$_instance = $factory->getSession($user, $credentials); } return self::$_instance; } diff --git a/framework/Kolab_Session/lib/Horde/Kolab/Session/Stored.php b/framework/Kolab_Session/lib/Horde/Kolab/Session/Stored.php index f73215eca..c1455908f 100644 --- a/framework/Kolab_Session/lib/Horde/Kolab/Session/Stored.php +++ b/framework/Kolab_Session/lib/Horde/Kolab/Session/Stored.php @@ -167,14 +167,4 @@ class Horde_Kolab_Session_Stored implements Horde_Kolab_Session { return $this->_session->getStorage(); } - - /** - * Return the connection status of this session. - * - * @return boolean True if the session has been successfully connected. - */ - public function isConnected() - { - return $this->_session->isConnected(); - } } diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/BaseTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/BaseTest.php index 4247388a2..483cd2a58 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/BaseTest.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/BaseTest.php @@ -162,18 +162,6 @@ class Horde_Kolab_Session_Class_BaseTest extends Horde_Kolab_Session_SessionTest $this->assertEquals('https://freebusy.example.org/fb', $session->getFreebusyServer()); } - public function testMethodConnectThrowsExceptionIfTheCredentialsHaveNoPasswordEntry() - { - $session = new Horde_Kolab_Session_Base( - 'user', $this->_getComposite(), array() - ); - try { - $session->connect(array()); - } catch (Horde_Kolab_Session_Exception $e) { - $this->assertEquals('Missing password!', $e->getMessage()); - } - } - public function testMethodConnectThrowsExceptionIfTheConnectionFailed() { $composite = $this->_getMockedComposite(); diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/BaseTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/BaseTest.php index 5379d5cfe..0ff43c543 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/BaseTest.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/BaseTest.php @@ -36,6 +36,9 @@ class Horde_Kolab_Session_Class_Factory_BaseTest extends Horde_Kolab_Session_Ses { parent::setUp(); $this->setupFactoryMocks(); + $this->user = $this->getMock( + 'Horde_Kolab_Server_Object_Hash', array(), array(), '', false, false + ); } public function testMethodGetvalidatorHasResultHordekolabsesessionvalid() @@ -103,6 +106,15 @@ class Horde_Kolab_Session_Class_Factory_BaseTest extends Horde_Kolab_Session_Ses $this->session_auth->expects($this->once()) ->method('getCurrentUser') ->will($this->returnValue('new@example.org')); + $this->server->objects->expects($this->once()) + ->method('fetch') + ->will($this->returnValue($this->user)); + $this->user->expects($this->exactly(1)) + ->method('getSingle') + ->will($this->returnValue('mail@example.org')); + $this->user->expects($this->exactly(4)) + ->method('getExternal') + ->will($this->returnValue(array('mail@example.org'))); $factory = new Horde_Kolab_Session_Factory_Constructor( $this->server, $this->session_auth, array(), $this->session_storage ); @@ -114,6 +126,15 @@ class Horde_Kolab_Session_Class_Factory_BaseTest extends Horde_Kolab_Session_Ses $this->session_storage->expects($this->once()) ->method('load') ->will($this->returnValue(false)); + $this->server->objects->expects($this->once()) + ->method('fetch') + ->will($this->returnValue($this->user)); + $this->user->expects($this->exactly(1)) + ->method('getSingle') + ->will($this->returnValue('mail@example.org')); + $this->user->expects($this->exactly(4)) + ->method('getExternal') + ->will($this->returnValue(array('mail@example.org'))); $factory = new Horde_Kolab_Session_Factory_Constructor( $this->server, $this->session_auth, array(), $this->session_storage ); diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConfigurationTest.php b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConfigurationTest.php index c4f54d85e..5946485de 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConfigurationTest.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/Class/Factory/ConfigurationTest.php @@ -210,7 +210,19 @@ class Horde_Kolab_Session_Class_Factory_ConfigurationTest extends Horde_Kolab_Se $factory = new Horde_Kolab_Session_Factory_Configuration( array( 'server' => array( - 'basedn' => '' + 'mock' => true, + 'basedn' => '', + 'data' => array( + 'dn=user' => array( + 'dn' => 'dn=user', + 'data' => array( + 'uid' => array(''), + 'mail' => array('user@example.org'), + 'userPassword' => array(''), + 'objectClass' => array('top', 'kolabInetOrgPerson'), + ) + ) + ) ) ) ); -- 2.11.0