summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/tests/User_LDAPTest.php
diff options
context:
space:
mode:
authorroot <roger.szabo@web.de>2016-08-30 17:43:29 +0800
committerLukas Reschke <lukas@statuscode.ch>2016-11-23 19:02:48 +0100
commit861c8572c03ba577ca89e1f9e88ab108cfafdf49 (patch)
tree56d8bc1a4f5b7a7dd94604da8efa7de309feeb40 /apps/user_ldap/tests/User_LDAPTest.php
parentd342eedc777413cc4b9438d53faed561563e03bf (diff)
downloadnextcloud-server-861c8572c03ba577ca89e1f9e88ab108cfafdf49.tar.gz
nextcloud-server-861c8572c03ba577ca89e1f9e88ab108cfafdf49.zip
restore ldap_password_pr
Signed-off-by: Roger Szabo <roger.szabo@web.de> remove notification part Signed-off-by: Roger Szabo <roger.szabo@web.de> blizzz comments Signed-off-by: Roger Szabo <roger.szabo@web.de> morris comment Signed-off-by: Roger Szabo <roger.szabo@web.de> improved error message for changing password Signed-off-by: Roger Szabo <roger.szabo@web.de> blizz comments 20161013 Signed-off-by: Roger Szabo <roger.szabo@web.de> Signed-off-by: Roger Szabo <roger.szabo@web.de> Adjust HintException usage Signed-off-by: Roger Szabo <roger.szabo@web.de> Signed-off-by: Roger Szabo <roger.szabo@web.de>
Diffstat (limited to 'apps/user_ldap/tests/User_LDAPTest.php')
-rw-r--r--apps/user_ldap/tests/User_LDAPTest.php101
1 files changed, 100 insertions, 1 deletions
diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php
index 05837097929..958d0b51979 100644
--- a/apps/user_ldap/tests/User_LDAPTest.php
+++ b/apps/user_ldap/tests/User_LDAPTest.php
@@ -9,6 +9,7 @@
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin McCorkell <robin@mccorkell.me.uk>
* @author Thomas Müller <thomas.mueller@tmit.eu>
+ * @author Roger Szabo <roger.szabo@web.de>
*
* @license AGPL-3.0
*
@@ -36,7 +37,7 @@ use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\LogWrapper;
use OCA\User_LDAP\User\Manager;
use OCA\User_LDAP\User\OfflineUser;
-use OCA\User_LDAP\User\User;
+use OC\HintException;
use OCA\User_LDAP\User_LDAP as UserLDAP;
use OCP\IAvatarManager;
use OCP\IConfig;
@@ -958,5 +959,103 @@ class User_LDAPTest extends TestCase {
// and once again to verify that caching works
$backend->loginName2UserName($loginName);
}
+
+ /**
+ * Prepares the Access mock for setPassword tests
+ * @param \OCA\User_LDAP\Access|\PHPUnit_Framework_MockObject_MockObject $access mock
+ * @return void
+ */
+ private function prepareAccessForSetPassword(&$access, $enablePasswordChange = true) {
+ $access->connection->expects($this->any())
+ ->method('__get')
+ ->will($this->returnCallback(function($name) use (&$enablePasswordChange) {
+ if($name === 'ldapLoginFilter') {
+ return '%uid';
+ }
+ if($name === 'turnOnPasswordChange') {
+ return $enablePasswordChange?1:0;
+ }
+ return null;
+ }));
+
+ $access->connection->expects($this->any())
+ ->method('getFromCache')
+ ->will($this->returnCallback(function($uid) {
+ if($uid === 'userExists'.'roland') {
+ return true;
+ }
+ return null;
+ }));
+
+ $access->expects($this->any())
+ ->method('fetchListOfUsers')
+ ->will($this->returnCallback(function($filter) {
+ if($filter === 'roland') {
+ return array(array('dn' => ['dnOfRoland,dc=test']));
+ }
+ return array();
+ }));
+
+ $access->expects($this->any())
+ ->method('fetchUsersByLoginName')
+ ->will($this->returnCallback(function($uid) {
+ if($uid === 'roland') {
+ return array(array('dn' => ['dnOfRoland,dc=test']));
+ }
+ return array();
+ }));
+
+ $access->expects($this->any())
+ ->method('dn2username')
+ ->with($this->equalTo('dnOfRoland,dc=test'))
+ ->will($this->returnValue('roland'));
+
+ $access->expects($this->any())
+ ->method('stringResemblesDN')
+ ->with($this->equalTo('dnOfRoland,dc=test'))
+ ->will($this->returnValue(true));
+
+ $access->expects($this->any())
+ ->method('setPassword')
+ ->will($this->returnCallback(function($uid, $password) {
+ if(strlen($password) <= 5) {
+ throw new HintException('Password fails quality checking policy', '', 19);
+ }
+ return true;
+ }));
+ }
+
+ /**
+ * @expectedException \OC\HintException
+ * @expectedExceptionMessage Password fails quality checking policy
+ */
+ public function testSetPasswordInvalid() {
+ $access = $this->getAccessMock();
+ $this->prepareAccessForSetPassword($access);
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ \OC_User::useBackend($backend);
+
+ $this->assertTrue(\OC_User::setPassword('roland', 'dt'));
+ }
+
+ public function testSetPasswordValid() {
+ $access = $this->getAccessMock();
+
+ $this->prepareAccessForSetPassword($access);
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ \OC_User::useBackend($backend);
+
+ $this->assertTrue(\OC_User::setPassword('roland', 'dt12234$'));
+ }
+
+ public function testSetPasswordValidDisabled() {
+ $access = $this->getAccessMock();
+
+ $this->prepareAccessForSetPassword($access, false);
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ \OC_User::useBackend($backend);
+
+ $this->assertFalse(\OC_User::setPassword('roland', 'dt12234$'));
+ }
}