2014-03-27 21:01:14 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Juan Pablo Villafáñez <jvillafanez@solidgear.es>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
* @author Roger Szabo <roger.szabo@web.de>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author sidey79 <s.butzek@gmx.de>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-03-26 13:44:34 +03: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,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-03-26 13:44:34 +03:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2016-05-12 12:25:50 +03:00
|
|
|
namespace OCA\User_LDAP\Tests\User;
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
use OCA\User_LDAP\Access;
|
|
|
|
use OCA\User_LDAP\Connection;
|
2016-09-02 12:02:12 +03:00
|
|
|
use OCA\User_LDAP\FilesystemHelper;
|
|
|
|
use OCA\User_LDAP\LogWrapper;
|
2016-05-12 12:25:50 +03:00
|
|
|
use OCA\User_LDAP\User\User;
|
2016-09-02 12:02:12 +03:00
|
|
|
use OCP\IAvatar;
|
|
|
|
use OCP\IAvatarManager;
|
|
|
|
use OCP\IConfig;
|
|
|
|
use OCP\Image;
|
|
|
|
use OCP\IUser;
|
2016-01-19 17:48:38 +03:00
|
|
|
use OCP\IUserManager;
|
2017-03-31 10:16:22 +03:00
|
|
|
use OCP\Notification\IManager as INotificationManager;
|
2017-10-24 16:26:53 +03:00
|
|
|
use OCP\Notification\INotification;
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2015-11-25 18:58:54 +03:00
|
|
|
/**
|
2016-05-12 18:14:59 +03:00
|
|
|
* Class UserTest
|
2015-11-25 18:58:54 +03:00
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
2016-05-12 18:14:59 +03:00
|
|
|
* @package OCA\User_LDAP\Tests\User
|
2015-11-25 18:58:54 +03:00
|
|
|
*/
|
2016-05-12 12:25:50 +03:00
|
|
|
class UserTest extends \Test\TestCase {
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var Access|\PHPUnit\Framework\MockObject\MockObject */
|
2017-11-03 19:40:05 +03:00
|
|
|
protected $access;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var Connection|\PHPUnit\Framework\MockObject\MockObject */
|
2017-11-03 19:40:05 +03:00
|
|
|
protected $connection;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
|
2018-07-02 18:38:16 +03:00
|
|
|
protected $config;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var FilesystemHelper|\PHPUnit\Framework\MockObject\MockObject */
|
2018-07-02 18:38:16 +03:00
|
|
|
protected $filesystemhelper;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var INotificationManager|\PHPUnit\Framework\MockObject\MockObject */
|
2018-07-02 18:38:16 +03:00
|
|
|
protected $notificationManager;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
2018-07-02 18:38:16 +03:00
|
|
|
protected $userManager;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var Image|\PHPUnit\Framework\MockObject\MockObject */
|
2018-07-02 18:38:16 +03:00
|
|
|
protected $image;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IAvatarManager|\PHPUnit\Framework\MockObject\MockObject */
|
2018-07-02 18:38:16 +03:00
|
|
|
protected $avatarManager;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var LogWrapper|\PHPUnit\Framework\MockObject\MockObject */
|
2018-07-02 18:38:16 +03:00
|
|
|
protected $log;
|
|
|
|
/** @var string */
|
|
|
|
protected $uid = 'alice';
|
|
|
|
/** @var string */
|
|
|
|
protected $dn = 'uid=alice,dc=foo,dc=bar';
|
|
|
|
/** @var User */
|
|
|
|
protected $user;
|
2017-11-03 19:40:05 +03:00
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2018-07-02 18:38:16 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection = $this->createMock(Connection::class);
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->access = $this->createMock(Access::class);
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->connection = $this->connection;
|
|
|
|
$this->access->expects($this->any())
|
|
|
|
->method('getConnection')
|
|
|
|
->willReturn($this->connection);
|
|
|
|
|
2018-07-02 18:38:16 +03: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 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetDNandUsername() {
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->assertSame($this->dn, $this->user->getDN());
|
|
|
|
$this->assertSame($this->uid, $this->user->getUsername());
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateEmailProvided() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('__get')
|
|
|
|
->with($this->equalTo('ldapEmailAttribute'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('email');
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('readAttribute')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->dn),
|
2014-03-27 21:01:14 +04:00
|
|
|
$this->equalTo('email'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['alice@foo.bar']);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$coreUser = $this->getMockBuilder(IUser::class)
|
2016-01-19 17:48:38 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2018-07-02 18:38:16 +03:00
|
|
|
$coreUser->expects($this->once())
|
2016-01-19 17:48:38 +03:00
|
|
|
->method('setEMailAddress')
|
|
|
|
->with('alice@foo.bar');
|
2018-07-02 18:38:16 +03:00
|
|
|
|
|
|
|
$this->userManager->expects($this->any())
|
2016-01-19 17:48:38 +03:00
|
|
|
->method('get')
|
2018-07-02 18:38:16 +03:00
|
|
|
->willReturn($coreUser);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateEmail();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateEmailNotProvided() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('__get')
|
|
|
|
->with($this->equalTo('ldapEmailAttribute'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('email');
|
2018-07-02 18:38:16 +03:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('readAttribute')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->dn),
|
2014-03-27 21:01:14 +04:00
|
|
|
$this->equalTo('email'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->never())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('setUserValue');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateEmail();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateEmailNotConfigured() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('__get')
|
|
|
|
->with($this->equalTo('ldapEmailAttribute'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('');
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->never())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('readAttribute');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->never())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('setUserValue');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateEmail();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateQuotaAllProvided() {
|
2018-06-28 02:11:36 +03:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('__get')
|
2018-06-28 02:11:36 +03:00
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '']
|
|
|
|
]);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('readAttribute')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->dn),
|
2014-03-27 21:01:14 +04:00
|
|
|
$this->equalTo('myquota'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['42 GB']);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->once())
|
2016-02-09 20:11:30 +03:00
|
|
|
->method('setQuota')
|
|
|
|
->with('42 GB');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->userManager->expects($this->atLeastOnce())
|
2016-02-09 20:11:30 +03:00
|
|
|
->method('get')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->uid)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($coreUser);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateQuota();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
2017-03-17 15:02:08 +03:00
|
|
|
public function testUpdateQuotaToDefaultAllProvided() {
|
2018-06-28 02:11:36 +03:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2017-03-17 15:02:08 +03:00
|
|
|
->method('__get')
|
2018-06-28 02:11:36 +03:00
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '']
|
|
|
|
]);
|
2017-03-17 15:02:08 +03:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->once())
|
2017-03-17 15:02:08 +03:00
|
|
|
->method('readAttribute')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->dn),
|
2017-03-17 15:02:08 +03:00
|
|
|
$this->equalTo('myquota'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['default']);
|
2017-03-17 15:02:08 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->once())
|
2017-03-17 15:02:08 +03:00
|
|
|
->method('setQuota')
|
|
|
|
->with('default');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->userManager->expects($this->once())
|
2017-03-17 15:02:08 +03:00
|
|
|
->method('get')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->uid)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($coreUser);
|
2017-03-17 15:02:08 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateQuota();
|
2017-03-17 15:02:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateQuotaToNoneAllProvided() {
|
2018-06-28 02:11:36 +03:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2017-03-17 15:02:08 +03:00
|
|
|
->method('__get')
|
2018-06-28 02:11:36 +03:00
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '']
|
|
|
|
]);
|
2017-03-17 15:02:08 +03:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->once())
|
2017-03-17 15:02:08 +03:00
|
|
|
->method('readAttribute')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->dn),
|
2017-03-17 15:02:08 +03:00
|
|
|
$this->equalTo('myquota'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['none']);
|
2017-03-17 15:02:08 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->once())
|
2017-03-17 15:02:08 +03:00
|
|
|
->method('setQuota')
|
|
|
|
->with('none');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->userManager->expects($this->once())
|
2017-03-17 15:02:08 +03:00
|
|
|
->method('get')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->uid)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($coreUser);
|
2017-03-17 15:02:08 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateQuota();
|
2017-03-17 15:02:08 +03:00
|
|
|
}
|
|
|
|
|
2014-03-27 21:01:14 +04:00
|
|
|
public function testUpdateQuotaDefaultProvided() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->at(0))
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('__get')
|
2017-03-15 10:55:14 +03:00
|
|
|
->with($this->equalTo('ldapQuotaAttribute'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('myquota');
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->at(1))
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('__get')
|
2017-03-15 10:55:14 +03:00
|
|
|
->with($this->equalTo('ldapQuotaDefault'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('25 GB');
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('__get');
|
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('readAttribute')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->dn),
|
2014-03-27 21:01:14 +04:00
|
|
|
$this->equalTo('myquota'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->once())
|
2016-02-09 20:11:30 +03:00
|
|
|
->method('setQuota')
|
|
|
|
->with('25 GB');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->userManager->expects($this->once())
|
2016-02-09 20:11:30 +03:00
|
|
|
->method('get')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->uid)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($coreUser);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateQuota();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateQuotaIndividualProvided() {
|
2018-06-28 02:11:36 +03:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('__get')
|
2018-06-28 02:11:36 +03:00
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '']
|
|
|
|
]);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('readAttribute')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->dn),
|
2014-03-27 21:01:14 +04:00
|
|
|
$this->equalTo('myquota'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['27 GB']);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->once())
|
2016-02-09 20:11:30 +03:00
|
|
|
->method('setQuota')
|
|
|
|
->with('27 GB');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->userManager->expects($this->once())
|
2016-02-09 20:11:30 +03:00
|
|
|
->method('get')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->uid)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($coreUser);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateQuota();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateQuotaNoneProvided() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2018-06-28 02:11:36 +03:00
|
|
|
->method('__get')
|
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '']
|
|
|
|
]);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('readAttribute')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->dn),
|
2014-03-27 21:01:14 +04:00
|
|
|
$this->equalTo('myquota'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->never())
|
2017-08-16 12:10:23 +03:00
|
|
|
->method('setQuota');
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->userManager->expects($this->never())
|
2017-03-16 14:22:02 +03:00
|
|
|
->method('get')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->uid);
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->never())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('setUserValue');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateQuota();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateQuotaNoneConfigured() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2018-06-28 02:11:36 +03:00
|
|
|
->method('__get')
|
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', ''],
|
|
|
|
['ldapQuotaDefault', '']
|
|
|
|
]);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->never())
|
2017-08-16 12:10:23 +03:00
|
|
|
->method('setQuota');
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->userManager->expects($this->never())
|
2018-06-28 02:11:36 +03:00
|
|
|
->method('get');
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->never())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('readAttribute');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->never())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('setUserValue');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateQuota();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
2015-09-29 17:19:45 +03:00
|
|
|
public function testUpdateQuotaFromValue() {
|
|
|
|
$readQuota = '19 GB';
|
|
|
|
|
2018-06-28 02:11:36 +03:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2015-09-29 17:19:45 +03:00
|
|
|
->method('__get')
|
2018-06-28 02:11:36 +03:00
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '']
|
|
|
|
]);
|
2015-09-29 17:19:45 +03:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->never())
|
2015-09-29 17:19:45 +03:00
|
|
|
->method('readAttribute');
|
|
|
|
|
2016-09-02 12:02:12 +03:00
|
|
|
$user = $this->createMock(IUser::class);
|
2016-02-09 20:11:30 +03:00
|
|
|
$user->expects($this->once())
|
|
|
|
->method('setQuota')
|
|
|
|
->with($readQuota);
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->userManager->expects($this->once())
|
2016-02-09 20:11:30 +03:00
|
|
|
->method('get')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->uid)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($user);
|
2015-09-29 17:19:45 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateQuota($readQuota);
|
2015-09-29 17:19:45 +03:00
|
|
|
}
|
|
|
|
|
2017-03-16 14:22:02 +03:00
|
|
|
/**
|
|
|
|
* Unparseable quota will fallback to use the LDAP default
|
|
|
|
*/
|
|
|
|
public function testUpdateWrongQuotaAllProvided() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2018-06-28 02:11:36 +03:00
|
|
|
->method('__get')
|
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '23 GB']
|
|
|
|
]);
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->once())
|
2017-03-16 14:22:02 +03:00
|
|
|
->method('readAttribute')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->dn),
|
2017-03-16 14:22:02 +03:00
|
|
|
$this->equalTo('myquota'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['42 GBwos']);
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->once())
|
2017-03-16 14:22:02 +03:00
|
|
|
->method('setQuota')
|
|
|
|
->with('23 GB');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->userManager->expects($this->once())
|
2017-03-16 14:22:02 +03:00
|
|
|
->method('get')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->uid)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($coreUser);
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateQuota();
|
2017-03-16 14:22:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* No user quota and wrong default will set 'default' as quota
|
|
|
|
*/
|
|
|
|
public function testUpdateWrongDefaultQuotaProvided() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2018-06-28 02:11:36 +03:00
|
|
|
->method('__get')
|
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '23 GBwowowo']
|
|
|
|
]);
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->once())
|
2017-03-16 14:22:02 +03:00
|
|
|
->method('readAttribute')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->dn),
|
2017-03-16 14:22:02 +03:00
|
|
|
$this->equalTo('myquota'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->never())
|
2017-08-16 12:10:23 +03:00
|
|
|
->method('setQuota');
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->userManager->expects($this->never())
|
2018-06-28 02:11:36 +03:00
|
|
|
->method('get');
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateQuota();
|
2017-03-16 14:22:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrong user quota and wrong default will set 'default' as quota
|
|
|
|
*/
|
|
|
|
public function testUpdateWrongQuotaAndDefaultAllProvided() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2018-06-28 02:11:36 +03:00
|
|
|
->method('__get')
|
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', 'myquota'],
|
|
|
|
['ldapQuotaDefault', '23 GBwowowo']
|
|
|
|
]);
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->once())
|
2017-03-16 14:22:02 +03:00
|
|
|
->method('readAttribute')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->dn),
|
2017-03-16 14:22:02 +03:00
|
|
|
$this->equalTo('myquota'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['23 flush']);
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->never())
|
2017-08-16 12:10:23 +03:00
|
|
|
->method('setQuota');
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->userManager->expects($this->never())
|
2018-06-28 02:11:36 +03:00
|
|
|
->method('get');
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateQuota();
|
2017-03-16 14:22:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* No quota attribute set and wrong default will set 'default' as quota
|
|
|
|
*/
|
|
|
|
public function testUpdateWrongDefaultQuotaNotProvided() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->exactly(2))
|
2018-06-28 02:11:36 +03:00
|
|
|
->method('__get')
|
|
|
|
->willReturnMap([
|
|
|
|
['ldapQuotaAttribute', ''],
|
|
|
|
['ldapQuotaDefault', '23 GBwowowo']
|
|
|
|
]);
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->never())
|
2017-03-16 14:22:02 +03:00
|
|
|
->method('readAttribute');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$coreUser = $this->createMock(IUser::class);
|
|
|
|
$coreUser->expects($this->never())
|
2017-08-16 12:10:23 +03:00
|
|
|
->method('setQuota');
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->userManager->expects($this->never())
|
2018-06-28 02:11:36 +03:00
|
|
|
->method('get');
|
2017-03-16 14:22:02 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateQuota();
|
2017-03-16 14:22:02 +03:00
|
|
|
}
|
|
|
|
|
2014-03-27 21:01:14 +04:00
|
|
|
//the testUpdateAvatar series also implicitely tests getAvatarImage
|
2019-11-25 23:09:05 +03:00
|
|
|
public function XtestUpdateAvatarJpegPhotoProvided() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('readAttribute')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->dn),
|
2018-07-05 12:29:19 +03:00
|
|
|
$this->equalTo('jpegphoto'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['this is a photo']);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-03 01:38:25 +03:00
|
|
|
$this->image->expects($this->once())
|
|
|
|
->method('loadFromBase64')
|
|
|
|
->willReturn('imageResource');
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('valid')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('width')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(128);
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('height')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(128);
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('centerCrop')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2019-09-04 15:44:48 +03:00
|
|
|
$this->image->expects($this->once())
|
|
|
|
->method('data')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('this is a photo');
|
2019-09-04 15:44:48 +03:00
|
|
|
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('getUserValue')
|
|
|
|
->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
|
|
|
|
->willReturn('');
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('setUserValue')
|
|
|
|
->with($this->uid, 'user_ldap', 'lastAvatarChecksum', md5('this is a photo'));
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->filesystemhelper->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('isLoaded')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2016-09-02 12:02:12 +03:00
|
|
|
$avatar = $this->createMock(IAvatar::class);
|
2014-03-27 21:01:14 +04:00
|
|
|
$avatar->expects($this->once())
|
|
|
|
->method('set')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->isInstanceOf($this->image));
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->avatarManager->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('getAvatar')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->uid))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($avatar);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-05 12:29:19 +03:00
|
|
|
$this->connection->expects($this->any())
|
|
|
|
->method('resolveRule')
|
|
|
|
->with('avatar')
|
|
|
|
->willReturn(['jpegphoto', 'thumbnailphoto']);
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateAvatar();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
2019-09-04 15:44:48 +03:00
|
|
|
public function testUpdateAvatarKnownJpegPhotoProvided() {
|
|
|
|
$this->access->expects($this->once())
|
|
|
|
->method('readAttribute')
|
|
|
|
->with($this->equalTo($this->dn),
|
|
|
|
$this->equalTo('jpegphoto'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['this is a photo']);
|
2019-09-04 15:44:48 +03:00
|
|
|
|
|
|
|
$this->image->expects($this->once())
|
|
|
|
->method('loadFromBase64')
|
|
|
|
->willReturn('imageResource');
|
|
|
|
$this->image->expects($this->never())
|
|
|
|
->method('valid');
|
|
|
|
$this->image->expects($this->never())
|
|
|
|
->method('width');
|
|
|
|
$this->image->expects($this->never())
|
|
|
|
->method('height');
|
|
|
|
$this->image->expects($this->never())
|
|
|
|
->method('centerCrop');
|
|
|
|
$this->image->expects($this->once())
|
|
|
|
->method('data')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('this is a photo');
|
2019-09-04 15:44:48 +03:00
|
|
|
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('getUserValue')
|
|
|
|
->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
|
|
|
|
->willReturn(md5('this is a photo'));
|
|
|
|
$this->config->expects($this->never())
|
|
|
|
->method('setUserValue');
|
|
|
|
|
|
|
|
$this->filesystemhelper->expects($this->never())
|
|
|
|
->method('isLoaded');
|
|
|
|
|
|
|
|
$avatar = $this->createMock(IAvatar::class);
|
|
|
|
$avatar->expects($this->never())
|
|
|
|
->method('set');
|
|
|
|
|
|
|
|
$this->avatarManager->expects($this->never())
|
|
|
|
->method('getAvatar');
|
|
|
|
|
|
|
|
$this->connection->expects($this->any())
|
|
|
|
->method('resolveRule')
|
|
|
|
->with('avatar')
|
|
|
|
->willReturn(['jpegphoto', 'thumbnailphoto']);
|
|
|
|
|
|
|
|
$this->assertTrue($this->user->updateAvatar());
|
|
|
|
}
|
|
|
|
|
2019-11-25 23:09:05 +03:00
|
|
|
public function XtestUpdateAvatarThumbnailPhotoProvided() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->any())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('readAttribute')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($dn, $attr) {
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($dn === $this->dn
|
|
|
|
&& $attr === 'jpegphoto') {
|
2017-11-03 19:40:05 +03:00
|
|
|
return false;
|
2020-04-10 15:19:56 +03:00
|
|
|
} elseif ($dn === $this->dn
|
|
|
|
&& $attr === 'thumbnailphoto') {
|
2017-11-03 19:40:05 +03:00
|
|
|
return ['this is a photo'];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-03 01:38:25 +03:00
|
|
|
$this->image->expects($this->once())
|
|
|
|
->method('loadFromBase64')
|
|
|
|
->willReturn('imageResource');
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('valid')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('width')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(128);
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('height')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(128);
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->image->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('centerCrop')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2019-09-04 15:44:48 +03:00
|
|
|
$this->image->expects($this->once())
|
|
|
|
->method('data')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('this is a photo');
|
2019-09-04 15:44:48 +03:00
|
|
|
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('getUserValue')
|
|
|
|
->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
|
|
|
|
->willReturn('');
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('setUserValue')
|
|
|
|
->with($this->uid, 'user_ldap', 'lastAvatarChecksum', md5('this is a photo'));
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->filesystemhelper->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('isLoaded')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2016-09-02 12:02:12 +03:00
|
|
|
$avatar = $this->createMock(IAvatar::class);
|
2014-03-27 21:01:14 +04:00
|
|
|
$avatar->expects($this->once())
|
|
|
|
->method('set')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->isInstanceOf($this->image));
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->avatarManager->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('getAvatar')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->uid))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($avatar);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-05 12:29:19 +03:00
|
|
|
$this->connection->expects($this->any())
|
|
|
|
->method('resolveRule')
|
|
|
|
->with('avatar')
|
|
|
|
->willReturn(['jpegphoto', 'thumbnailphoto']);
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateAvatar();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
2018-07-03 01:38:25 +03:00
|
|
|
public function testUpdateAvatarCorruptPhotoProvided() {
|
|
|
|
$this->access->expects($this->any())
|
|
|
|
->method('readAttribute')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($dn, $attr) {
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($dn === $this->dn
|
|
|
|
&& $attr === 'jpegphoto') {
|
2018-07-03 01:38:25 +03:00
|
|
|
return false;
|
2020-04-10 15:19:56 +03:00
|
|
|
} elseif ($dn === $this->dn
|
|
|
|
&& $attr === 'thumbnailphoto') {
|
2018-07-03 01:38:25 +03:00
|
|
|
return ['this is a photo'];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->image->expects($this->once())
|
|
|
|
->method('loadFromBase64')
|
|
|
|
->willReturn(false);
|
|
|
|
$this->image->expects($this->never())
|
|
|
|
->method('valid');
|
|
|
|
$this->image->expects($this->never())
|
|
|
|
->method('width');
|
|
|
|
$this->image->expects($this->never())
|
|
|
|
->method('height');
|
|
|
|
$this->image->expects($this->never())
|
|
|
|
->method('centerCrop');
|
2019-09-04 15:44:48 +03:00
|
|
|
$this->image->expects($this->never())
|
|
|
|
->method('data');
|
|
|
|
|
|
|
|
$this->config->expects($this->never())
|
|
|
|
->method('getUserValue');
|
|
|
|
$this->config->expects($this->never())
|
|
|
|
->method('setUserValue');
|
2018-07-03 01:38:25 +03:00
|
|
|
|
|
|
|
$this->filesystemhelper->expects($this->never())
|
|
|
|
->method('isLoaded');
|
|
|
|
|
|
|
|
$avatar = $this->createMock(IAvatar::class);
|
|
|
|
$avatar->expects($this->never())
|
|
|
|
->method('set');
|
|
|
|
|
|
|
|
$this->avatarManager->expects($this->never())
|
|
|
|
->method('getAvatar');
|
|
|
|
|
2018-07-05 12:29:19 +03:00
|
|
|
$this->connection->expects($this->any())
|
|
|
|
->method('resolveRule')
|
|
|
|
->with('avatar')
|
|
|
|
->willReturn(['jpegphoto', 'thumbnailphoto']);
|
|
|
|
|
2018-07-03 01:38:25 +03:00
|
|
|
$this->user->updateAvatar();
|
|
|
|
}
|
|
|
|
|
2019-11-25 23:09:05 +03:00
|
|
|
public function XtestUpdateAvatarUnsupportedThumbnailPhotoProvided() {
|
2018-07-03 01:38:25 +03:00
|
|
|
$this->access->expects($this->any())
|
|
|
|
->method('readAttribute')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($dn, $attr) {
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($dn === $this->dn
|
|
|
|
&& $attr === 'jpegphoto') {
|
2018-07-03 01:38:25 +03:00
|
|
|
return false;
|
2020-04-10 15:19:56 +03:00
|
|
|
} elseif ($dn === $this->dn
|
|
|
|
&& $attr === 'thumbnailphoto') {
|
2018-07-03 01:38:25 +03:00
|
|
|
return ['this is a photo'];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->image->expects($this->once())
|
|
|
|
->method('loadFromBase64')
|
|
|
|
->willReturn('imageResource');
|
|
|
|
$this->image->expects($this->once())
|
|
|
|
->method('valid')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2018-07-03 01:38:25 +03:00
|
|
|
$this->image->expects($this->once())
|
|
|
|
->method('width')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(128);
|
2018-07-03 01:38:25 +03:00
|
|
|
$this->image->expects($this->once())
|
|
|
|
->method('height')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(128);
|
2018-07-03 01:38:25 +03:00
|
|
|
$this->image->expects($this->once())
|
|
|
|
->method('centerCrop')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2019-09-04 15:44:48 +03:00
|
|
|
$this->image->expects($this->once())
|
|
|
|
->method('data')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('this is a photo');
|
2019-09-04 15:44:48 +03:00
|
|
|
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('getUserValue')
|
|
|
|
->with($this->uid, 'user_ldap', 'lastAvatarChecksum', '')
|
|
|
|
->willReturn('');
|
|
|
|
$this->config->expects($this->never())
|
|
|
|
->method('setUserValue');
|
2018-07-03 01:38:25 +03:00
|
|
|
|
|
|
|
$this->filesystemhelper->expects($this->once())
|
|
|
|
->method('isLoaded')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2018-07-03 01:38:25 +03:00
|
|
|
|
|
|
|
$avatar = $this->createMock(IAvatar::class);
|
|
|
|
$avatar->expects($this->once())
|
|
|
|
->method('set')
|
|
|
|
->with($this->isInstanceOf($this->image))
|
|
|
|
->willThrowException(new \Exception());
|
|
|
|
|
|
|
|
$this->avatarManager->expects($this->once())
|
|
|
|
->method('getAvatar')
|
|
|
|
->with($this->equalTo($this->uid))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($avatar);
|
2018-07-03 01:38:25 +03:00
|
|
|
|
2018-07-05 12:29:19 +03:00
|
|
|
$this->connection->expects($this->any())
|
|
|
|
->method('resolveRule')
|
|
|
|
->with('avatar')
|
|
|
|
->willReturn(['jpegphoto', 'thumbnailphoto']);
|
|
|
|
|
2018-07-03 01:38:25 +03:00
|
|
|
$this->assertFalse($this->user->updateAvatar());
|
|
|
|
}
|
|
|
|
|
2014-03-27 21:01:14 +04:00
|
|
|
public function testUpdateAvatarNotProvided() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->any())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('readAttribute')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($dn, $attr) {
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($dn === $this->dn
|
|
|
|
&& $attr === 'jpegPhoto') {
|
2017-11-03 19:40:05 +03:00
|
|
|
return false;
|
2020-04-10 15:19:56 +03:00
|
|
|
} elseif ($dn === $this->dn
|
|
|
|
&& $attr === 'thumbnailPhoto') {
|
2017-11-03 19:40:05 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->image->expects($this->never())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('valid');
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->image->expects($this->never())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('width');
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->image->expects($this->never())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('height');
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->image->expects($this->never())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('centerCrop');
|
2019-09-04 15:44:48 +03:00
|
|
|
$this->image->expects($this->never())
|
|
|
|
->method('data');
|
|
|
|
|
|
|
|
$this->config->expects($this->never())
|
|
|
|
->method('getUserValue');
|
|
|
|
$this->config->expects($this->never())
|
|
|
|
->method('setUserValue');
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->filesystemhelper->expects($this->never())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('isLoaded');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->avatarManager->expects($this->never())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('getAvatar');
|
|
|
|
|
2018-07-05 12:29:19 +03:00
|
|
|
$this->connection->expects($this->any())
|
|
|
|
->method('resolveRule')
|
|
|
|
->with('avatar')
|
|
|
|
->willReturn(['jpegphoto', 'thumbnailphoto']);
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->updateAvatar();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateBeforeFirstLogin() {
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->at(0))
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('getUserValue')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->uid), $this->equalTo('user_ldap'),
|
2014-03-27 21:01:14 +04:00
|
|
|
$this->equalTo(User::USER_PREFKEY_FIRSTLOGIN),
|
|
|
|
$this->equalTo(0))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(0);
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->at(1))
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('getUserValue')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->uid), $this->equalTo('user_ldap'),
|
2014-03-27 21:01:14 +04:00
|
|
|
$this->equalTo(User::USER_PREFKEY_LASTREFRESH),
|
|
|
|
$this->equalTo(0))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(0);
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->exactly(2))
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('getUserValue');
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->never())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('setUserValue');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->update();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUpdateAfterFirstLogin() {
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->at(0))
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('getUserValue')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->uid), $this->equalTo('user_ldap'),
|
2014-03-27 21:01:14 +04:00
|
|
|
$this->equalTo(User::USER_PREFKEY_FIRSTLOGIN),
|
|
|
|
$this->equalTo(0))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(1);
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->at(1))
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('getUserValue')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->uid), $this->equalTo('user_ldap'),
|
2014-03-27 21:01:14 +04:00
|
|
|
$this->equalTo(User::USER_PREFKEY_LASTREFRESH),
|
|
|
|
$this->equalTo(0))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(0);
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->exactly(2))
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('getUserValue');
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('setUserValue')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->uid), $this->equalTo('user_ldap'),
|
2014-03-27 21:01:14 +04:00
|
|
|
$this->equalTo(User::USER_PREFKEY_LASTREFRESH),
|
|
|
|
$this->anything())
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-05 12:29:19 +03:00
|
|
|
$this->connection->expects($this->any())
|
|
|
|
->method('resolveRule')
|
|
|
|
->with('avatar')
|
|
|
|
->willReturn(['jpegphoto', 'thumbnailphoto']);
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->update();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
2019-02-13 02:14:56 +03:00
|
|
|
public function extStorageHomeDataProvider() {
|
|
|
|
return [
|
|
|
|
[ 'myFolder', null ],
|
|
|
|
[ '', null, false ],
|
|
|
|
[ 'myFolder', 'myFolder' ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider extStorageHomeDataProvider
|
|
|
|
*/
|
|
|
|
public function testUpdateExtStorageHome(string $expected, string $valueFromLDAP = null, bool $isSet = true) {
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($valueFromLDAP === null) {
|
2019-02-13 02:14:56 +03:00
|
|
|
$this->connection->expects($this->once())
|
|
|
|
->method('__get')
|
|
|
|
->willReturnMap([
|
|
|
|
['ldapExtStorageHomeAttribute', 'homeDirectory'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$return = [];
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($isSet) {
|
2019-02-13 02:14:56 +03:00
|
|
|
$return[] = $expected;
|
|
|
|
}
|
|
|
|
$this->access->expects($this->once())
|
|
|
|
->method('readAttribute')
|
|
|
|
->with($this->dn, 'homeDirectory')
|
|
|
|
->willReturn($return);
|
|
|
|
}
|
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($expected !== '') {
|
2019-02-13 02:14:56 +03:00
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('setUserValue')
|
|
|
|
->with($this->uid, 'user_ldap', 'extStorageHome', $expected);
|
|
|
|
} else {
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('deleteUserValue')
|
|
|
|
->with($this->uid, 'user_ldap', 'extStorageHome');
|
|
|
|
}
|
|
|
|
|
|
|
|
$actual = $this->user->updateExtStorageHome($valueFromLDAP);
|
|
|
|
$this->assertSame($expected, $actual);
|
|
|
|
}
|
|
|
|
|
2014-03-27 21:01:14 +04:00
|
|
|
public function testUpdateNoRefresh() {
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->at(0))
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('getUserValue')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->uid), $this->equalTo('user_ldap'),
|
2014-03-27 21:01:14 +04:00
|
|
|
$this->equalTo(User::USER_PREFKEY_FIRSTLOGIN),
|
|
|
|
$this->equalTo(0))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(1);
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->at(1))
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('getUserValue')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->uid), $this->equalTo('user_ldap'),
|
2014-03-27 21:01:14 +04:00
|
|
|
$this->equalTo(User::USER_PREFKEY_LASTREFRESH),
|
|
|
|
$this->equalTo(0))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(time() - 10);
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->once())
|
2017-08-09 22:52:23 +03:00
|
|
|
->method('getAppValue')
|
|
|
|
->with($this->equalTo('user_ldap'),
|
|
|
|
$this->equalTo('updateAttributesInterval'),
|
|
|
|
$this->anything())
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(1800);
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->exactly(2))
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('getUserValue');
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->never())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('setUserValue');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->update();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMarkLogin() {
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('setUserValue')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->uid),
|
2014-03-27 21:01:14 +04:00
|
|
|
$this->equalTo('user_ldap'),
|
|
|
|
$this->equalTo(User::USER_PREFKEY_FIRSTLOGIN),
|
|
|
|
$this->equalTo(1))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->markLogin();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetAvatarImageProvided() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->once())
|
2014-03-27 21:01:14 +04:00
|
|
|
->method('readAttribute')
|
2018-07-02 18:38:16 +03:00
|
|
|
->with($this->equalTo($this->dn),
|
2018-07-05 12:29:19 +03:00
|
|
|
$this->equalTo('jpegphoto'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['this is a photo']);
|
2018-07-05 12:29:19 +03:00
|
|
|
$this->connection->expects($this->any())
|
|
|
|
->method('resolveRule')
|
|
|
|
->with('avatar')
|
|
|
|
->willReturn(['jpegphoto', 'thumbnailphoto']);
|
2014-03-27 21:01:14 +04:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$photo = $this->user->getAvatarImage();
|
2014-03-27 21:01:14 +04: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 18:38:16 +03:00
|
|
|
$this->user->getAvatarImage();
|
2014-03-27 21:01:14 +04:00
|
|
|
}
|
2015-08-21 01:55:42 +03:00
|
|
|
|
2018-07-05 12:29:19 +03:00
|
|
|
public function testGetAvatarImageDisabled() {
|
|
|
|
$this->access->expects($this->never())
|
|
|
|
->method('readAttribute')
|
|
|
|
->with($this->equalTo($this->dn), $this->anything());
|
|
|
|
$this->connection->expects($this->any())
|
|
|
|
->method('resolveRule')
|
|
|
|
->with('avatar')
|
|
|
|
->willReturn([]);
|
|
|
|
|
|
|
|
$this->assertFalse($this->user->getAvatarImage());
|
|
|
|
}
|
|
|
|
|
2018-07-03 01:38:25 +03:00
|
|
|
public function imageDataProvider() {
|
|
|
|
return [
|
|
|
|
[ false, false ],
|
|
|
|
[ 'corruptData', false ],
|
|
|
|
[ 'validData', true ],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2015-08-21 01:55:42 +03:00
|
|
|
public function testProcessAttributes() {
|
2019-02-13 02:14:56 +03:00
|
|
|
$requiredMethods = [
|
2015-08-21 01:55:42 +03:00
|
|
|
'markRefreshTime',
|
|
|
|
'updateQuota',
|
|
|
|
'updateEmail',
|
2016-02-03 15:16:55 +03:00
|
|
|
'composeAndStoreDisplayName',
|
2015-08-21 01:55:42 +03:00
|
|
|
'storeLDAPUserName',
|
|
|
|
'getHomePath',
|
2019-02-13 02:14:56 +03:00
|
|
|
'updateAvatar',
|
|
|
|
'updateExtStorageHome',
|
|
|
|
];
|
2015-08-21 01:55:42 +03:00
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var User|\PHPUnit\Framework\MockObject\MockObject $userMock */
|
2018-06-28 02:11:36 +03:00
|
|
|
$userMock = $this->getMockBuilder(User::class)
|
2018-07-02 18:38:16 +03:00
|
|
|
->setConstructorArgs([
|
|
|
|
$this->uid,
|
|
|
|
$this->dn,
|
|
|
|
$this->access,
|
|
|
|
$this->config,
|
|
|
|
$this->filesystemhelper,
|
|
|
|
$this->image,
|
|
|
|
$this->log,
|
|
|
|
$this->avatarManager,
|
|
|
|
$this->userManager,
|
|
|
|
$this->notificationManager
|
|
|
|
])
|
2015-08-21 01:55:42 +03:00
|
|
|
->setMethods($requiredMethods)
|
|
|
|
->getMock();
|
|
|
|
|
2020-03-26 11:30:18 +03:00
|
|
|
$this->connection->setConfiguration([
|
2015-08-21 01:55:42 +03:00
|
|
|
'homeFolderNamingRule' => 'homeDirectory'
|
2020-03-26 11:30:18 +03:00
|
|
|
]);
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->any())
|
2015-08-21 01:55:42 +03:00
|
|
|
->method('__get')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($name) {
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($name === 'homeFolderNamingRule') {
|
2015-08-21 01:55:42 +03:00
|
|
|
return 'attr:homeDirectory';
|
|
|
|
}
|
|
|
|
return $name;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2018-07-05 12:29:19 +03:00
|
|
|
$this->connection->expects($this->any())
|
|
|
|
->method('resolveRule')
|
|
|
|
->with('avatar')
|
|
|
|
->willReturn(['jpegphoto', 'thumbnailphoto']);
|
|
|
|
|
|
|
|
$record = [
|
|
|
|
strtolower($this->connection->ldapQuotaAttribute) => ['4096'],
|
|
|
|
strtolower($this->connection->ldapEmailAttribute) => ['alice@wonderland.org'],
|
|
|
|
strtolower($this->connection->ldapUserDisplayName) => ['Aaaaalice'],
|
2019-02-13 02:14:56 +03:00
|
|
|
strtolower($this->connection->ldapExtStorageHomeAttribute) => ['homeDirectory'],
|
2018-07-02 18:38:16 +03:00
|
|
|
'uid' => [$this->uid],
|
2018-07-05 12:29:19 +03:00
|
|
|
'homedirectory' => ['Alice\'s Folder'],
|
|
|
|
'memberof' => ['cn=groupOne', 'cn=groupTwo'],
|
|
|
|
'jpegphoto' => ['here be an image']
|
|
|
|
];
|
2015-08-21 01:55:42 +03:00
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
foreach ($requiredMethods as $method) {
|
2015-08-21 01:55:42 +03:00
|
|
|
$userMock->expects($this->once())
|
|
|
|
->method($method);
|
|
|
|
}
|
2019-11-25 23:09:05 +03:00
|
|
|
\OC_Hook::clear();//disconnect irrelevant hooks
|
2015-08-21 01:55:42 +03:00
|
|
|
$userMock->processAttributes($record);
|
2018-07-02 18:38:16 +03:00
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */
|
|
|
|
\OC_Hook::emit('OC_User', 'post_login', ['uid' => $this->uid]);
|
2015-08-21 01:55:42 +03:00
|
|
|
}
|
2015-09-23 17:52:48 +03:00
|
|
|
|
|
|
|
public function emptyHomeFolderAttributeValueProvider() {
|
2020-03-26 11:30:18 +03:00
|
|
|
return [
|
2018-07-02 18:38:16 +03:00
|
|
|
'empty' => [''],
|
|
|
|
'prefixOnly' => ['attr:'],
|
2020-03-26 11:30:18 +03:00
|
|
|
];
|
2015-09-23 17:52:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider emptyHomeFolderAttributeValueProvider
|
|
|
|
*/
|
|
|
|
public function testGetHomePathNotConfigured($attributeValue) {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->any())
|
2015-09-23 17:52:48 +03:00
|
|
|
->method('__get')
|
|
|
|
->with($this->equalTo('homeFolderNamingRule'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($attributeValue);
|
2015-09-23 17:52:48 +03:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->never())
|
2015-09-23 17:52:48 +03:00
|
|
|
->method('readAttribute');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->never())
|
2015-09-23 17:52:48 +03:00
|
|
|
->method('getAppValue');
|
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */
|
|
|
|
$this->assertFalse($this->user->getHomePath());
|
2015-09-23 17:52:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetHomePathConfiguredNotAvailableAllowed() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->any())
|
2015-09-23 17:52:48 +03:00
|
|
|
->method('__get')
|
|
|
|
->with($this->equalTo('homeFolderNamingRule'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('attr:foobar');
|
2015-09-23 17:52:48 +03:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->once())
|
2015-09-23 17:52:48 +03:00
|
|
|
->method('readAttribute')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2015-09-23 17:52:48 +03:00
|
|
|
|
|
|
|
// asks for "enforce_home_folder_naming_rule"
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->once())
|
2015-09-23 17:52:48 +03:00
|
|
|
->method('getAppValue')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2015-09-23 17:52:48 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */
|
|
|
|
$this->assertFalse($this->user->getHomePath());
|
2015-09-23 17:52:48 +03:00
|
|
|
}
|
|
|
|
|
2019-11-25 23:09:05 +03:00
|
|
|
|
2015-09-23 17:52:48 +03:00
|
|
|
public function testGetHomePathConfiguredNotAvailableNotAllowed() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->any())
|
2015-09-23 17:52:48 +03:00
|
|
|
->method('__get')
|
|
|
|
->with($this->equalTo('homeFolderNamingRule'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('attr:foobar');
|
2015-09-23 17:52:48 +03:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->once())
|
2015-09-23 17:52:48 +03:00
|
|
|
->method('readAttribute')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2015-09-23 17:52:48 +03:00
|
|
|
|
|
|
|
// asks for "enforce_home_folder_naming_rule"
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->once())
|
2015-09-23 17:52:48 +03:00
|
|
|
->method('getAppValue')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-09-23 17:52:48 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->user->getHomePath();
|
2015-09-23 17:52:48 +03:00
|
|
|
}
|
2016-02-03 15:16:55 +03:00
|
|
|
|
|
|
|
public function displayNameProvider() {
|
|
|
|
return [
|
2018-10-26 18:38:42 +03:00
|
|
|
['Roland Deschain', '', 'Roland Deschain', false],
|
|
|
|
['Roland Deschain', '', 'Roland Deschain', true],
|
|
|
|
['Roland Deschain', null, 'Roland Deschain', false],
|
|
|
|
['Roland Deschain', 'gunslinger@darktower.com', 'Roland Deschain (gunslinger@darktower.com)', false],
|
|
|
|
['Roland Deschain', 'gunslinger@darktower.com', 'Roland Deschain (gunslinger@darktower.com)', true],
|
2016-02-03 15:16:55 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider displayNameProvider
|
|
|
|
*/
|
2018-10-26 18:38:42 +03:00
|
|
|
public function testComposeAndStoreDisplayName($part1, $part2, $expected, $expectTriggerChange) {
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->config->expects($this->once())
|
2016-02-03 15:16:55 +03:00
|
|
|
->method('setUserValue');
|
2018-10-26 18:38:42 +03:00
|
|
|
$oldName = $expectTriggerChange ? 'xxGunslingerxx' : null;
|
2018-10-26 00:41:12 +03:00
|
|
|
$this->config->expects($this->once())
|
2018-10-26 18:38:42 +03:00
|
|
|
->method('getUserValue')
|
|
|
|
->with($this->user->getUsername(), 'user_ldap', 'displayName', null)
|
|
|
|
->willReturn($oldName);
|
2018-10-26 00:41:12 +03:00
|
|
|
|
|
|
|
$ncUserObj = $this->createMock(\OC\User\User::class);
|
2018-10-26 18:38:42 +03:00
|
|
|
if ($expectTriggerChange) {
|
|
|
|
$ncUserObj->expects($this->once())
|
|
|
|
->method('triggerChange')
|
|
|
|
->with('displayName', $expected);
|
|
|
|
} else {
|
|
|
|
$ncUserObj->expects($this->never())
|
|
|
|
->method('triggerChange');
|
|
|
|
}
|
2018-10-26 00:41:12 +03:00
|
|
|
$this->userManager->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->willReturn($ncUserObj);
|
2016-02-03 15:16:55 +03:00
|
|
|
|
2018-07-02 18:38:16 +03:00
|
|
|
$displayName = $this->user->composeAndStoreDisplayName($part1, $part2);
|
2016-02-03 15:16:55 +03:00
|
|
|
$this->assertSame($expected, $displayName);
|
|
|
|
}
|
2017-03-31 10:16:22 +03:00
|
|
|
|
2018-10-26 00:41:12 +03:00
|
|
|
public function testComposeAndStoreDisplayNameNoOverwrite() {
|
|
|
|
$displayName = 'Randall Flagg';
|
|
|
|
$this->config->expects($this->never())
|
|
|
|
->method('setUserValue');
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('getUserValue')
|
|
|
|
->willReturn($displayName);
|
|
|
|
|
|
|
|
$this->userManager->expects($this->never())
|
|
|
|
->method('get'); // Implicit: no triggerChange can be called
|
|
|
|
|
|
|
|
$composedDisplayName = $this->user->composeAndStoreDisplayName($displayName);
|
|
|
|
$this->assertSame($composedDisplayName, $displayName);
|
|
|
|
}
|
|
|
|
|
2017-03-31 10:16:22 +03:00
|
|
|
public function testHandlePasswordExpiryWarningDefaultPolicy() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->any())
|
2017-03-31 10:16:22 +03:00
|
|
|
->method('__get')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($name) {
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($name === 'ldapDefaultPPolicyDN') {
|
2017-03-31 10:16:22 +03:00
|
|
|
return 'cn=default,ou=policies,dc=foo,dc=bar';
|
|
|
|
}
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($name === 'turnOnPasswordChange') {
|
2017-03-31 10:16:22 +03:00
|
|
|
return '1';
|
|
|
|
}
|
|
|
|
return $name;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2017-03-31 10:16:22 +03:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->any())
|
2017-04-07 13:06:50 +03:00
|
|
|
->method('search')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($filter, $base) {
|
2020-04-16 10:25:17 +03:00
|
|
|
if ($base === $this->dn) {
|
2018-07-02 18:38:16 +03:00
|
|
|
return [
|
|
|
|
[
|
|
|
|
'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'],
|
2017-08-09 17:43:40 +03:00
|
|
|
'pwdgraceusetime' => [],
|
2018-07-02 18:38:16 +03:00
|
|
|
],
|
|
|
|
];
|
2017-03-31 10:16:22 +03:00
|
|
|
}
|
2020-04-16 10:25:17 +03:00
|
|
|
if ($base === 'cn=default,ou=policies,dc=foo,dc=bar') {
|
2018-07-02 18:38:16 +03:00
|
|
|
return [
|
|
|
|
[
|
|
|
|
'pwdmaxage' => ['2592000'],
|
|
|
|
'pwdexpirewarning' => ['2591999'],
|
|
|
|
],
|
|
|
|
];
|
2017-03-31 10:16:22 +03:00
|
|
|
}
|
2018-07-02 18:38:16 +03:00
|
|
|
return [];
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2017-03-31 10:16:22 +03:00
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$notification = $this->getMockBuilder(INotification::class)
|
2017-03-31 10:16:22 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$notification->expects($this->any())
|
|
|
|
->method('setApp')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($notification);
|
2017-03-31 10:16:22 +03:00
|
|
|
$notification->expects($this->any())
|
|
|
|
->method('setUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($notification);
|
2017-03-31 10:16:22 +03:00
|
|
|
$notification->expects($this->any())
|
|
|
|
->method('setObject')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($notification);
|
2017-03-31 10:16:22 +03:00
|
|
|
$notification->expects($this->any())
|
|
|
|
->method('setDateTime')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($notification);
|
2018-07-02 18:38:16 +03:00
|
|
|
|
|
|
|
$this->notificationManager->expects($this->exactly(2))
|
2017-03-31 10:16:22 +03:00
|
|
|
->method('createNotification')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($notification);
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->notificationManager->expects($this->exactly(1))
|
2017-03-31 10:16:22 +03:00
|
|
|
->method('notify');
|
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
\OC_Hook::clear();//disconnect irrelevant hooks
|
2018-07-02 18:38:16 +03: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 10:16:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testHandlePasswordExpiryWarningCustomPolicy() {
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->connection->expects($this->any())
|
2017-03-31 10:16:22 +03:00
|
|
|
->method('__get')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($name) {
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($name === 'ldapDefaultPPolicyDN') {
|
2017-03-31 10:16:22 +03:00
|
|
|
return 'cn=default,ou=policies,dc=foo,dc=bar';
|
|
|
|
}
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($name === 'turnOnPasswordChange') {
|
2017-03-31 10:16:22 +03:00
|
|
|
return '1';
|
|
|
|
}
|
|
|
|
return $name;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2017-03-31 10:16:22 +03:00
|
|
|
|
2017-11-03 19:40:05 +03:00
|
|
|
$this->access->expects($this->any())
|
2017-04-07 13:06:50 +03:00
|
|
|
->method('search')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($filter, $base) {
|
2020-04-16 10:25:17 +03:00
|
|
|
if ($base === $this->dn) {
|
2018-07-02 18:38:16 +03:00
|
|
|
return [
|
|
|
|
[
|
|
|
|
'pwdpolicysubentry' => ['cn=custom,ou=policies,dc=foo,dc=bar'],
|
|
|
|
'pwdchangedtime' => [(new \DateTime())->sub(new \DateInterval('P28D'))->format('Ymdhis').'Z'],
|
2017-08-09 17:43:40 +03:00
|
|
|
'pwdgraceusetime' => [],
|
2018-07-02 18:38:16 +03:00
|
|
|
]
|
|
|
|
];
|
2017-03-31 10:16:22 +03:00
|
|
|
}
|
2020-03-18 19:40:23 +03:00
|
|
|
if ($base === 'cn=custom,ou=policies,dc=foo,dc=bar') {
|
2018-07-02 18:38:16 +03:00
|
|
|
return [
|
|
|
|
[
|
|
|
|
'pwdmaxage' => ['2592000'],
|
|
|
|
'pwdexpirewarning' => ['2591999'],
|
|
|
|
]
|
|
|
|
];
|
2017-03-31 10:16:22 +03:00
|
|
|
}
|
2018-07-02 18:38:16 +03:00
|
|
|
return [];
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2017-03-31 10:16:22 +03:00
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$notification = $this->getMockBuilder(INotification::class)
|
2017-03-31 10:16:22 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$notification->expects($this->any())
|
|
|
|
->method('setApp')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($notification);
|
2017-03-31 10:16:22 +03:00
|
|
|
$notification->expects($this->any())
|
|
|
|
->method('setUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($notification);
|
2017-03-31 10:16:22 +03:00
|
|
|
$notification->expects($this->any())
|
|
|
|
->method('setObject')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($notification);
|
2017-03-31 10:16:22 +03:00
|
|
|
$notification->expects($this->any())
|
|
|
|
->method('setDateTime')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($notification);
|
2018-07-02 18:38:16 +03:00
|
|
|
|
|
|
|
$this->notificationManager->expects($this->exactly(2))
|
2017-03-31 10:16:22 +03:00
|
|
|
->method('createNotification')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($notification);
|
2018-07-02 18:38:16 +03:00
|
|
|
$this->notificationManager->expects($this->exactly(1))
|
2017-03-31 10:16:22 +03:00
|
|
|
->method('notify');
|
|
|
|
|
2018-07-02 18:38:16 +03: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 10:16:22 +03:00
|
|
|
}
|
2014-04-24 15:32:50 +04:00
|
|
|
}
|