2014-03-27 17:01:14 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 14:49:16 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2016-07-21 14:49:16 +00:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Juan Pablo Villafáñez <jvillafanez@solidgear.es>
|
2015-03-26 10:44:34 +00:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
* @author Roger Szabo <roger.szabo@web.de>
|
2016-01-12 14:02:16 +00:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Victor Dubiniuk <dubiniuk@owncloud.com>
|
2015-03-26 10:44:34 +00:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2015-02-26 10:37:37 +00:00
|
|
|
|
2016-05-12 09:25:50 +00:00
|
|
|
namespace OCA\User_LDAP\Tests\User;
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
use OCA\User_LDAP\Access;
|
|
|
|
use OCA\User_LDAP\Connection;
|
2016-09-02 09:02:12 +00:00
|
|
|
use OCA\User_LDAP\FilesystemHelper;
|
|
|
|
use OCA\User_LDAP\LogWrapper;
|
2016-05-12 09:25:50 +00:00
|
|
|
use OCA\User_LDAP\User\User;
|
2016-09-02 09:02:12 +00:00
|
|
|
use OCP\IAvatar;
|
|
|
|
use OCP\IAvatarManager;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\Image;
|
|
|
|
use OCP\IUser;
|
2016-01-19 14:48:38 +00:00
|
|
|
use OCP\IUserManager;
|
2017-03-31 07:16:22 +00:00
|
|
|
use OCP\Notification\IManager as INotificationManager;
|
2017-10-24 13:26:53 +00:00
|
|
|
use OCP\Notification\INotification;
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2015-11-25 15:58:54 +00:00
|
|
|
/**
|
2016-05-12 15:14:59 +00:00
|
|
|
* Class UserTest
|
2015-11-25 15:58:54 +00:00
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
2016-05-12 15:14:59 +00:00
|
|
|
* @package OCA\User_LDAP\Tests\User
|
2015-11-25 15:58:54 +00:00
|
|
|
*/
|
2016-05-12 09:25:50 +00:00
|
|
|
class UserTest extends \Test\TestCase {
|
2017-11-03 16:40:05 +00:00
|
|
|
/** @var Access|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $access;
|
|
|
|
/** @var Connection|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $connection;
|
2018-07-02 15:38:16 +00:00
|
|
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $config;
|
|
|
|
/** @var FilesystemHelper|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $filesystemhelper;
|
|
|
|
/** @var INotificationManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $notificationManager;
|
|
|
|
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $userManager;
|
|
|
|
/** @var Image|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $image;
|
|
|
|
/** @var IAvatarManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $avatarManager;
|
|
|
|
/** @var LogWrapper|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $log;
|
|
|
|
/** @var string */
|
|
|
|
protected $uid = 'alice';
|
|
|
|
/** @var string */
|
|
|
|
protected $dn = 'uid=alice,dc=foo,dc=bar';
|
|
|
|
/** @var User */
|
|
|
|
protected $user;
|
2017-11-03 16:40:05 +00:00
|
|
|
|
|
|
|
public function setUp() {
|
2018-07-02 15:38:16 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection = $this->createMock(Connection::class);
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->access = $this->createMock(Access::class);
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->connection = $this->connection;
|
|
|
|
$this->access->expects($this->any())
|
|
|
|
->method('getConnection')
|
|
|
|
->willReturn($this->connection);
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
|
|
$this->filesystemhelper = $this->createMock(FilesystemHelper::class);
|
|
|
|
$this->log = $this->createMock(LogWrapper::class);
|
|
|
|
$this->avatarManager = $this->createMock(IAvatarManager::class);
|
|
|
|
$this->image = $this->createMock(Image::class);
|
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
|
|
|
$this->notificationManager = $this->createMock(INotificationManager::class);
|
|
|
|
|
|
|
|
$this->user = new User(
|
|
|
|
$this->uid,
|
|
|
|
$this->dn,
|
|
|
|
$this->access,
|
|
|
|
$this->config,
|
|
|
|
$this->filesystemhelper,
|
|
|
|
$this->image,
|
|
|
|
$this->log,
|
|
|
|
$this->avatarManager,
|
|
|
|
$this->userManager,
|
|
|
|
$this->notificationManager
|
|
|
|
);
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetDNandUsername() {
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->assertSame($this->dn, $this->user->getDN());
|
|
|
|
$this->assertSame($this->uid, $this->user->getUsername());
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateEmailProvided() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('__get')
|
|
|
|
->with($this->equalTo('ldapEmailAttribute'))
|
|
|
|
->will($this->returnValue('email'));
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('readAttribute')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->dn),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo('email'))
|
2018-07-02 15:38:16 +00:00
|
|
|
->will($this->returnValue(['alice@foo.bar']));
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$coreUser = $this->getMockBuilder(IUser::class)
|
2016-01-19 14:48:38 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2018-07-02 15:38:16 +00:00
|
|
|
$coreUser->expects($this->once())
|
2016-01-19 14:48:38 +00:00
|
|
|
->method('setEMailAddress')
|
|
|
|
->with('alice@foo.bar');
|
2018-07-02 15:38:16 +00:00
|
|
|
|
|
|
|
$this->userManager->expects($this->any())
|
2016-01-19 14:48:38 +00:00
|
|
|
->method('get')
|
2018-07-02 15:38:16 +00:00
|
|
|
->willReturn($coreUser);
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateEmail();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateEmailNotProvided() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('__get')
|
|
|
|
->with($this->equalTo('ldapEmailAttribute'))
|
|
|
|
->will($this->returnValue('email'));
|
2018-07-02 15:38:16 +00:00
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('readAttribute')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->dn),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo('email'))
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->never())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('setUserValue');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateEmail();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateEmailNotConfigured() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('__get')
|
|
|
|
->with($this->equalTo('ldapEmailAttribute'))
|
|
|
|
->will($this->returnValue(''));
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->never())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('readAttribute');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->never())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('setUserValue');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateEmail();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateQuotaAllProvided() {
|
2018-06-27 23:11:36 +00:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('__get')
|
2018-06-27 23:11:36 +00:00
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '']
|
|
|
|
]);
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('readAttribute')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->dn),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo('myquota'))
|
2018-07-02 15:38:16 +00:00
|
|
|
->will($this->returnValue(['42 GB']));
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->once())
|
2016-02-09 17:11:30 +00:00
|
|
|
->method('setQuota')
|
|
|
|
->with('42 GB');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->userManager->expects($this->atLeastOnce())
|
2016-02-09 17:11:30 +00:00
|
|
|
->method('get')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->uid)
|
|
|
|
->will($this->returnValue($coreUser));
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateQuota();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 12:02:08 +00:00
|
|
|
public function testUpdateQuotaToDefaultAllProvided() {
|
2018-06-27 23:11:36 +00:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2017-03-17 12:02:08 +00:00
|
|
|
->method('__get')
|
2018-06-27 23:11:36 +00:00
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '']
|
|
|
|
]);
|
2017-03-17 12:02:08 +00:00
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->once())
|
2017-03-17 12:02:08 +00:00
|
|
|
->method('readAttribute')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->dn),
|
2017-03-17 12:02:08 +00:00
|
|
|
$this->equalTo('myquota'))
|
2018-07-02 15:38:16 +00:00
|
|
|
->will($this->returnValue(['default']));
|
2017-03-17 12:02:08 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->once())
|
2017-03-17 12:02:08 +00:00
|
|
|
->method('setQuota')
|
|
|
|
->with('default');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->userManager->expects($this->once())
|
2017-03-17 12:02:08 +00:00
|
|
|
->method('get')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->uid)
|
|
|
|
->will($this->returnValue($coreUser));
|
2017-03-17 12:02:08 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateQuota();
|
2017-03-17 12:02:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateQuotaToNoneAllProvided() {
|
2018-06-27 23:11:36 +00:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2017-03-17 12:02:08 +00:00
|
|
|
->method('__get')
|
2018-06-27 23:11:36 +00:00
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '']
|
|
|
|
]);
|
2017-03-17 12:02:08 +00:00
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->once())
|
2017-03-17 12:02:08 +00:00
|
|
|
->method('readAttribute')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->dn),
|
2017-03-17 12:02:08 +00:00
|
|
|
$this->equalTo('myquota'))
|
2018-07-02 15:38:16 +00:00
|
|
|
->will($this->returnValue(['none']));
|
2017-03-17 12:02:08 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->once())
|
2017-03-17 12:02:08 +00:00
|
|
|
->method('setQuota')
|
|
|
|
->with('none');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->userManager->expects($this->once())
|
2017-03-17 12:02:08 +00:00
|
|
|
->method('get')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->uid)
|
|
|
|
->will($this->returnValue($coreUser));
|
2017-03-17 12:02:08 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateQuota();
|
2017-03-17 12:02:08 +00:00
|
|
|
}
|
|
|
|
|
2014-03-27 17:01:14 +00:00
|
|
|
public function testUpdateQuotaDefaultProvided() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->at(0))
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('__get')
|
2017-03-15 07:55:14 +00:00
|
|
|
->with($this->equalTo('ldapQuotaAttribute'))
|
|
|
|
->will($this->returnValue('myquota'));
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->at(1))
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('__get')
|
2017-03-15 07:55:14 +00:00
|
|
|
->with($this->equalTo('ldapQuotaDefault'))
|
|
|
|
->will($this->returnValue('25 GB'));
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('__get');
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('readAttribute')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->dn),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo('myquota'))
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->once())
|
2016-02-09 17:11:30 +00:00
|
|
|
->method('setQuota')
|
|
|
|
->with('25 GB');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->userManager->expects($this->once())
|
2016-02-09 17:11:30 +00:00
|
|
|
->method('get')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->uid)
|
|
|
|
->will($this->returnValue($coreUser));
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateQuota();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateQuotaIndividualProvided() {
|
2018-06-27 23:11:36 +00:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('__get')
|
2018-06-27 23:11:36 +00:00
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '']
|
|
|
|
]);
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('readAttribute')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->dn),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo('myquota'))
|
2018-07-02 15:38:16 +00:00
|
|
|
->will($this->returnValue(['27 GB']));
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->once())
|
2016-02-09 17:11:30 +00:00
|
|
|
->method('setQuota')
|
|
|
|
->with('27 GB');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->userManager->expects($this->once())
|
2016-02-09 17:11:30 +00:00
|
|
|
->method('get')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->uid)
|
|
|
|
->will($this->returnValue($coreUser));
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateQuota();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateQuotaNoneProvided() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2018-06-27 23:11:36 +00:00
|
|
|
->method('__get')
|
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '']
|
|
|
|
]);
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('readAttribute')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->dn),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo('myquota'))
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->never())
|
2017-08-16 09:10:23 +00:00
|
|
|
->method('setQuota');
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->userManager->expects($this->never())
|
2017-03-16 11:22:02 +00:00
|
|
|
->method('get')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->uid);
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->never())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('setUserValue');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateQuota();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateQuotaNoneConfigured() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2018-06-27 23:11:36 +00:00
|
|
|
->method('__get')
|
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', ''],
|
|
|
|
['ldapQuotaDefault', '']
|
|
|
|
]);
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->never())
|
2017-08-16 09:10:23 +00:00
|
|
|
->method('setQuota');
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->userManager->expects($this->never())
|
2018-06-27 23:11:36 +00:00
|
|
|
->method('get');
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->never())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('readAttribute');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->never())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('setUserValue');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateQuota();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 14:19:45 +00:00
|
|
|
public function testUpdateQuotaFromValue() {
|
|
|
|
$readQuota = '19 GB';
|
|
|
|
|
2018-06-27 23:11:36 +00:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2015-09-29 14:19:45 +00:00
|
|
|
->method('__get')
|
2018-06-27 23:11:36 +00:00
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '']
|
|
|
|
]);
|
2015-09-29 14:19:45 +00:00
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->never())
|
2015-09-29 14:19:45 +00:00
|
|
|
->method('readAttribute');
|
|
|
|
|
2016-09-02 09:02:12 +00:00
|
|
|
$user = $this->createMock(IUser::class);
|
2016-02-09 17:11:30 +00:00
|
|
|
$user->expects($this->once())
|
|
|
|
->method('setQuota')
|
|
|
|
->with($readQuota);
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->userManager->expects($this->once())
|
2016-02-09 17:11:30 +00:00
|
|
|
->method('get')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->uid)
|
2016-02-09 17:11:30 +00:00
|
|
|
->will($this->returnValue($user));
|
2015-09-29 14:19:45 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateQuota($readQuota);
|
2015-09-29 14:19:45 +00:00
|
|
|
}
|
|
|
|
|
2017-03-16 11:22:02 +00:00
|
|
|
/**
|
|
|
|
* Unparseable quota will fallback to use the LDAP default
|
|
|
|
*/
|
|
|
|
public function testUpdateWrongQuotaAllProvided() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2018-06-27 23:11:36 +00:00
|
|
|
->method('__get')
|
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '23 GB']
|
|
|
|
]);
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->once())
|
2017-03-16 11:22:02 +00:00
|
|
|
->method('readAttribute')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->dn),
|
2017-03-16 11:22:02 +00:00
|
|
|
$this->equalTo('myquota'))
|
2018-07-02 15:38:16 +00:00
|
|
|
->will($this->returnValue(['42 GBwos']));
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->once())
|
2017-03-16 11:22:02 +00:00
|
|
|
->method('setQuota')
|
|
|
|
->with('23 GB');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->userManager->expects($this->once())
|
2017-03-16 11:22:02 +00:00
|
|
|
->method('get')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->uid)
|
|
|
|
->will($this->returnValue($coreUser));
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateQuota();
|
2017-03-16 11:22:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* No user quota and wrong default will set 'default' as quota
|
|
|
|
*/
|
|
|
|
public function testUpdateWrongDefaultQuotaProvided() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2018-06-27 23:11:36 +00:00
|
|
|
->method('__get')
|
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '23 GBwowowo']
|
|
|
|
]);
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->once())
|
2017-03-16 11:22:02 +00:00
|
|
|
->method('readAttribute')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->dn),
|
2017-03-16 11:22:02 +00:00
|
|
|
$this->equalTo('myquota'))
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->never())
|
2017-08-16 09:10:23 +00:00
|
|
|
->method('setQuota');
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->userManager->expects($this->never())
|
2018-06-27 23:11:36 +00:00
|
|
|
->method('get');
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateQuota();
|
2017-03-16 11:22:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrong user quota and wrong default will set 'default' as quota
|
|
|
|
*/
|
|
|
|
public function testUpdateWrongQuotaAndDefaultAllProvided() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2018-06-27 23:11:36 +00:00
|
|
|
->method('__get')
|
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '23 GBwowowo']
|
|
|
|
]);
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->once())
|
2017-03-16 11:22:02 +00:00
|
|
|
->method('readAttribute')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->dn),
|
2017-03-16 11:22:02 +00:00
|
|
|
$this->equalTo('myquota'))
|
2018-07-02 15:38:16 +00:00
|
|
|
->will($this->returnValue(['23 flush']));
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->never())
|
2017-08-16 09:10:23 +00:00
|
|
|
->method('setQuota');
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->userManager->expects($this->never())
|
2018-06-27 23:11:36 +00:00
|
|
|
->method('get');
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateQuota();
|
2017-03-16 11:22:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* No quota attribute set and wrong default will set 'default' as quota
|
|
|
|
*/
|
|
|
|
public function testUpdateWrongDefaultQuotaNotProvided() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2018-06-27 23:11:36 +00:00
|
|
|
->method('__get')
|
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', ''],
|
|
|
|
['ldapQuotaDefault', '23 GBwowowo']
|
|
|
|
]);
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->never())
|
2017-03-16 11:22:02 +00:00
|
|
|
->method('readAttribute');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->never())
|
2017-08-16 09:10:23 +00:00
|
|
|
->method('setQuota');
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->userManager->expects($this->never())
|
2018-06-27 23:11:36 +00:00
|
|
|
->method('get');
|
2017-03-16 11:22:02 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateQuota();
|
2017-03-16 11:22:02 +00:00
|
|
|
}
|
|
|
|
|
2014-03-27 17:01:14 +00:00
|
|
|
//the testUpdateAvatar series also implicitely tests getAvatarImage
|
|
|
|
public function testUpdateAvatarJpegPhotoProvided() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('readAttribute')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->dn),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo('jpegPhoto'))
|
2018-07-02 15:38:16 +00:00
|
|
|
->will($this->returnValue(['this is a photo']));
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('valid')
|
|
|
|
->will($this->returnValue(true));
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('width')
|
|
|
|
->will($this->returnValue(128));
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('height')
|
|
|
|
->will($this->returnValue(128));
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('centerCrop')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->filesystemhelper->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('isLoaded')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2016-09-02 09:02:12 +00:00
|
|
|
$avatar = $this->createMock(IAvatar::class);
|
2014-03-27 17:01:14 +00:00
|
|
|
$avatar->expects($this->once())
|
|
|
|
->method('set')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->isInstanceOf($this->image));
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->avatarManager->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('getAvatar')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->uid))
|
2014-03-27 17:01:14 +00:00
|
|
|
->will($this->returnValue($avatar));
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateAvatar();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateAvatarThumbnailPhotoProvided() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->any())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('readAttribute')
|
2017-11-03 16:40:05 +00:00
|
|
|
->willReturnCallback(function($dn, $attr) {
|
2018-07-02 15:38:16 +00:00
|
|
|
if($dn === $this->dn
|
2017-11-03 16:40:05 +00:00
|
|
|
&& $attr === 'jpegPhoto')
|
|
|
|
{
|
|
|
|
return false;
|
2018-07-02 15:38:16 +00:00
|
|
|
} elseif($dn === $this->dn
|
2017-11-03 16:40:05 +00:00
|
|
|
&& $attr === 'thumbnailPhoto')
|
|
|
|
{
|
|
|
|
return ['this is a photo'];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('valid')
|
|
|
|
->will($this->returnValue(true));
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('width')
|
|
|
|
->will($this->returnValue(128));
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('height')
|
|
|
|
->will($this->returnValue(128));
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('centerCrop')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->filesystemhelper->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('isLoaded')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2016-09-02 09:02:12 +00:00
|
|
|
$avatar = $this->createMock(IAvatar::class);
|
2014-03-27 17:01:14 +00:00
|
|
|
$avatar->expects($this->once())
|
|
|
|
->method('set')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->isInstanceOf($this->image));
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->avatarManager->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('getAvatar')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->uid))
|
2014-03-27 17:01:14 +00:00
|
|
|
->will($this->returnValue($avatar));
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateAvatar();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateAvatarNotProvided() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->any())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('readAttribute')
|
2017-11-03 16:40:05 +00:00
|
|
|
->willReturnCallback(function($dn, $attr) {
|
2018-07-02 15:38:16 +00:00
|
|
|
if($dn === $this->dn
|
2017-11-03 16:40:05 +00:00
|
|
|
&& $attr === 'jpegPhoto')
|
|
|
|
{
|
|
|
|
return false;
|
2018-07-02 15:38:16 +00:00
|
|
|
} elseif($dn === $this->dn
|
2017-11-03 16:40:05 +00:00
|
|
|
&& $attr === 'thumbnailPhoto')
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->image->expects($this->never())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('valid');
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->image->expects($this->never())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('width');
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->image->expects($this->never())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('height');
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->image->expects($this->never())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('centerCrop');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->filesystemhelper->expects($this->never())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('isLoaded');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->avatarManager->expects($this->never())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('getAvatar');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->updateAvatar();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateBeforeFirstLogin() {
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->at(0))
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('getUserValue')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->uid), $this->equalTo('user_ldap'),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo(User::USER_PREFKEY_FIRSTLOGIN),
|
|
|
|
$this->equalTo(0))
|
|
|
|
->will($this->returnValue(0));
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->at(1))
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('getUserValue')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->uid), $this->equalTo('user_ldap'),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo(User::USER_PREFKEY_LASTREFRESH),
|
|
|
|
$this->equalTo(0))
|
|
|
|
->will($this->returnValue(0));
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->exactly(2))
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('getUserValue');
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->never())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('setUserValue');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->update();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateAfterFirstLogin() {
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->at(0))
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('getUserValue')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->uid), $this->equalTo('user_ldap'),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo(User::USER_PREFKEY_FIRSTLOGIN),
|
|
|
|
$this->equalTo(0))
|
|
|
|
->will($this->returnValue(1));
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->at(1))
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('getUserValue')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->uid), $this->equalTo('user_ldap'),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo(User::USER_PREFKEY_LASTREFRESH),
|
|
|
|
$this->equalTo(0))
|
|
|
|
->will($this->returnValue(0));
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->exactly(2))
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('getUserValue');
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('setUserValue')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->uid), $this->equalTo('user_ldap'),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo(User::USER_PREFKEY_LASTREFRESH),
|
|
|
|
$this->anything())
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->update();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateNoRefresh() {
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->at(0))
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('getUserValue')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->uid), $this->equalTo('user_ldap'),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo(User::USER_PREFKEY_FIRSTLOGIN),
|
|
|
|
$this->equalTo(0))
|
|
|
|
->will($this->returnValue(1));
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->at(1))
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('getUserValue')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->uid), $this->equalTo('user_ldap'),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo(User::USER_PREFKEY_LASTREFRESH),
|
|
|
|
$this->equalTo(0))
|
2017-08-10 07:24:39 +00:00
|
|
|
->will($this->returnValue(time() - 10));
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->once())
|
2017-08-09 19:52:23 +00:00
|
|
|
->method('getAppValue')
|
|
|
|
->with($this->equalTo('user_ldap'),
|
|
|
|
$this->equalTo('updateAttributesInterval'),
|
|
|
|
$this->anything())
|
2017-08-09 20:28:35 +00:00
|
|
|
->will($this->returnValue(1800));
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->exactly(2))
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('getUserValue');
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->never())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('setUserValue');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->update();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMarkLogin() {
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('setUserValue')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->uid),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo('user_ldap'),
|
|
|
|
$this->equalTo(User::USER_PREFKEY_FIRSTLOGIN),
|
|
|
|
$this->equalTo(1))
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->markLogin();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAvatarImageProvided() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 17:01:14 +00:00
|
|
|
->method('readAttribute')
|
2018-07-02 15:38:16 +00:00
|
|
|
->with($this->equalTo($this->dn),
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->equalTo('jpegPhoto'))
|
2018-07-02 15:38:16 +00:00
|
|
|
->will($this->returnValue(['this is a photo']));
|
2014-03-27 17:01:14 +00:00
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$photo = $this->user->getAvatarImage();
|
2014-03-27 17:01:14 +00:00
|
|
|
$this->assertSame('this is a photo', $photo);
|
|
|
|
//make sure readAttribute is not called again but the already fetched
|
|
|
|
//photo is returned
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->getAvatarImage();
|
2014-03-27 17:01:14 +00:00
|
|
|
}
|
2015-08-20 22:55:42 +00:00
|
|
|
|
|
|
|
public function testProcessAttributes() {
|
|
|
|
$requiredMethods = array(
|
|
|
|
'markRefreshTime',
|
|
|
|
'updateQuota',
|
|
|
|
'updateEmail',
|
2016-02-03 12:16:55 +00:00
|
|
|
'composeAndStoreDisplayName',
|
2015-08-20 22:55:42 +00:00
|
|
|
'storeLDAPUserName',
|
|
|
|
'getHomePath',
|
|
|
|
'updateAvatar'
|
|
|
|
);
|
|
|
|
|
2018-06-27 23:11:36 +00:00
|
|
|
/** @var User|\PHPUnit_Framework_MockObject_MockObject $userMock */
|
|
|
|
$userMock = $this->getMockBuilder(User::class)
|
2018-07-02 15:38:16 +00:00
|
|
|
->setConstructorArgs([
|
|
|
|
$this->uid,
|
|
|
|
$this->dn,
|
|
|
|
$this->access,
|
|
|
|
$this->config,
|
|
|
|
$this->filesystemhelper,
|
|
|
|
$this->image,
|
|
|
|
$this->log,
|
|
|
|
$this->avatarManager,
|
|
|
|
$this->userManager,
|
|
|
|
$this->notificationManager
|
|
|
|
])
|
2015-08-20 22:55:42 +00:00
|
|
|
->setMethods($requiredMethods)
|
|
|
|
->getMock();
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->setConfiguration(array(
|
2015-08-20 22:55:42 +00:00
|
|
|
'homeFolderNamingRule' => 'homeDirectory'
|
|
|
|
));
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->any())
|
2015-08-20 22:55:42 +00:00
|
|
|
->method('__get')
|
|
|
|
->will($this->returnCallback(function($name) {
|
|
|
|
if($name === 'homeFolderNamingRule') {
|
|
|
|
return 'attr:homeDirectory';
|
|
|
|
}
|
|
|
|
return $name;
|
|
|
|
}));
|
|
|
|
|
|
|
|
$record = array(
|
2017-11-03 16:40:05 +00:00
|
|
|
strtolower($this->connection->ldapQuotaAttribute) => array('4096'),
|
|
|
|
strtolower($this->connection->ldapEmailAttribute) => array('alice@wonderland.org'),
|
|
|
|
strtolower($this->connection->ldapUserDisplayName) => array('Aaaaalice'),
|
2018-07-02 15:38:16 +00:00
|
|
|
'uid' => [$this->uid],
|
2015-08-20 22:55:42 +00:00
|
|
|
'homedirectory' => array('Alice\'s Folder'),
|
|
|
|
'memberof' => array('cn=groupOne', 'cn=groupTwo'),
|
|
|
|
'jpegphoto' => array('here be an image')
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach($requiredMethods as $method) {
|
|
|
|
$userMock->expects($this->once())
|
|
|
|
->method($method);
|
|
|
|
}
|
2017-03-31 07:16:22 +00:00
|
|
|
\OC_Hook::clear();//disconnect irrelevant hooks
|
2015-08-20 22:55:42 +00:00
|
|
|
$userMock->processAttributes($record);
|
2018-07-02 15:38:16 +00:00
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */
|
|
|
|
\OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
|
2015-08-20 22:55:42 +00:00
|
|
|
}
|
2015-09-23 14:52:48 +00:00
|
|
|
|
|
|
|
public function emptyHomeFolderAttributeValueProvider() {
|
|
|
|
return array(
|
2018-07-02 15:38:16 +00:00
|
|
|
'empty' => [''],
|
|
|
|
'prefixOnly' => ['attr:'],
|
2015-09-23 14:52:48 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider emptyHomeFolderAttributeValueProvider
|
|
|
|
*/
|
|
|
|
public function testGetHomePathNotConfigured($attributeValue) {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->any())
|
2015-09-23 14:52:48 +00:00
|
|
|
->method('__get')
|
|
|
|
->with($this->equalTo('homeFolderNamingRule'))
|
|
|
|
->will($this->returnValue($attributeValue));
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->never())
|
2015-09-23 14:52:48 +00:00
|
|
|
->method('readAttribute');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->never())
|
2015-09-23 14:52:48 +00:00
|
|
|
->method('getAppValue');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */
|
|
|
|
$this->assertFalse($this->user->getHomePath());
|
2015-09-23 14:52:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetHomePathConfiguredNotAvailableAllowed() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->any())
|
2015-09-23 14:52:48 +00:00
|
|
|
->method('__get')
|
|
|
|
->with($this->equalTo('homeFolderNamingRule'))
|
|
|
|
->will($this->returnValue('attr:foobar'));
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->once())
|
2015-09-23 14:52:48 +00:00
|
|
|
->method('readAttribute')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
|
|
|
// asks for "enforce_home_folder_naming_rule"
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->once())
|
2015-09-23 14:52:48 +00:00
|
|
|
->method('getAppValue')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */
|
|
|
|
$this->assertFalse($this->user->getHomePath());
|
2015-09-23 14:52:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Exception
|
|
|
|
*/
|
|
|
|
public function testGetHomePathConfiguredNotAvailableNotAllowed() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->any())
|
2015-09-23 14:52:48 +00:00
|
|
|
->method('__get')
|
|
|
|
->with($this->equalTo('homeFolderNamingRule'))
|
|
|
|
->will($this->returnValue('attr:foobar'));
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->once())
|
2015-09-23 14:52:48 +00:00
|
|
|
->method('readAttribute')
|
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
|
|
|
// asks for "enforce_home_folder_naming_rule"
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->once())
|
2015-09-23 14:52:48 +00:00
|
|
|
->method('getAppValue')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->user->getHomePath();
|
2015-09-23 14:52:48 +00:00
|
|
|
}
|
2016-02-03 12:16:55 +00:00
|
|
|
|
|
|
|
public function displayNameProvider() {
|
|
|
|
return [
|
|
|
|
['Roland Deschain', '', 'Roland Deschain'],
|
|
|
|
['Roland Deschain', null, 'Roland Deschain'],
|
|
|
|
['Roland Deschain', 'gunslinger@darktower.com', 'Roland Deschain (gunslinger@darktower.com)'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider displayNameProvider
|
|
|
|
*/
|
|
|
|
public function testComposeAndStoreDisplayName($part1, $part2, $expected) {
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->config->expects($this->once())
|
2016-02-03 12:16:55 +00:00
|
|
|
->method('setUserValue');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
$displayName = $this->user->composeAndStoreDisplayName($part1, $part2);
|
2016-02-03 12:16:55 +00:00
|
|
|
$this->assertSame($expected, $displayName);
|
|
|
|
}
|
2017-03-31 07:16:22 +00:00
|
|
|
|
|
|
|
public function testHandlePasswordExpiryWarningDefaultPolicy() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->any())
|
2017-03-31 07:16:22 +00:00
|
|
|
->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;
|
|
|
|
}));
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->any())
|
2017-04-07 10:06:50 +00:00
|
|
|
->method('search')
|
|
|
|
->will($this->returnCallback(function($filter, $base) {
|
2018-07-02 15:38:16 +00:00
|
|
|
if($base === [$this->dn]) {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'],
|
2017-08-09 14:43:40 +00:00
|
|
|
'pwdgraceusetime' => [],
|
2018-07-02 15:38:16 +00:00
|
|
|
],
|
|
|
|
];
|
2017-03-31 07:16:22 +00:00
|
|
|
}
|
2018-07-02 15:38:16 +00:00
|
|
|
if($base === ['cn=default,ou=policies,dc=foo,dc=bar']) {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'pwdmaxage' => ['2592000'],
|
|
|
|
'pwdexpirewarning' => ['2591999'],
|
|
|
|
],
|
|
|
|
];
|
2017-03-31 07:16:22 +00:00
|
|
|
}
|
2018-07-02 15:38:16 +00:00
|
|
|
return [];
|
2017-03-31 07:16:22 +00:00
|
|
|
}));
|
|
|
|
|
2017-10-24 13:26:53 +00:00
|
|
|
$notification = $this->getMockBuilder(INotification::class)
|
2017-03-31 07:16:22 +00:00
|
|
|
->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));
|
2018-07-02 15:38:16 +00:00
|
|
|
|
|
|
|
$this->notificationManager->expects($this->exactly(2))
|
2017-03-31 07:16:22 +00:00
|
|
|
->method('createNotification')
|
|
|
|
->will($this->returnValue($notification));
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->notificationManager->expects($this->exactly(1))
|
2017-03-31 07:16:22 +00:00
|
|
|
->method('notify');
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
\OC_Hook::clear();//disconnect irrelevant hooks
|
2018-07-02 15:38:16 +00:00
|
|
|
\OCP\Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry');
|
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */
|
|
|
|
\OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
|
2017-03-31 07:16:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testHandlePasswordExpiryWarningCustomPolicy() {
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->connection->expects($this->any())
|
2017-03-31 07:16:22 +00:00
|
|
|
->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;
|
|
|
|
}));
|
|
|
|
|
2017-11-03 16:40:05 +00:00
|
|
|
$this->access->expects($this->any())
|
2017-04-07 10:06:50 +00:00
|
|
|
->method('search')
|
|
|
|
->will($this->returnCallback(function($filter, $base) {
|
2018-07-02 15:38:16 +00:00
|
|
|
if($base === [$this->dn]) {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'pwdpolicysubentry' => ['cn=custom,ou=policies,dc=foo,dc=bar'],
|
|
|
|
'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'],
|
2017-08-09 14:43:40 +00:00
|
|
|
'pwdgraceusetime' => [],
|
2018-07-02 15:38:16 +00:00
|
|
|
]
|
|
|
|
];
|
2017-03-31 07:16:22 +00:00
|
|
|
}
|
2018-07-02 15:38:16 +00:00
|
|
|
if($base === ['cn=custom,ou=policies,dc=foo,dc=bar']) {
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'pwdmaxage' => ['2592000'],
|
|
|
|
'pwdexpirewarning' => ['2591999'],
|
|
|
|
]
|
|
|
|
];
|
2017-03-31 07:16:22 +00:00
|
|
|
}
|
2018-07-02 15:38:16 +00:00
|
|
|
return [];
|
2017-03-31 07:16:22 +00:00
|
|
|
}));
|
|
|
|
|
2017-10-24 13:26:53 +00:00
|
|
|
$notification = $this->getMockBuilder(INotification::class)
|
2017-03-31 07:16:22 +00:00
|
|
|
->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));
|
2018-07-02 15:38:16 +00:00
|
|
|
|
|
|
|
$this->notificationManager->expects($this->exactly(2))
|
2017-03-31 07:16:22 +00:00
|
|
|
->method('createNotification')
|
|
|
|
->will($this->returnValue($notification));
|
2018-07-02 15:38:16 +00:00
|
|
|
$this->notificationManager->expects($this->exactly(1))
|
2017-03-31 07:16:22 +00:00
|
|
|
->method('notify');
|
|
|
|
|
2018-07-02 15:38:16 +00:00
|
|
|
\OC_Hook::clear();//disconnect irrelevant hooks
|
|
|
|
\OCP\Util::connectHook('OC_User', 'post_login', $this->user, 'handlePasswordExpiry');
|
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */
|
|
|
|
\OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
|
2017-03-31 07:16:22 +00:00
|
|
|
}
|
2014-04-24 11:32:50 +00:00
|
|
|
}
|