From 055a09e487c2c6fedaa213a11434f9a985e12423 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 21 Mar 2014 15:27:51 +0100 Subject: [PATCH 1/3] On clone create a new instance of the Configuration To avide effects on the original instance of Connection when the clone is modified, for instance on authentication checks. --- apps/user_ldap/lib/connection.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php index b2075748a3..08ac4ac626 100644 --- a/apps/user_ldap/lib/connection.php +++ b/apps/user_ldap/lib/connection.php @@ -78,6 +78,8 @@ class Connection extends LDAPUtility { //a cloned instance inherits the connection resource. It may use it, //but it may not disconnect it $this->dontDestruct = true; + $this->configuration = new Configuration($this->configPrefix, + !is_null($this->configID)); } public function __get($name) { From 86d479cb28bcfc4fe7c665930b7954dcbe579e79 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 21 Mar 2014 15:29:49 +0100 Subject: [PATCH 2/3] Use array_key_exists instead of isset, because the latter returns false if the assigned value is null --- apps/user_ldap/lib/configuration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/user_ldap/lib/configuration.php b/apps/user_ldap/lib/configuration.php index 612a623e91..d42b1c0582 100644 --- a/apps/user_ldap/lib/configuration.php +++ b/apps/user_ldap/lib/configuration.php @@ -119,9 +119,9 @@ class Configuration { $cta = $this->getConfigTranslationArray(); foreach($config as $inputkey => $val) { - if(strpos($inputkey, '_') !== false && isset($cta[$inputkey])) { + if(strpos($inputkey, '_') !== false && array_key_exists($inputkey, $cta)) { $key = $cta[$inputkey]; - } elseif(isset($this->config[$inputkey])) { + } elseif(array_key_exists($inputkey, $this->config)) { $key = $inputkey; } else { continue; From 422ccf4cdb7558cea6c3c92cca3c5ea4ce192f44 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 21 Mar 2014 15:31:30 +0100 Subject: [PATCH 3/3] add test for cloning and keeping configuration seperate --- apps/user_ldap/tests/connection.php | 54 +++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 apps/user_ldap/tests/connection.php diff --git a/apps/user_ldap/tests/connection.php b/apps/user_ldap/tests/connection.php new file mode 100644 index 0000000000..f51b0c8301 --- /dev/null +++ b/apps/user_ldap/tests/connection.php @@ -0,0 +1,54 @@ +. +* +*/ + +namespace OCA\user_ldap\tests; + +class Test_Connection extends \PHPUnit_Framework_TestCase { + + public function testOriginalAgentUnchangedOnClone() { + //background: upon login a bind is done with the user credentials + //which is valid for the whole LDAP resource. It needs to be reset + //to the agent's credentials + $lw = $this->getMock('\OCA\user_ldap\lib\ILDAPWrapper'); + + $connection = new \OCA\user_ldap\lib\Connection($lw, '', null); + $agent = array( + 'ldapAgentName' => 'agent', + 'ldapAgentPassword' => '123456', + ); + $connection->setConfiguration($agent); + + $testConnection = clone $connection; + $user = array( + 'ldapAgentName' => 'user', + 'ldapAgentPassword' => 'password', + ); + $testConnection->setConfiguration($user); + + $agentName = $connection->ldapAgentName; + $agentPawd = $connection->ldapAgentPassword; + + $this->assertSame($agentName, $agent['ldapAgentName']); + $this->assertSame($agentPawd, $agent['ldapAgentPassword']); + } + +} \ No newline at end of file