Browse Source

added test to verify that current update() method fails when changing a user's password on an ActiveDirectory server.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@17487 44c647ce-9c0f-0410-b52a-842ac1e357ba
sgehrig 16 years ago
parent
commit
bc3e1df202
1 changed files with 96 additions and 0 deletions
  1. 96 0
      tests/Zend/Ldap/ChangePasswordTest.php

+ 96 - 0
tests/Zend/Ldap/ChangePasswordTest.php

@@ -114,4 +114,100 @@ class Zend_Ldap_ChangePasswordTest extends Zend_Ldap_OnlineTestCase
             $this->fail($e->getMessage());
         }
     }
+
+    public function testAddNewUserWithPasswordActiveDirectory()
+    {
+        if ($this->_getLdap()->getRootDse()->getServerType() !==
+                Zend_Ldap_Node_RootDse::SERVER_TYPE_ACTIVEDIRECTORY) {
+            $this->markTestSkipped('Test can only be run on an ActiveDirectory server');
+        }
+        $options = $this->_getLdap()->getOptions();
+        if ($options['useSsl'] !== true && $options['useStartTls'] !== true) {
+            $this->markTestSkipped('Test can only be run on an SSL or TLS secured connection');
+        }
+
+        $dn = $this->_createDn('cn=New User,');
+        $data = array();
+        $password = 'pa$$w0rd';
+        Zend_Ldap_Attribute::setAttribute($data, 'cn', 'New User', false);
+        Zend_Ldap_Attribute::setAttribute($data, 'displayName', 'New User', false);
+        Zend_Ldap_Attribute::setAttribute($data, 'sAMAccountName', 'newuser', false);
+        Zend_Ldap_Attribute::setAttribute($data, 'userAccountControl', 512, false);
+        Zend_Ldap_Attribute::setAttribute($data, 'objectClass', 'person', true);
+        Zend_Ldap_Attribute::setAttribute($data, 'objectClass', 'organizationalPerson', true);
+        Zend_Ldap_Attribute::setAttribute($data, 'objectClass', 'user', true);
+        Zend_Ldap_Attribute::setPassword($data, $password,
+            Zend_Ldap_Attribute::PASSWORD_UNICODEPWD, 'unicodePwd');
+
+        try {
+            $this->_getLdap()->add($dn, $data);
+
+            $this->assertType('Zend_Ldap', $this->_getLdap()->bind($dn, $password));
+
+            $this->_getLdap()->bind();
+            $this->_getLdap()->delete($dn);
+        } catch (Zend_Ldap_Exception $e) {
+            $this->_getLdap()->bind();
+            if ($this->_getLdap()->exists($dn)) {
+                $this->_getLdap()->delete($dn);
+            }
+            $this->fail($e->getMessage());
+        }
+    }
+
+    public function testChangePasswordWithUserAccountActiveDirectory()
+    {
+        if ($this->_getLdap()->getRootDse()->getServerType() !==
+                Zend_Ldap_Node_RootDse::SERVER_TYPE_ACTIVEDIRECTORY) {
+            $this->markTestSkipped('Test can only be run on an ActiveDirectory server');
+        }
+        $options = $this->_getLdap()->getOptions();
+        if ($options['useSsl'] !== true && $options['useStartTls'] !== true) {
+            $this->markTestSkipped('Test can only be run on an SSL or TLS secured connection');
+        }
+
+        $dn = $this->_createDn('cn=New User,');
+        $data = array();
+        $password = 'pa$$w0rd';
+        Zend_Ldap_Attribute::setAttribute($data, 'cn', 'New User', false);
+        Zend_Ldap_Attribute::setAttribute($data, 'displayName', 'New User', false);
+        Zend_Ldap_Attribute::setAttribute($data, 'sAMAccountName', 'newuser', false);
+        Zend_Ldap_Attribute::setAttribute($data, 'userAccountControl', 512, false);
+        Zend_Ldap_Attribute::setAttribute($data, 'objectClass', 'person', true);
+        Zend_Ldap_Attribute::setAttribute($data, 'objectClass', 'organizationalPerson', true);
+        Zend_Ldap_Attribute::setAttribute($data, 'objectClass', 'user', true);
+        Zend_Ldap_Attribute::setPassword($data, $password,
+            Zend_Ldap_Attribute::PASSWORD_UNICODEPWD, 'unicodePwd');
+
+        try {
+            $this->_getLdap()->add($dn, $data);
+
+            $this->_getLdap()->bind($dn, $password);
+
+            $newPasswd = 'newpasswd';
+            $newData = array();
+            Zend_Ldap_Attribute::setPassword($newData, $newPasswd, Zend_Ldap_Attribute::PASSWORD_UNICODEPWD);
+            $this->_getLdap()->update($dn, $newData);
+
+            try {
+                $this->_getLdap()->bind($dn, $password);
+                $this->fail('Expected exception not thrown');
+            } catch (Zend_Ldap_Exception $zle) {
+                $message = $zle->getMessage();
+                $this->assertTrue(strstr($message, 'Invalid credentials') ||
+                    strstr($message, 'Server is unwilling to perform'));
+            }
+
+            $this->assertType('Zend_Ldap', $this->_getLdap()->bind($dn, $newPasswd));
+
+            $this->_getLdap()->bind();
+            $this->_getLdap()->delete($dn);
+        } catch (Zend_Ldap_Exception $e) {
+            $this->_getLdap()->bind();
+            if ($this->_getLdap()->exists($dn)) {
+                $this->_getLdap()->delete($dn);
+            }
+            $this->fail($e->getMessage());
+        }
+    }
 }