*
* @license AGPL-3.0
*
@@ -34,6 +35,7 @@ use OCP\IConfig;
use OCP\Image;
use OCP\IUserManager;
use OCP\Util;
+use OCP\Notification\IManager as INotificationManager;
/**
* User
@@ -73,6 +75,10 @@ class User {
* @var IUserManager
*/
protected $userManager;
+ /**
+ * @var INotificationManager
+ */
+ protected $notificationManager;
/**
* @var string
*/
@@ -108,11 +114,13 @@ class User {
* @param LogWrapper $log
* @param IAvatarManager $avatarManager
* @param IUserManager $userManager
+ * @param INotificationManager $notificationManager
*/
public function __construct($username, $dn, IUserTools $access,
IConfig $config, FilesystemHelper $fs, Image $image,
- LogWrapper $log, IAvatarManager $avatarManager, IUserManager $userManager) {
-
+ LogWrapper $log, IAvatarManager $avatarManager, IUserManager $userManager,
+ INotificationManager $notificationManager) {
+
if ($username === null) {
$log->log("uid for '$dn' must not be null!", Util::ERROR);
throw new \InvalidArgumentException('uid must not be null!');
@@ -121,16 +129,19 @@ class User {
throw new \InvalidArgumentException('uid must not be an empty string!');
}
- $this->access = $access;
- $this->connection = $access->getConnection();
- $this->config = $config;
- $this->fs = $fs;
- $this->dn = $dn;
- $this->uid = $username;
- $this->image = $image;
- $this->log = $log;
- $this->avatarManager = $avatarManager;
- $this->userManager = $userManager;
+ $this->access = $access;
+ $this->connection = $access->getConnection();
+ $this->config = $config;
+ $this->fs = $fs;
+ $this->dn = $dn;
+ $this->uid = $username;
+ $this->image = $image;
+ $this->log = $log;
+ $this->avatarManager = $avatarManager;
+ $this->userManager = $userManager;
+ $this->notificationManager = $notificationManager;
+
+ \OCP\Util::connectHook('OC_User', 'post_login', $this, 'handlePasswordExpiry');
}
/**
@@ -587,4 +598,98 @@ class User {
}
}
+ /**
+ * called by a post_login hook to handle password expiry
+ *
+ * @param array $params
+ */
+ public function handlePasswordExpiry($params) {
+ $ppolicyDN = $this->connection->ldapDefaultPPolicyDN;
+ if (empty($ppolicyDN) || (intval($this->connection->turnOnPasswordChange) !== 1)) {
+ return;//password expiry handling disabled
+ }
+ $uid = $params['uid'];
+ if(isset($uid) && $uid === $this->getUsername()) {
+ //retrieve relevant user attributes
+ $result = $this->access->search('objectclass=*', $this->dn, ['pwdpolicysubentry', 'pwdgraceusetime', 'pwdreset', 'pwdchangedtime']);
+
+ if(array_key_exists('pwdpolicysubentry', $result[0])) {
+ $pwdPolicySubentry = $result[0]['pwdpolicysubentry'];
+ if($pwdPolicySubentry && (count($pwdPolicySubentry) > 0)){
+ $ppolicyDN = $pwdPolicySubentry[0];//custom ppolicy DN
+ }
+ }
+
+ $pwdGraceUseTime = array_key_exists('pwdgraceusetime', $result[0]) ? $result[0]['pwdgraceusetime'] : null;
+ $pwdReset = array_key_exists('pwdreset', $result[0]) ? $result[0]['pwdreset'] : null;
+ $pwdChangedTime = array_key_exists('pwdchangedtime', $result[0]) ? $result[0]['pwdchangedtime'] : null;
+
+ //retrieve relevant password policy attributes
+ $cacheKey = 'ppolicyAttributes' . $ppolicyDN;
+ $result = $this->connection->getFromCache($cacheKey);
+ if(is_null($result)) {
+ $result = $this->access->search('objectclass=*', $ppolicyDN, ['pwdgraceauthnlimit', 'pwdmaxage', 'pwdexpirewarning']);
+ $this->connection->writeToCache($cacheKey, $result);
+ }
+
+ $pwdGraceAuthNLimit = array_key_exists('pwdgraceauthnlimit', $result[0]) ? $result[0]['pwdgraceauthnlimit'] : null;
+ $pwdMaxAge = array_key_exists('pwdmaxage', $result[0]) ? $result[0]['pwdmaxage'] : null;
+ $pwdExpireWarning = array_key_exists('pwdexpirewarning', $result[0]) ? $result[0]['pwdexpirewarning'] : null;
+
+ //handle grace login
+ $pwdGraceUseTimeCount = count($pwdGraceUseTime);
+ if($pwdGraceUseTime && $pwdGraceUseTimeCount > 0) { //was this a grace login?
+ if($pwdGraceAuthNLimit
+ && (count($pwdGraceAuthNLimit) > 0)
+ &&($pwdGraceUseTimeCount < intval($pwdGraceAuthNLimit[0]))) { //at least one more grace login available?
+ $this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
+ header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
+ 'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid)));
+ } else { //no more grace login available
+ header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
+ 'user_ldap.renewPassword.showLoginFormInvalidPassword', array('user' => $uid)));
+ }
+ exit();
+ }
+ //handle pwdReset attribute
+ if($pwdReset && (count($pwdReset) > 0) && $pwdReset[0] === 'TRUE') { //user must change his password
+ $this->config->setUserValue($uid, 'user_ldap', 'needsPasswordReset', 'true');
+ header('Location: '.\OC::$server->getURLGenerator()->linkToRouteAbsolute(
+ 'user_ldap.renewPassword.showRenewPasswordForm', array('user' => $uid)));
+ exit();
+ }
+ //handle password expiry warning
+ if($pwdChangedTime && (count($pwdChangedTime) > 0)) {
+ if($pwdMaxAge && (count($pwdMaxAge) > 0)
+ && $pwdExpireWarning && (count($pwdExpireWarning) > 0)) {
+ $pwdMaxAgeInt = intval($pwdMaxAge[0]);
+ $pwdExpireWarningInt = intval($pwdExpireWarning[0]);
+ if($pwdMaxAgeInt > 0 && $pwdExpireWarningInt > 0){
+ $pwdChangedTimeDt = \DateTime::createFromFormat('YmdHisZ', $pwdChangedTime[0]);
+ $pwdChangedTimeDt->add(new \DateInterval('PT'.$pwdMaxAgeInt.'S'));
+ $currentDateTime = new \DateTime();
+ $secondsToExpiry = $pwdChangedTimeDt->getTimestamp() - $currentDateTime->getTimestamp();
+ if($secondsToExpiry <= $pwdExpireWarningInt) {
+ //remove last password expiry warning if any
+ $notification = $this->notificationManager->createNotification();
+ $notification->setApp('user_ldap')
+ ->setUser($uid)
+ ->setObject('pwd_exp_warn', $uid)
+ ;
+ $this->notificationManager->markProcessed($notification);
+ //create new password expiry warning
+ $notification = $this->notificationManager->createNotification();
+ $notification->setApp('user_ldap')
+ ->setUser($uid)
+ ->setDateTime($currentDateTime)
+ ->setObject('pwd_exp_warn', $uid)
+ ->setSubject('pwd_exp_warn_days', [strval(ceil($secondsToExpiry / 60 / 60 / 24))])
+ ;
+ $this->notificationManager->notify($notification);
+ }
+ }
+ }
+ }
+ }
+ }
}
diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php
index fa959fd9a8..75cdb3951c 100644
--- a/apps/user_ldap/lib/User_LDAP.php
+++ b/apps/user_ldap/lib/User_LDAP.php
@@ -41,6 +41,7 @@ use OCA\User_LDAP\Exceptions\NotOnLDAP;
use OCA\User_LDAP\User\OfflineUser;
use OCA\User_LDAP\User\User;
use OCP\IConfig;
+use OCP\Notification\IManager as INotificationManager;
use OCP\Util;
class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP {
@@ -50,13 +51,18 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
/** @var \OCP\IConfig */
protected $ocConfig;
+ /** @var INotificationManager */
+ protected $notificationManager;
+
/**
* @param Access $access
* @param \OCP\IConfig $ocConfig
+ * @param \OCP\Notification\IManager $notificationManager
*/
- public function __construct(Access $access, IConfig $ocConfig) {
+ public function __construct(Access $access, IConfig $ocConfig, INotificationManager $notificationManager) {
parent::__construct($access);
$this->ocConfig = $ocConfig;
+ $this->notificationManager = $notificationManager;
}
/**
@@ -190,8 +196,19 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid .
'. Maybe the LDAP entry has no set display name attribute?');
}
- if($user->getUsername() !== false) {
- return $this->access->setPassword($user->getDN(), $password);
+ if($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
+ $ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN;
+ $turnOnPasswordChange = $this->access->connection->turnOnPasswordChange;
+ if (!empty($ldapDefaultPPolicyDN) && (intval($turnOnPasswordChange) === 1)) {
+ //remove last password expiry warning if any
+ $notification = $this->notificationManager->createNotification();
+ $notification->setApp('user_ldap')
+ ->setUser($uid)
+ ->setObject('pwd_exp_warn', $uid)
+ ;
+ $this->notificationManager->markProcessed($notification);
+ }
+ return true;
}
return false;
diff --git a/apps/user_ldap/lib/User_Proxy.php b/apps/user_ldap/lib/User_Proxy.php
index 6417841f24..8e81b10f7b 100644
--- a/apps/user_ldap/lib/User_Proxy.php
+++ b/apps/user_ldap/lib/User_Proxy.php
@@ -31,6 +31,7 @@ namespace OCA\User_LDAP;
use OCA\User_LDAP\User\User;
use OCP\IConfig;
+use OCP\Notification\IManager as INotificationManager;
class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP {
private $backends = array();
@@ -40,11 +41,12 @@ class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface,
* Constructor
* @param array $serverConfigPrefixes array containing the config Prefixes
*/
- public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig) {
+ public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig,
+ INotificationManager $notificationManager) {
parent::__construct($ldap);
foreach($serverConfigPrefixes as $configPrefix) {
$this->backends[$configPrefix] =
- new User_LDAP($this->getAccess($configPrefix), $ocConfig);
+ new User_LDAP($this->getAccess($configPrefix), $ocConfig, $notificationManager);
if(is_null($this->refBackend)) {
$this->refBackend = &$this->backends[$configPrefix];
}
diff --git a/apps/user_ldap/templates/renewpassword.php b/apps/user_ldap/templates/renewpassword.php
new file mode 100644
index 0000000000..7b1df75e06
--- /dev/null
+++ b/apps/user_ldap/templates/renewpassword.php
@@ -0,0 +1,73 @@
+
+
+
+
+
diff --git a/apps/user_ldap/templates/settings.php b/apps/user_ldap/templates/settings.php
index 6942b2eb2b..0d4ca804dd 100644
--- a/apps/user_ldap/templates/settings.php
+++ b/apps/user_ldap/templates/settings.php
@@ -103,6 +103,7 @@ style('user_ldap', 'settings');
t('(New password is sent as plain text to LDAP)'));?>
+
t('Special Attributes'));?>
diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php
index 271e8eb605..85f0516dec 100644
--- a/apps/user_ldap/tests/AccessTest.php
+++ b/apps/user_ldap/tests/AccessTest.php
@@ -42,6 +42,7 @@ use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Image;
use OCP\IUserManager;
+use OCP\Notification\IManager as INotificationManager;
/**
* Class AccessTest
@@ -89,7 +90,8 @@ class AccessTest extends \Test\TestCase {
$this->createMock(IAvatarManager::class),
$this->createMock(Image::class),
$this->createMock(IDBConnection::class),
- $this->createMock(IUserManager::class)])
+ $this->createMock(IUserManager::class),
+ $this->createMock(INotificationManager::class)])
->getMock();
$helper = new Helper(\OC::$server->getConfig());
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php
index 32fc2151a7..25b7cf83f9 100644
--- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestFetchUsersByLoginName.php
@@ -47,7 +47,7 @@ class IntegrationTestFetchUsersByLoginName extends AbstractIntegrationTest {
$this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
$this->mapping->clear();
$this->access->setUserMapper($this->mapping);
- $this->backend = new \OCA\User_LDAP\User_LDAP($this->access, \OC::$server->getConfig());
+ $this->backend = new \OCA\User_LDAP\User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager());
}
/**
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php
index 3826cbdae5..2f14b0d1c1 100644
--- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestPaging.php
@@ -44,7 +44,7 @@ class IntegrationTestPaging extends AbstractIntegrationTest {
require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
parent::init();
- $this->backend = new \OCA\User_LDAP\User_LDAP($this->access, \OC::$server->getConfig());
+ $this->backend = new \OCA\User_LDAP\User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager());
}
/**
diff --git a/apps/user_ldap/tests/Integration/Lib/IntegrationTestUserHome.php b/apps/user_ldap/tests/Integration/Lib/IntegrationTestUserHome.php
index 9db4cafea4..57c48fa18e 100644
--- a/apps/user_ldap/tests/Integration/Lib/IntegrationTestUserHome.php
+++ b/apps/user_ldap/tests/Integration/Lib/IntegrationTestUserHome.php
@@ -48,7 +48,7 @@ class IntegrationTestUserHome extends AbstractIntegrationTest {
$this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
$this->mapping->clear();
$this->access->setUserMapper($this->mapping);
- $this->backend = new \OCA\User_LDAP\User_LDAP($this->access, \OC::$server->getConfig());
+ $this->backend = new \OCA\User_LDAP\User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager());
}
/**
diff --git a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php
index 7c8f9475b4..3fb5a67591 100644
--- a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php
+++ b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserAvatar.php
@@ -45,7 +45,7 @@ class IntegrationTestUserAvatar extends AbstractIntegrationTest {
$this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
$this->mapping->clear();
$this->access->setUserMapper($this->mapping);
- $userBackend = new \OCA\User_LDAP\User_LDAP($this->access, \OC::$server->getConfig());
+ $userBackend = new \OCA\User_LDAP\User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager());
\OC_User::useBackend($userBackend);
}
@@ -130,7 +130,8 @@ class IntegrationTestUserAvatar extends AbstractIntegrationTest {
\OC::$server->getAvatarManager(),
new \OCP\Image(),
\OC::$server->getDatabaseConnection(),
- \OC::$server->getUserManager()
+ \OC::$server->getUserManager(),
+ \OC::$server->getNotificationManager()
);
}
diff --git a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php
index d0444daca5..616bf410e0 100644
--- a/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php
+++ b/apps/user_ldap/tests/Integration/Lib/User/IntegrationTestUserDisplayName.php
@@ -43,7 +43,7 @@ class IntegrationTestUserDisplayName extends AbstractIntegrationTest {
$this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
$this->mapping->clear();
$this->access->setUserMapper($this->mapping);
- $userBackend = new User_LDAP($this->access, \OC::$server->getConfig());
+ $userBackend = new User_LDAP($this->access, \OC::$server->getConfig(), \OC::$server->getNotificationManager());
\OC_User::useBackend($userBackend);
}
diff --git a/apps/user_ldap/tests/User/ManagerTest.php b/apps/user_ldap/tests/User/ManagerTest.php
index 16d6a3d9d6..823081f1da 100644
--- a/apps/user_ldap/tests/User/ManagerTest.php
+++ b/apps/user_ldap/tests/User/ManagerTest.php
@@ -36,6 +36,7 @@ use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Image;
use OCP\IUserManager;
+use OCP\Notification\IManager as INotificationManager;
/**
* Class Test_User_Manager
@@ -55,6 +56,7 @@ class ManagerTest extends \Test\TestCase {
$image = $this->createMock(Image::class);
$dbc = $this->createMock(IDBConnection::class);
$userMgr = $this->createMock(IUserManager::class);
+ $notiMgr = $this->createMock(INotificationManager::class);
$connection = new \OCA\User_LDAP\Connection(
$lw = $this->createMock(ILDAPWrapper::class),
@@ -66,11 +68,11 @@ class ManagerTest extends \Test\TestCase {
->method('getConnection')
->will($this->returnValue($connection));
- return array($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr);
+ return array($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr);
}
public function testGetByDNExisting() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
$inputDN = 'cn=foo,dc=foobar,dc=bar';
@@ -89,7 +91,7 @@ class ManagerTest extends \Test\TestCase {
$access->expects($this->never())
->method('username2dn');
- $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
+ $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr);
$manager->setLdapAccess($access);
$user = $manager->get($inputDN);
@@ -101,7 +103,7 @@ class ManagerTest extends \Test\TestCase {
}
public function testGetByEDirectoryDN() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
$inputDN = 'uid=foo,o=foobar,c=bar';
@@ -120,7 +122,7 @@ class ManagerTest extends \Test\TestCase {
$access->expects($this->never())
->method('username2dn');
- $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
+ $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr);
$manager->setLdapAccess($access);
$user = $manager->get($inputDN);
@@ -128,7 +130,7 @@ class ManagerTest extends \Test\TestCase {
}
public function testGetByExoticDN() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
$inputDN = 'ab=cde,f=ghei,mno=pq';
@@ -147,7 +149,7 @@ class ManagerTest extends \Test\TestCase {
$access->expects($this->never())
->method('username2dn');
- $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
+ $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr);
$manager->setLdapAccess($access);
$user = $manager->get($inputDN);
@@ -155,7 +157,7 @@ class ManagerTest extends \Test\TestCase {
}
public function testGetByDNNotExisting() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
$inputDN = 'cn=gone,dc=foobar,dc=bar';
@@ -175,7 +177,7 @@ class ManagerTest extends \Test\TestCase {
->with($this->equalTo($inputDN))
->will($this->returnValue(false));
- $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
+ $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr);
$manager->setLdapAccess($access);
$user = $manager->get($inputDN);
@@ -183,7 +185,7 @@ class ManagerTest extends \Test\TestCase {
}
public function testGetByUidExisting() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
$dn = 'cn=foo,dc=foobar,dc=bar';
@@ -202,7 +204,7 @@ class ManagerTest extends \Test\TestCase {
->with($this->equalTo($uid))
->will($this->returnValue(false));
- $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
+ $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr);
$manager->setLdapAccess($access);
$user = $manager->get($uid);
@@ -214,7 +216,7 @@ class ManagerTest extends \Test\TestCase {
}
public function testGetByUidNotExisting() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
$uid = 'gone';
@@ -227,7 +229,7 @@ class ManagerTest extends \Test\TestCase {
->with($this->equalTo($uid))
->will($this->returnValue(false));
- $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
+ $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr);
$manager->setLdapAccess($access);
$user = $manager->get($uid);
@@ -235,10 +237,10 @@ class ManagerTest extends \Test\TestCase {
}
public function testGetAttributesAll() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
+ $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr);
$manager->setLdapAccess($access);
$connection = $access->getConnection();
@@ -253,10 +255,10 @@ class ManagerTest extends \Test\TestCase {
}
public function testGetAttributesMinimal() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
- $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr);
+ $manager = new Manager($config, $filesys, $log, $avaMgr, $image, $dbc, $userMgr, $notiMgr);
$manager->setLdapAccess($access);
$attributes = $manager->getAttributes(true);
diff --git a/apps/user_ldap/tests/User/UserTest.php b/apps/user_ldap/tests/User/UserTest.php
index 6961e39d9f..0437051b13 100644
--- a/apps/user_ldap/tests/User/UserTest.php
+++ b/apps/user_ldap/tests/User/UserTest.php
@@ -37,6 +37,7 @@ use OCP\IDBConnection;
use OCP\Image;
use OCP\IUser;
use OCP\IUserManager;
+use OCP\Notification\IManager as INotificationManager;
/**
* Class UserTest
@@ -56,11 +57,12 @@ class UserTest extends \Test\TestCase {
$image = $this->createMock(Image::class);
$dbc = $this->createMock(IDBConnection::class);
$userMgr = $this->createMock(IUserManager::class);
+ $notiMgr = $this->createMock(INotificationManager::class);
- return array($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr);
+ return array($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr);
}
- private function getAdvancedMocks($cfMock, $fsMock, $logMock, $avaMgr, $dbc, $userMgr = null) {
+ private function getAdvancedMocks($cfMock, $fsMock, $logMock, $avaMgr, $dbc, $userMgr = null, $notiMgr = null) {
static $conMethods;
static $accMethods;
static $umMethods;
@@ -77,9 +79,12 @@ class UserTest extends \Test\TestCase {
if (is_null($userMgr)) {
$userMgr = $this->createMock(IUserManager::class);
}
+ if (is_null($notiMgr)) {
+ $notiMgr = $this->createMock(INotificationManager::class);
+ }
$um = $this->getMockBuilder('\OCA\User_LDAP\User\Manager')
->setMethods($umMethods)
- ->setConstructorArgs([$cfMock, $fsMock, $logMock, $avaMgr, $im, $dbc, $userMgr])
+ ->setConstructorArgs([$cfMock, $fsMock, $logMock, $avaMgr, $im, $dbc, $userMgr, $notiMgr])
->getMock();
$helper = new \OCA\User_LDAP\Helper(\OC::$server->getConfig());
$connector = $this->getMockBuilder('\OCA\User_LDAP\Connection')
@@ -95,25 +100,25 @@ class UserTest extends \Test\TestCase {
}
public function testGetDNandUsername() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr, $notiMgr) =
$this->getTestInstances();
$uid = 'alice';
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$this->assertSame($dn, $user->getDN());
$this->assertSame($uid, $user->getUsername());
}
public function testUpdateEmailProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc, $userMgr);
+ $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc, $userMgr, $notiMgr);
$connection->expects($this->once())
->method('__get')
@@ -140,13 +145,13 @@ class UserTest extends \Test\TestCase {
->method('get')
->willReturn($uuser);
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateEmail();
}
public function testUpdateEmailNotProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -170,13 +175,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateEmail();
}
public function testUpdateEmailNotConfigured() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -197,13 +202,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateEmail();
}
public function testUpdateQuotaAllProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -244,13 +249,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
public function testUpdateQuotaToDefaultAllProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -284,13 +289,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
public function testUpdateQuotaToNoneAllProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -324,13 +329,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
public function testUpdateQuotaDefaultProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -369,13 +374,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
public function testUpdateQuotaIndividualProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -416,13 +421,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
public function testUpdateQuotaNoneProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -464,13 +469,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
public function testUpdateQuotaNoneConfigured() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -510,13 +515,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
public function testUpdateQuotaFromValue() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -545,7 +550,7 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota($readQuota);
}
@@ -554,7 +559,7 @@ class UserTest extends \Test\TestCase {
* Unparseable quota will fallback to use the LDAP default
*/
public function testUpdateWrongQuotaAllProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -593,7 +598,7 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
@@ -602,7 +607,7 @@ class UserTest extends \Test\TestCase {
* No user quota and wrong default will set 'default' as quota
*/
public function testUpdateWrongDefaultQuotaProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -641,7 +646,7 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
@@ -650,7 +655,7 @@ class UserTest extends \Test\TestCase {
* Wrong user quota and wrong default will set 'default' as quota
*/
public function testUpdateWrongQuotaAndDefaultAllProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -689,7 +694,7 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
@@ -698,7 +703,7 @@ class UserTest extends \Test\TestCase {
* No quota attribute set and wrong default will set 'default' as quota
*/
public function testUpdateWrongDefaultQuotaNotProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -734,14 +739,14 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateQuota();
}
//the testUpdateAvatar series also implicitely tests getAvatarImage
public function testUpdateAvatarJpegPhotoProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -784,13 +789,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateAvatar();
}
public function testUpdateAvatarThumbnailPhotoProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -842,13 +847,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateAvatar();
}
public function testUpdateAvatarNotProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -888,13 +893,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->updateAvatar();
}
public function testUpdateBeforeFirstLogin() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -924,13 +929,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->update();
}
public function testUpdateAfterFirstLogin() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -964,13 +969,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->update();
}
public function testUpdateNoRefresh() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -1000,13 +1005,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->update();
}
public function testMarkLogin() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr, $notiMgr) =
$this->getTestInstances();
$config->expects($this->once())
@@ -1021,13 +1026,13 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->markLogin();
}
public function testGetAvatarImageProvided() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $db, $userMgr, $notiMgr) =
$this->getTestInstances();
$access->expects($this->once())
@@ -1040,7 +1045,7 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$photo = $user->getAvatarImage();
$this->assertSame('this is a photo', $photo);
@@ -1050,7 +1055,7 @@ class UserTest extends \Test\TestCase {
}
public function testProcessAttributes() {
- list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -1070,7 +1075,7 @@ class UserTest extends \Test\TestCase {
);
$userMock = $this->getMockBuilder('OCA\User_LDAP\User\User')
- ->setConstructorArgs(array($uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr))
+ ->setConstructorArgs(array($uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr))
->setMethods($requiredMethods)
->getMock();
@@ -1102,7 +1107,7 @@ class UserTest extends \Test\TestCase {
$userMock->expects($this->once())
->method($method);
}
-
+ \OC_Hook::clear();//disconnect irrelevant hooks
$userMock->processAttributes($record);
\OC_Hook::emit('OC_User', 'post_login', array('uid' => $uid));
}
@@ -1118,7 +1123,7 @@ class UserTest extends \Test\TestCase {
* @dataProvider emptyHomeFolderAttributeValueProvider
*/
public function testGetHomePathNotConfigured($attributeValue) {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -1139,14 +1144,14 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$path = $user->getHomePath();
$this->assertSame($path, false);
}
public function testGetHomePathConfiguredNotAvailableAllowed() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
@@ -1170,7 +1175,7 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$path = $user->getHomePath();
@@ -1181,11 +1186,11 @@ class UserTest extends \Test\TestCase {
* @expectedException \Exception
*/
public function testGetHomePathConfiguredNotAvailableNotAllowed() {
- list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
$this->getTestInstances();
list($access, $connection) =
- $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc, $userMgr);
+ $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc, $userMgr, $notiMgr);
$connection->expects($this->any())
->method('__get')
@@ -1205,7 +1210,7 @@ class UserTest extends \Test\TestCase {
$dn = 'uid=alice,dc=foo,dc=bar';
$user = new User(
- $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$user->getHomePath();
}
@@ -1222,16 +1227,161 @@ class UserTest extends \Test\TestCase {
* @dataProvider displayNameProvider
*/
public function testComposeAndStoreDisplayName($part1, $part2, $expected) {
- list($access, $config, $filesys, $image, $log, $avaMgr, , $userMgr) =
+ list($access, $config, $filesys, $image, $log, $avaMgr, , $userMgr, $notiMgr) =
$this->getTestInstances();
$config->expects($this->once())
->method('setUserValue');
$user = new User(
- 'user', 'cn=user', $access, $config, $filesys, $image, $log, $avaMgr, $userMgr);
+ 'user', 'cn=user', $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
$displayName = $user->composeAndStoreDisplayName($part1, $part2);
$this->assertSame($expected, $displayName);
}
+
+ public function testHandlePasswordExpiryWarningDefaultPolicy() {
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ $this->getTestInstances();
+
+ list($access, $connection) =
+ $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
+
+ $uid = 'alice';
+ $dn = 'uid=alice';
+
+ $connection->expects($this->any())
+ ->method('__get')
+ ->will($this->returnCallback(function($name) {
+ if($name === 'ldapDefaultPPolicyDN') {
+ return 'cn=default,ou=policies,dc=foo,dc=bar';
+ }
+ if($name === 'turnOnPasswordChange') {
+ return '1';
+ }
+ return $name;
+ }));
+
+ $access->expects($this->any())
+ ->method('search')
+ ->will($this->returnCallback(function($filter, $base) {
+ if($base === 'uid=alice') {
+ return array(
+ array(
+ 'pwdchangedtime' => array((new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'),
+ ),
+ );
+ }
+ if($base === 'cn=default,ou=policies,dc=foo,dc=bar') {
+ return array(
+ array(
+ 'pwdmaxage' => array('2592000'),
+ 'pwdexpirewarning' => array('2591999'),
+ ),
+ );
+ }
+ return array();
+ }));
+
+ $notification = $this->getMockBuilder('OCP\Notification\INotification')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $notification->expects($this->any())
+ ->method('setApp')
+ ->will($this->returnValue($notification));
+ $notification->expects($this->any())
+ ->method('setUser')
+ ->will($this->returnValue($notification));
+ $notification->expects($this->any())
+ ->method('setObject')
+ ->will($this->returnValue($notification));
+ $notification->expects($this->any())
+ ->method('setDateTime')
+ ->will($this->returnValue($notification));
+ $notiMgr->expects($this->exactly(2))
+ ->method('createNotification')
+ ->will($this->returnValue($notification));
+ $notiMgr->expects($this->exactly(1))
+ ->method('notify');
+
+ $user = new User(
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+
+ \OC_Hook::clear();//disconnect irrelevant hooks
+ \OCP\Util::connectHook('OC_User', 'post_login', $user, 'handlePasswordExpiry');
+ \OC_Hook::emit('OC_User', 'post_login', array('uid' => $uid));
+ }
+
+ public function testHandlePasswordExpiryWarningCustomPolicy() {
+ list(, $config, $filesys, $image, $log, $avaMgr, $dbc, $userMgr, $notiMgr) =
+ $this->getTestInstances();
+
+ list($access, $connection) =
+ $this->getAdvancedMocks($config, $filesys, $log, $avaMgr, $dbc);
+
+ $uid = 'alice';
+ $dn = 'uid=alice';
+
+ $connection->expects($this->any())
+ ->method('__get')
+ ->will($this->returnCallback(function($name) {
+ if($name === 'ldapDefaultPPolicyDN') {
+ return 'cn=default,ou=policies,dc=foo,dc=bar';
+ }
+ if($name === 'turnOnPasswordChange') {
+ return '1';
+ }
+ return $name;
+ }));
+
+ $access->expects($this->any())
+ ->method('search')
+ ->will($this->returnCallback(function($filter, $base) {
+ if($base === 'uid=alice') {
+ return array(
+ array(
+ 'pwdpolicysubentry' => array('cn=custom,ou=policies,dc=foo,dc=bar'),
+ 'pwdchangedtime' => array((new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'),
+ )
+ );
+ }
+ if($base === 'cn=custom,ou=policies,dc=foo,dc=bar') {
+ return array(
+ array(
+ 'pwdmaxage' => array('2592000'),
+ 'pwdexpirewarning' => array('2591999'),
+ )
+ );
+ }
+ return array();
+ }));
+
+ $notification = $this->getMockBuilder('OCP\Notification\INotification')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $notification->expects($this->any())
+ ->method('setApp')
+ ->will($this->returnValue($notification));
+ $notification->expects($this->any())
+ ->method('setUser')
+ ->will($this->returnValue($notification));
+ $notification->expects($this->any())
+ ->method('setObject')
+ ->will($this->returnValue($notification));
+ $notification->expects($this->any())
+ ->method('setDateTime')
+ ->will($this->returnValue($notification));
+ $notiMgr->expects($this->exactly(2))
+ ->method('createNotification')
+ ->will($this->returnValue($notification));
+ $notiMgr->expects($this->exactly(1))
+ ->method('notify');
+
+ $user = new User(
+ $uid, $dn, $access, $config, $filesys, $image, $log, $avaMgr, $userMgr, $notiMgr);
+
+ \OC_Hook::clear();//disconnect irrelevant hooks
+ \OCP\Util::connectHook('OC_User', 'post_login', $user, 'handlePasswordExpiry');
+ \OC_Hook::emit('OC_User', 'post_login', array('uid' => $uid));
+ }
}
diff --git a/apps/user_ldap/tests/User_LDAPTest.php b/apps/user_ldap/tests/User_LDAPTest.php
index 1b1f9fdec7..aaf67ebcab 100644
--- a/apps/user_ldap/tests/User_LDAPTest.php
+++ b/apps/user_ldap/tests/User_LDAPTest.php
@@ -47,6 +47,7 @@ use OCP\IDBConnection;
use OCP\Image;
use OCP\IUserManager;
use Test\TestCase;
+use OCP\Notification\IManager as INotificationManager;
/**
* Class Test_User_Ldap_Direct
@@ -92,7 +93,8 @@ class User_LDAPTest extends TestCase {
$this->createMock(IAvatarManager::class),
$this->createMock(Image::class),
$this->createMock(IDBConnection::class),
- $this->createMock(IUserManager::class)
+ $this->createMock(IUserManager::class),
+ $this->createMock(INotificationManager::class)
])
->getMock();
@@ -197,7 +199,7 @@ class User_LDAPTest extends TestCase {
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
\OC_User::useBackend($backend);
$result = $backend->checkPassword('roland', 'dt19');
@@ -208,7 +210,7 @@ class User_LDAPTest extends TestCase {
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
\OC_User::useBackend($backend);
$result = $backend->checkPassword('roland', 'wrong');
@@ -219,7 +221,7 @@ class User_LDAPTest extends TestCase {
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
\OC_User::useBackend($backend);
$result = $backend->checkPassword('mallory', 'evil');
@@ -234,7 +236,7 @@ class User_LDAPTest extends TestCase {
->method('username2dn')
->will($this->returnValue(false));
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
\OC_User::useBackend($backend);
$result = $backend->checkPassword('roland', 'dt19');
@@ -244,7 +246,7 @@ class User_LDAPTest extends TestCase {
public function testCheckPasswordPublicAPI() {
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
\OC_User::useBackend($backend);
$result = \OCP\User::checkPassword('roland', 'dt19');
@@ -254,7 +256,7 @@ class User_LDAPTest extends TestCase {
public function testCheckPasswordPublicAPIWrongPassword() {
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
\OC_User::useBackend($backend);
$result = \OCP\User::checkPassword('roland', 'wrong');
@@ -264,7 +266,7 @@ class User_LDAPTest extends TestCase {
public function testCheckPasswordPublicAPIWrongUser() {
$access = $this->getAccessMock();
$this->prepareAccessForCheckPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
\OC_User::useBackend($backend);
$result = \OCP\User::checkPassword('mallory', 'evil');
@@ -273,7 +275,7 @@ class User_LDAPTest extends TestCase {
public function testDeleteUserCancel() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$result = $backend->deleteUser('notme');
$this->assertFalse($result);
}
@@ -295,7 +297,7 @@ class User_LDAPTest extends TestCase {
->method('getUserValue')
->will($this->onConsecutiveCalls('1', '/var/vhome/jdings/'));
- $backend = new UserLDAP($access, $config);
+ $backend = new UserLDAP($access, $config, $this->createMock(INotificationManager::class));
$result = $backend->deleteUser('jeremy');
$this->assertTrue($result);
@@ -356,7 +358,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersNoParam() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$result = $backend->getUsers();
$this->assertEquals(3, count($result));
@@ -365,7 +367,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersLimitOffset() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$result = $backend->getUsers('', 1, 2);
$this->assertEquals(1, count($result));
@@ -374,7 +376,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersLimitOffset2() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$result = $backend->getUsers('', 2, 1);
$this->assertEquals(2, count($result));
@@ -383,7 +385,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersSearchWithResult() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$result = $backend->getUsers('yo');
$this->assertEquals(2, count($result));
@@ -392,7 +394,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersSearchEmptyResult() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$result = $backend->getUsers('nix');
$this->assertEquals(0, count($result));
@@ -401,7 +403,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersViaAPINoParam() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
\OC_User::useBackend($backend);
$result = \OCP\User::getUsers();
@@ -411,7 +413,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersViaAPILimitOffset() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
\OC_User::useBackend($backend);
$result = \OCP\User::getUsers('', 1, 2);
@@ -421,7 +423,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersViaAPILimitOffset2() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
\OC_User::useBackend($backend);
$result = \OCP\User::getUsers('', 2, 1);
@@ -431,7 +433,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersViaAPISearchWithResult() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
\OC_User::useBackend($backend);
$result = \OCP\User::getUsers('yo');
@@ -441,7 +443,7 @@ class User_LDAPTest extends TestCase {
public function testGetUsersViaAPISearchEmptyResult() {
$access = $this->getAccessMock();
$this->prepareAccessForGetUsers($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
\OC_User::useBackend($backend);
$result = \OCP\User::getUsers('nix');
@@ -450,7 +452,7 @@ class User_LDAPTest extends TestCase {
public function testUserExists() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$this->prepareMockForUserExists($access);
$access->expects($this->any())
@@ -472,7 +474,7 @@ class User_LDAPTest extends TestCase {
*/
public function testUserExistsForDeleted() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$this->prepareMockForUserExists($access);
$access->expects($this->any())
@@ -490,7 +492,7 @@ class User_LDAPTest extends TestCase {
public function testUserExistsForNeverExisting() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$this->prepareMockForUserExists($access);
$access->expects($this->any())
@@ -509,7 +511,7 @@ class User_LDAPTest extends TestCase {
public function testUserExistsPublicAPI() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$this->prepareMockForUserExists($access);
\OC_User::useBackend($backend);
@@ -532,7 +534,7 @@ class User_LDAPTest extends TestCase {
*/
public function testUserExistsPublicAPIForDeleted() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$this->prepareMockForUserExists($access);
\OC_User::useBackend($backend);
@@ -551,7 +553,7 @@ class User_LDAPTest extends TestCase {
public function testUserExistsPublicAPIForNeverExisting() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$this->prepareMockForUserExists($access);
\OC_User::useBackend($backend);
@@ -571,7 +573,7 @@ class User_LDAPTest extends TestCase {
public function testDeleteUser() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
//we do not support deleting users at all
$result = $backend->deleteUser('gunslinger');
@@ -581,7 +583,8 @@ class User_LDAPTest extends TestCase {
public function testGetHomeAbsolutePath() {
$access = $this->getAccessMock();
$config = $this->createMock(IConfig::class);
- $backend = new UserLDAP($access, $config);
+ $noti = $this->createMock(INotificationManager::class);
+ $backend = new UserLDAP($access, $config, $noti);
$this->prepareMockForUserExists($access);
$access->connection->expects($this->any())
@@ -616,7 +619,8 @@ class User_LDAPTest extends TestCase {
public function testGetHomeRelative() {
$access = $this->getAccessMock();
$config = $this->createMock(IConfig::class);
- $backend = new UserLDAP($access, $config);
+ $noti = $this->createMock(INotificationManager::class);
+ $backend = new UserLDAP($access, $config, $noti);
$this->prepareMockForUserExists($access);
$dataDir = \OC::$server->getConfig()->getSystemValue(
@@ -659,7 +663,7 @@ class User_LDAPTest extends TestCase {
*/
public function testGetHomeNoPath() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$this->prepareMockForUserExists($access);
$access->connection->expects($this->any())
@@ -690,7 +694,7 @@ class User_LDAPTest extends TestCase {
*/
public function testGetHomeDeletedUser() {
$access = $this->getAccessMock();
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$this->prepareMockForUserExists($access);
$access->connection->expects($this->any())
@@ -761,7 +765,7 @@ class User_LDAPTest extends TestCase {
public function testGetDisplayName() {
$access = $this->getAccessMock();
$this->prepareAccessForGetDisplayName($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$this->prepareMockForUserExists($access);
$access->connection->expects($this->any())
@@ -802,7 +806,7 @@ class User_LDAPTest extends TestCase {
}
}));
$this->prepareAccessForGetDisplayName($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$this->prepareMockForUserExists($access);
$access->connection->expects($this->any())
@@ -832,7 +836,7 @@ class User_LDAPTest extends TestCase {
->method('countUsers')
->will($this->returnValue(5));
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$result = $backend->countUsers();
$this->assertEquals(5, $result);
@@ -845,7 +849,7 @@ class User_LDAPTest extends TestCase {
->method('countUsers')
->will($this->returnValue(false));
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$result = $backend->countUsers();
$this->assertFalse($result);
@@ -878,7 +882,7 @@ class User_LDAPTest extends TestCase {
->method('writeToCache')
->with($this->equalTo('loginName2UserName-'.$loginName), $this->equalTo($username));
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$name = $backend->loginName2UserName($loginName);
$this->assertSame($username, $name);
@@ -907,7 +911,7 @@ class User_LDAPTest extends TestCase {
->method('writeToCache')
->with($this->equalTo('loginName2UserName-'.$loginName), false);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$name = $backend->loginName2UserName($loginName);
$this->assertSame(false, $name);
@@ -954,7 +958,7 @@ class User_LDAPTest extends TestCase {
->method('getUserValue')
->willReturn(1);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
$name = $backend->loginName2UserName($loginName);
$this->assertSame(false, $name);
@@ -1035,7 +1039,7 @@ class User_LDAPTest extends TestCase {
$access = $this->getAccessMock();
$this->prepareAccessForSetPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
\OC_User::useBackend($backend);
$this->assertTrue(\OC_User::setPassword('roland', 'dt'));
@@ -1045,17 +1049,17 @@ class User_LDAPTest extends TestCase {
$access = $this->getAccessMock();
$this->prepareAccessForSetPassword($access);
- $backend = new UserLDAP($access, $this->createMock(IConfig::class));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::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));
+ $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class));
\OC_User::useBackend($backend);
$this->assertFalse(\OC_User::setPassword('roland', 'dt12234$'));
@@ -1074,9 +1078,11 @@ class User_LDAPTest extends TestCase {
->with('NotExistingUser')
->willReturn(null);
$config = $this->createMock(IConfig::class);
+ $noti = $this->createMock(INotificationManager::class);
$ldap = new User_LDAP(
$access,
- $config
+ $config,
+ $noti
);
$ldap->setPassword('NotExistingUser', 'Password');
}
@@ -1095,9 +1101,11 @@ class User_LDAPTest extends TestCase {
->with('NotExistingUser')
->willReturn($user);
$config = $this->createMock(IConfig::class);
+ $noti = $this->createMock(INotificationManager::class);
$ldap = new User_LDAP(
$access,
- $config
+ $config,
+ $noti
);
$this->assertFalse($ldap->setPassword('NotExistingUser', 'Password'));
}
diff --git a/apps/user_ldap/tests/User_ProxyTest.php b/apps/user_ldap/tests/User_ProxyTest.php
index 6d779d758e..df021a6de3 100644
--- a/apps/user_ldap/tests/User_ProxyTest.php
+++ b/apps/user_ldap/tests/User_ProxyTest.php
@@ -24,6 +24,7 @@ namespace OCA\User_LDAP\Tests;
use OCA\User_LDAP\ILDAPWrapper;
use OCA\User_LDAP\User_Proxy;
use OCP\IConfig;
+use OCP\Notification\IManager as INotificationManager;
use Test\TestCase;
class User_ProxyTest extends TestCase {
@@ -31,6 +32,8 @@ class User_ProxyTest extends TestCase {
private $ldapWrapper;
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
private $config;
+ /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */
+ private $notificationManager;
/** @var User_Proxy|\PHPUnit_Framework_MockObject_MockObject */
private $proxy;
@@ -39,11 +42,13 @@ class User_ProxyTest extends TestCase {
$this->ldapWrapper = $this->createMock(ILDAPWrapper::class);
$this->config = $this->createMock(IConfig::class);
+ $this->notificationManager = $this->createMock(INotificationManager::class);
$this->proxy = $this->getMockBuilder(User_Proxy::class)
->setConstructorArgs([
[],
$this->ldapWrapper,
$this->config,
+ $this->notificationManager,
])
->setMethods(['handleRequest'])
->getMock();
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index c58d9f5852..44c42d353e 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -19,3 +19,5 @@ if (!class_exists('PHPUnit_Framework_TestCase')) {
}
OC_Hook::clear();
+
+set_include_path(get_include_path() . PATH_SEPARATOR . '/usr/share/php');