Przeglądaj źródła

[ZF-9564]
fixed behavior when updating and adding entries that have multiple values on an RDN attribute
updated test-suite to test behavior

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22163 44c647ce-9c0f-0410-b52a-842ac1e357ba

sgehrig 15 lat temu
rodzic
commit
ce825b6a74
2 zmienionych plików z 134 dodań i 5 usunięć
  1. 11 5
      library/Zend/Ldap.php
  2. 123 0
      tests/Zend/Ldap/CrudTest.php

+ 11 - 5
library/Zend/Ldap.php

@@ -1196,10 +1196,10 @@ class Zend_Ldap
         $rdnParts = $dn->getRdn(Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER);
         foreach ($rdnParts as $key => $value) {
             $value = Zend_Ldap_Dn::unescapeValue($value);
-            if (!array_key_exists($key, $entry) ||
-                    !in_array($value, $entry[$key]) ||
-                    count($entry[$key]) !== 1) {
+            if (!array_key_exists($key, $entry)) {
                 $entry[$key] = array($value);
+            } else if (!in_array($value, $entry[$key])) {
+                $entry[$key] = array_merge(array($value), $entry[$key]);
             }
         }
         $adAttributes = array('distinguishedname', 'instancetype', 'name', 'objectcategory',
@@ -1237,10 +1237,16 @@ class Zend_Ldap
         self::prepareLdapEntryArray($entry);
 
         $rdnParts = $dn->getRdn(Zend_Ldap_Dn::ATTR_CASEFOLD_LOWER);
+        foreach ($rdnParts as $key => $value) {
+            $value = Zend_Ldap_Dn::unescapeValue($value);
+            if (array_key_exists($key, $entry) && !in_array($value, $entry[$key])) {
+                $entry[$key] = array_merge(array($value), $entry[$key]);
+            }
+        }
+
         $adAttributes = array('distinguishedname', 'instancetype', 'name', 'objectcategory',
             'objectguid', 'usnchanged', 'usncreated', 'whenchanged', 'whencreated');
-        $stripAttributes = array_merge(array_keys($rdnParts), $adAttributes);
-        foreach ($stripAttributes as $attr) {
+        foreach ($adAttributes as $attr) {
             if (array_key_exists($attr, $entry)) {
                 unset($entry[$attr]);
             }

+ 123 - 0
tests/Zend/Ldap/CrudTest.php

@@ -383,4 +383,127 @@ class Zend_Ldap_CrudTest extends Zend_Ldap_OnlineTestCase
             $this->fail($e->getMessage());
         }
     }
+
+	/**
+     * @group ZF-9564
+     */
+    public function testAddingEntryWithMissingRdnAttribute() {
+        $dn   = $this->_createDn('ou=TestCreated,');
+        $data = array(
+            'objectClass' => array('organizationalUnit')
+        );
+        try {
+            $this->_getLdap()->add($dn, $data);
+            $entry = $this->_getLdap()->getEntry($dn);
+            $this->_getLdap()->delete($dn);
+            $this->assertEquals(array('TestCreated'), $entry['ou']);
+
+        } catch (Zend_Ldap_Exception $e) {
+            if ($this->_getLdap()->exists($dn)) {
+                $this->_getLdap()->delete($dn);
+            }
+            $this->fail($e->getMessage());
+        }
+    }
+
+	/**
+     * @group ZF-9564
+     */
+    public function testAddingEntryWithMissingRdnAttributeValue() {
+        $dn   = $this->_createDn('ou=TestCreated,');
+        $data = array(
+        	'ou' => array('SecondOu'),
+            'objectClass' => array('organizationalUnit')
+        );
+        try {
+            $this->_getLdap()->add($dn, $data);
+            $entry = $this->_getLdap()->getEntry($dn);
+            $this->_getLdap()->delete($dn);
+            $this->assertEquals(array('TestCreated', 'SecondOu'), $entry['ou']);
+
+        } catch (Zend_Ldap_Exception $e) {
+            if ($this->_getLdap()->exists($dn)) {
+                $this->_getLdap()->delete($dn);
+            }
+            $this->fail($e->getMessage());
+        }
+    }
+
+    /**
+     * @group ZF-9564
+     */
+    public function testAddingEntryThatHasMultipleValuesOnRdnAttribute() {
+        $dn   = $this->_createDn('ou=TestCreated,');
+        $data = array(
+            'ou' => array('TestCreated', 'SecondOu'),
+            'objectClass' => array('organizationalUnit')
+        );
+        try {
+            $this->_getLdap()->add($dn, $data);
+            $entry = $this->_getLdap()->getEntry($dn);
+            $this->_getLdap()->delete($dn);
+            $this->assertEquals(array('TestCreated', 'SecondOu'), $entry['ou']);
+
+        } catch (Zend_Ldap_Exception $e) {
+            if ($this->_getLdap()->exists($dn)) {
+                $this->_getLdap()->delete($dn);
+            }
+            $this->fail($e->getMessage());
+        }
+    }
+
+	/**
+     * @group ZF-9564
+     */
+    public function testUpdatingEntryWithAttributeThatIsAnRdnAttribute() {
+        $dn   = $this->_createDn('ou=TestCreated,');
+        $data = array(
+            'ou' => array('TestCreated'),
+            'objectClass' => array('organizationalUnit')
+        );
+        try {
+            $this->_getLdap()->add($dn, $data);
+            $entry = $this->_getLdap()->getEntry($dn);
+
+            $data = array('ou' => array_merge($entry['ou'], array('SecondOu')));
+            $this->_getLdap()->update($dn, $data);
+            $entry = $this->_getLdap()->getEntry($dn);
+            $this->_getLdap()->delete($dn);
+            $this->assertEquals(array('TestCreated', 'SecondOu'), $entry['ou']);
+
+        } catch (Zend_Ldap_Exception $e) {
+            if ($this->_getLdap()->exists($dn)) {
+                $this->_getLdap()->delete($dn);
+            }
+            $this->fail($e->getMessage());
+        }
+    }
+
+	/**
+     * @group ZF-9564
+     */
+    public function testUpdatingEntryWithRdnAttributeValueMissingInData() {
+        $dn   = $this->_createDn('ou=TestCreated,');
+        $data = array(
+            'ou' => array('TestCreated'),
+            'objectClass' => array('organizationalUnit')
+        );
+        try {
+            $this->_getLdap()->add($dn, $data);
+            $entry = $this->_getLdap()->getEntry($dn);
+
+            $data = array('ou' => 'SecondOu');
+            $this->_getLdap()->update($dn, $data);
+            $entry = $this->_getLdap()->getEntry($dn);
+            $this->_getLdap()->delete($dn);
+            $this->assertEquals(array('TestCreated', 'SecondOu'), $entry['ou']);
+
+        } catch (Zend_Ldap_Exception $e) {
+            if ($this->_getLdap()->exists($dn)) {
+                $this->_getLdap()->delete($dn);
+            }
+            $this->fail($e->getMessage());
+        }
+
+    }
 }