Bläddra i källkod

[ZF-11611] fixed problem with multi-valued-RDN attributes

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24351 44c647ce-9c0f-0410-b52a-842ac1e357ba
sgehrig 14 år sedan
förälder
incheckning
dcb4df9f27
2 ändrade filer med 76 tillägg och 3 borttagningar
  1. 8 3
      library/Zend/Ldap/Node.php
  2. 68 0
      tests/Zend/Ldap/Node/OfflineTest.php

+ 8 - 3
library/Zend/Ldap/Node.php

@@ -319,12 +319,17 @@ class Zend_Ldap_Node extends Zend_Ldap_Node_Abstract implements Iterator, Recurs
     /**
     /**
      * Ensures that teh RDN attributes are correctly set.
      * Ensures that teh RDN attributes are correctly set.
      *
      *
+     * @param  boolean    $overwrite    True to overwrite the RDN attributes
      * @return void
      * @return void
      */
      */
-    protected function _ensureRdnAttributeValues()
+    protected function _ensureRdnAttributeValues($overwrite = false)
     {
     {
         foreach ($this->getRdnArray() as $key => $value) {
         foreach ($this->getRdnArray() as $key => $value) {
-            Zend_Ldap_Attribute::setAttribute($this->_currentData, $key, $value, false);
+            if (!array_key_exists($key, $this->_currentData) || $overwrite) {
+                Zend_Ldap_Attribute::setAttribute($this->_currentData, $key, $value, false);
+            } else if (!in_array($value, $this->_currentData[$key])) {
+                Zend_Ldap_Attribute::setAttribute($this->_currentData, $key, $value, true);
+            }
         }
         }
     }
     }
 
 
@@ -501,7 +506,7 @@ class Zend_Ldap_Node extends Zend_Ldap_Node_Abstract implements Iterator, Recurs
         } else {
         } else {
             $this->_newDn = Zend_Ldap_Dn::factory($newDn);
             $this->_newDn = Zend_Ldap_Dn::factory($newDn);
         }
         }
-        $this->_ensureRdnAttributeValues();
+        $this->_ensureRdnAttributeValues(true);
         return $this;
         return $this;
     }
     }
 
 

+ 68 - 0
tests/Zend/Ldap/Node/OfflineTest.php

@@ -595,4 +595,72 @@ class Zend_Ldap_Node_OfflineTest extends Zend_Ldap_TestCase
         $node->removeFromAttribute('test', array('value1', 'value3'));
         $node->removeFromAttribute('test', array('value1', 'value3'));
         $this->assertEquals(array('value2'), $node->test);
         $this->assertEquals(array('value2'), $node->test);
     }
     }
+
+    /**
+     * ZF-11611
+     */
+    public function testRdnAttributesHandleMultiValuedAttribute()
+    {
+        $data = array(
+        	'dn' => 'cn=funkygroup,ou=Groupes,dc=domain,dc=local',
+        	'objectClass' => array(
+        		'groupOfNames',
+        		'top',
+        	),
+        	'cn' => array(
+        		'The Funkygroup',
+        		'funkygroup',
+        	),
+        	'member' => 'uid=john-doe,ou=Users,dc=domain,dc=local',
+        );
+
+        $node = Zend_Ldap_Node::fromArray($data, true);
+        $this->assertEmpty($node->getChangedData());
+    }
+
+	/**
+     * ZF-11611
+     */
+    public function testRdnAttributesHandleMultiValuedAttribute2()
+    {
+        $data = array(
+        	'dn' => 'cn=funkygroup,ou=Groupes,dc=domain,dc=local',
+        	'objectClass' => array(
+        		'groupOfNames',
+        		'top',
+        	),
+        	'member' => 'uid=john-doe,ou=Users,dc=domain,dc=local',
+        );
+
+        $node = Zend_Ldap_Node::fromArray($data, true);
+        $cn = $node->getAttribute('cn');
+        $this->assertEquals(array(
+            0 => 'funkygroup'
+        ), $cn);
+    }
+
+	/**
+     * ZF-11611
+     */
+    public function testRdnAttributesHandleMultiValuedAttribute3()
+    {
+        $data = array(
+        	'dn' => 'cn=funkygroup,ou=Groupes,dc=domain,dc=local',
+        	'objectClass' => array(
+        		'groupOfNames',
+        		'top',
+        	),
+        	'cn' => array(
+        	    0 => 'The Funkygroup'
+        	),
+        	'member' => 'uid=john-doe,ou=Users,dc=domain,dc=local',
+        );
+
+        $node = Zend_Ldap_Node::fromArray($data, true);
+        $cn = $node->getAttribute('cn');
+        $this->assertEquals(array(
+           0 => 'The Funkygroup',
+           1 => 'funkygroup',
+        ), $cn);
+    }
 }
 }