2014-12-22 16:54:50 +03: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>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
|
|
* @author Daniel Calviño Sánchez <danxuliu@gmail.com>
|
2020-08-24 15:54:25 +03:00
|
|
|
* @author Daniel Kesselberg <mail@danielkesselberg.de>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2020-08-24 15:54:25 +03:00
|
|
|
* @author GretaD <gretadoci@gmail.com>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author michag86 <micha_g@arcor.de>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2020-12-16 16:54:15 +03:00
|
|
|
* @author Sujith Haridasan <sujith.h@gmail.com>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Thomas Citharel <nextcloud@tcit.fr>
|
2015-06-25 12:43:55 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Tom Needham <tom@owncloud.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author zulan <git@zulan.net>
|
2014-12-22 16:54:50 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @license AGPL-3.0
|
2014-12-22 16:54:50 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* 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.
|
2015-02-26 13:37:37 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2014-12-22 16:54:50 +03:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 13:44:34 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2014-12-22 16:54:50 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* 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/>
|
2014-12-22 16:54:50 +03:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
namespace OCA\Provisioning_API\Tests\Controller;
|
2014-12-22 16:54:50 +03:00
|
|
|
|
2017-02-28 12:40:49 +03:00
|
|
|
use Exception;
|
2017-01-24 16:07:52 +03:00
|
|
|
use OC\Accounts\AccountManager;
|
2019-07-09 10:05:30 +03:00
|
|
|
use OC\Authentication\Token\RemoteWipe;
|
2017-02-28 12:40:49 +03:00
|
|
|
use OC\Group\Manager;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OC\SubAdmin;
|
2018-01-26 14:47:59 +03:00
|
|
|
use OCA\FederatedFileSharing\FederatedShareProvider;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCA\Provisioning_API\Controller\UsersController;
|
2020-07-13 17:23:59 +03:00
|
|
|
use OCA\Provisioning_API\FederatedShareProviderFactory;
|
2019-09-17 17:33:27 +03:00
|
|
|
use OCA\Settings\Mailer\NewUserMailHelper;
|
2020-12-01 16:33:22 +03:00
|
|
|
use OCP\Accounts\IAccountManager;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\App\IAppManager;
|
2017-01-18 16:34:38 +03:00
|
|
|
use OCP\AppFramework\Http\DataResponse;
|
2020-08-09 17:36:19 +03:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2017-02-28 12:40:49 +03:00
|
|
|
use OCP\IConfig;
|
2017-01-18 16:34:38 +03:00
|
|
|
use OCP\IGroup;
|
2017-02-24 09:01:13 +03:00
|
|
|
use OCP\IL10N;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\ILogger;
|
2017-01-24 17:45:55 +03:00
|
|
|
use OCP\IRequest;
|
2020-12-02 16:11:47 +03:00
|
|
|
use OCP\IURLGenerator;
|
2017-01-18 16:34:38 +03:00
|
|
|
use OCP\IUser;
|
2015-08-11 12:08:57 +03:00
|
|
|
use OCP\IUserManager;
|
|
|
|
use OCP\IUserSession;
|
2017-02-24 09:01:13 +03:00
|
|
|
use OCP\L10N\IFactory;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\Mail\IEMailTemplate;
|
2020-08-09 17:36:19 +03:00
|
|
|
use OCP\Security\Events\GenerateSecurePasswordEvent;
|
2018-03-16 17:30:48 +03:00
|
|
|
use OCP\Security\ISecureRandom;
|
2018-11-07 18:35:51 +03:00
|
|
|
use OCP\UserInterface;
|
2019-07-09 10:05:30 +03:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2017-02-28 12:40:49 +03:00
|
|
|
use Test\TestCase;
|
2015-08-11 12:08:57 +03:00
|
|
|
|
2017-02-28 12:40:49 +03:00
|
|
|
class UsersControllerTest extends TestCase {
|
2017-01-24 16:07:52 +03:00
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IUserManager|MockObject */
|
2015-08-11 12:08:57 +03:00
|
|
|
protected $userManager;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IConfig|MockObject */
|
2015-08-11 12:08:57 +03:00
|
|
|
protected $config;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IAppManager|MockObject */
|
2017-06-02 11:09:42 +03:00
|
|
|
protected $appManager;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var Manager|MockObject */
|
2015-08-11 12:08:57 +03:00
|
|
|
protected $groupManager;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IUserSession|MockObject */
|
2015-08-11 12:08:57 +03:00
|
|
|
protected $userSession;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var ILogger|MockObject */
|
2015-10-27 16:09:45 +03:00
|
|
|
protected $logger;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var UsersController|MockObject */
|
2015-10-27 16:09:45 +03:00
|
|
|
protected $api;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var AccountManager|MockObject */
|
2017-01-24 16:07:52 +03:00
|
|
|
protected $accountManager;
|
2020-12-02 16:11:47 +03:00
|
|
|
/** @var IURLGenerator|MockObject */
|
|
|
|
protected $urlGenerator;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IRequest|MockObject */
|
2017-02-28 12:40:49 +03:00
|
|
|
protected $request;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IFactory|MockObject */
|
2017-02-24 09:01:13 +03:00
|
|
|
private $l10nFactory;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var NewUserMailHelper|MockObject */
|
2017-04-07 15:51:05 +03:00
|
|
|
private $newUserMailHelper;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var FederatedShareProviderFactory|MockObject */
|
2020-07-13 17:23:59 +03:00
|
|
|
private $federatedShareProviderFactory;
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var ISecureRandom|MockObject */
|
2018-03-16 17:30:48 +03:00
|
|
|
private $secureRandom;
|
2019-07-09 10:05:30 +03:00
|
|
|
/** @var RemoteWipe|MockObject */
|
|
|
|
private $remoteWipe;
|
2020-08-09 17:36:19 +03:00
|
|
|
/** @var IEventDispatcher */
|
|
|
|
private $eventDispatcher;
|
2017-02-24 09:01:13 +03:00
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2016-04-07 18:22:21 +03:00
|
|
|
parent::setUp();
|
2015-07-25 13:46:39 +03:00
|
|
|
|
2017-02-28 12:40:49 +03:00
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2017-06-02 11:09:42 +03:00
|
|
|
$this->appManager = $this->createMock(IAppManager::class);
|
2017-02-28 12:40:49 +03:00
|
|
|
$this->groupManager = $this->createMock(Manager::class);
|
|
|
|
$this->userSession = $this->createMock(IUserSession::class);
|
|
|
|
$this->logger = $this->createMock(ILogger::class);
|
|
|
|
$this->request = $this->createMock(IRequest::class);
|
|
|
|
$this->accountManager = $this->createMock(AccountManager::class);
|
2020-12-02 16:11:47 +03:00
|
|
|
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->l10nFactory = $this->createMock(IFactory::class);
|
2017-04-07 15:51:05 +03:00
|
|
|
$this->newUserMailHelper = $this->createMock(NewUserMailHelper::class);
|
2020-07-13 17:23:59 +03:00
|
|
|
$this->federatedShareProviderFactory = $this->createMock(FederatedShareProviderFactory::class);
|
2018-03-16 17:30:48 +03:00
|
|
|
$this->secureRandom = $this->createMock(ISecureRandom::class);
|
2019-07-09 10:05:30 +03:00
|
|
|
$this->remoteWipe = $this->createMock(RemoteWipe::class);
|
2020-08-09 17:36:19 +03:00
|
|
|
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
2017-02-24 09:01:13 +03:00
|
|
|
|
2017-02-28 12:40:49 +03:00
|
|
|
$this->api = $this->getMockBuilder(UsersController::class)
|
2015-10-27 16:09:45 +03:00
|
|
|
->setConstructorArgs([
|
2016-08-11 20:49:45 +03:00
|
|
|
'provisioning_api',
|
2017-01-24 17:45:55 +03:00
|
|
|
$this->request,
|
2016-05-11 20:38:49 +03:00
|
|
|
$this->userManager,
|
|
|
|
$this->config,
|
2017-06-02 11:09:42 +03:00
|
|
|
$this->appManager,
|
2016-05-11 20:38:49 +03:00
|
|
|
$this->groupManager,
|
|
|
|
$this->userSession,
|
2017-01-24 16:07:52 +03:00
|
|
|
$this->accountManager,
|
2020-12-02 16:11:47 +03:00
|
|
|
$this->urlGenerator,
|
2016-05-11 20:38:49 +03:00
|
|
|
$this->logger,
|
2017-04-07 15:51:05 +03:00
|
|
|
$this->l10nFactory,
|
2018-01-26 14:47:59 +03:00
|
|
|
$this->newUserMailHelper,
|
2020-07-13 17:23:59 +03:00
|
|
|
$this->federatedShareProviderFactory,
|
2019-07-09 10:05:30 +03:00
|
|
|
$this->secureRandom,
|
|
|
|
$this->remoteWipe,
|
2020-08-09 17:36:19 +03:00
|
|
|
$this->eventDispatcher,
|
2016-05-11 20:38:49 +03:00
|
|
|
])
|
2015-10-27 16:09:45 +03:00
|
|
|
->setMethods(['fillStorageInfo'])
|
|
|
|
->getMock();
|
|
|
|
}
|
2015-08-19 10:43:40 +03:00
|
|
|
|
|
|
|
public function testGetUsersAsAdmin() {
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('admin');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('search')
|
2018-03-16 13:44:20 +03:00
|
|
|
->with('MyCustomSearch')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['Admin' => [], 'Foo' => [], 'Bar' => []]);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$expected = ['users' => [
|
2020-04-09 10:22:29 +03:00
|
|
|
'Admin',
|
|
|
|
'Foo',
|
|
|
|
'Bar',
|
|
|
|
],
|
2016-08-11 20:49:45 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, $this->api->getUsers('MyCustomSearch')->getData());
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-08-19 10:43:40 +03:00
|
|
|
public function testGetUsersAsSubAdmin() {
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2016-07-12 09:38:56 +03:00
|
|
|
$firstGroup = $this->getMockBuilder('OCP\IGroup')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$firstGroup
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getGID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('FirstGroup');
|
2016-07-12 09:38:56 +03:00
|
|
|
$secondGroup = $this->getMockBuilder('OCP\IGroup')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$secondGroup
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getGID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('SecondGroup');
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isSubAdmin')
|
|
|
|
->with($loggedInUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdminsGroups')
|
|
|
|
->with($loggedInUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([$firstGroup, $secondGroup]);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->any())
|
|
|
|
->method('displayNamesInGroup')
|
|
|
|
->will($this->onConsecutiveCalls(['AnotherUserInTheFirstGroup' => []], ['UserInTheSecondGroup' => []]));
|
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$expected = [
|
2015-10-27 16:09:45 +03:00
|
|
|
'users' => [
|
|
|
|
'AnotherUserInTheFirstGroup',
|
|
|
|
'UserInTheSecondGroup',
|
|
|
|
],
|
2016-08-11 20:49:45 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, $this->api->getUsers('MyCustomSearch')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testAddUserAlreadyExisting() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(102);
|
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with('AlreadyExistingUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->logger
|
|
|
|
->expects($this->once())
|
|
|
|
->method('error')
|
|
|
|
->with('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']);
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-08-27 19:29:28 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('adminUser');
|
2015-08-27 19:29:28 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-08-27 19:29:28 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('adminUser')
|
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2018-04-19 01:12:06 +03:00
|
|
|
$this->api->addUser('AlreadyExistingUser', 'password', '', '', []);
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
2015-08-11 12:08:57 +03:00
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-30 11:30:00 +03:00
|
|
|
public function testAddUserNonExistingGroup() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('group NonExistingGroup does not exist');
|
|
|
|
$this->expectExceptionCode(104);
|
|
|
|
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with('NewUser')
|
|
|
|
->willReturn(false);
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-30 11:30:00 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('adminUser');
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('adminUser')
|
|
|
|
->willReturn(true);
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('groupExists')
|
|
|
|
->with('NonExistingGroup')
|
|
|
|
->willReturn(false);
|
|
|
|
|
2018-04-19 01:12:06 +03:00
|
|
|
$this->api->addUser('NewUser', 'pass', '', '', ['NonExistingGroup']);
|
2015-10-30 11:30:00 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-30 11:30:00 +03:00
|
|
|
public function testAddUserExistingGroupNonExistingGroup() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('group NonExistingGroup does not exist');
|
|
|
|
$this->expectExceptionCode(104);
|
|
|
|
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with('NewUser')
|
|
|
|
->willReturn(false);
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-30 11:30:00 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('adminUser');
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('adminUser')
|
|
|
|
->willReturn(true);
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('groupExists')
|
|
|
|
->withConsecutive(
|
|
|
|
['ExistingGroup'],
|
|
|
|
['NonExistingGroup']
|
|
|
|
)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnMap([
|
2015-10-30 11:30:00 +03:00
|
|
|
['ExistingGroup', true],
|
|
|
|
['NonExistingGroup', false]
|
2020-03-26 00:21:27 +03:00
|
|
|
]);
|
2015-10-30 11:30:00 +03:00
|
|
|
|
2018-04-19 01:12:06 +03:00
|
|
|
$this->api->addUser('NewUser', 'pass', '', '', ['ExistingGroup', 'NonExistingGroup']);
|
2015-10-30 11:30:00 +03:00
|
|
|
}
|
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testAddUserSuccessful() {
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
2015-08-11 12:08:57 +03:00
|
|
|
->method('userExists')
|
2015-10-27 16:09:45 +03:00
|
|
|
->with('NewUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
2015-08-11 12:08:57 +03:00
|
|
|
->method('createUser')
|
2015-10-27 16:09:45 +03:00
|
|
|
->with('NewUser', 'PasswordOfTheNewUser');
|
|
|
|
$this->logger
|
|
|
|
->expects($this->once())
|
|
|
|
->method('info')
|
|
|
|
->with('Successful addUser call with userid: NewUser', ['app' => 'ocs_api']);
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-08-27 19:29:28 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('adminUser');
|
2015-08-27 19:29:28 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-08-27 19:29:28 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('adminUser')
|
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->assertTrue(key_exists(
|
2019-06-21 17:38:25 +03:00
|
|
|
'id',
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->api->addUser('NewUser', 'PasswordOfTheNewUser')->getData()
|
|
|
|
));
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
2015-08-11 12:08:57 +03:00
|
|
|
|
2018-04-19 01:12:06 +03:00
|
|
|
public function testAddUserSuccessfulWithDisplayName() {
|
2020-12-02 16:11:47 +03:00
|
|
|
$api = $this->getMockBuilder(UsersController::class)
|
2018-04-19 01:12:06 +03:00
|
|
|
->setConstructorArgs([
|
|
|
|
'provisioning_api',
|
|
|
|
$this->request,
|
|
|
|
$this->userManager,
|
|
|
|
$this->config,
|
|
|
|
$this->appManager,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->userSession,
|
|
|
|
$this->accountManager,
|
2020-12-02 16:11:47 +03:00
|
|
|
$this->urlGenerator,
|
2018-04-19 01:12:06 +03:00
|
|
|
$this->logger,
|
|
|
|
$this->l10nFactory,
|
|
|
|
$this->newUserMailHelper,
|
2020-07-13 17:23:59 +03:00
|
|
|
$this->federatedShareProviderFactory,
|
2019-07-09 10:05:30 +03:00
|
|
|
$this->secureRandom,
|
2020-08-09 17:36:19 +03:00
|
|
|
$this->remoteWipe,
|
|
|
|
$this->eventDispatcher,
|
2018-04-19 01:12:06 +03:00
|
|
|
])
|
|
|
|
->setMethods(['editUser'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with('NewUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2018-04-19 01:12:06 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('createUser')
|
|
|
|
->with('NewUser', 'PasswordOfTheNewUser');
|
|
|
|
$this->logger
|
|
|
|
->expects($this->once())
|
|
|
|
->method('info')
|
|
|
|
->with('Successful addUser call with userid: NewUser', ['app' => 'ocs_api']);
|
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('adminUser');
|
2018-04-19 01:12:06 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2018-04-19 01:12:06 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('adminUser')
|
|
|
|
->willReturn(true);
|
|
|
|
$api
|
|
|
|
->expects($this->once())
|
|
|
|
->method('editUser')
|
|
|
|
->with('NewUser', 'display', 'DisplayNameOfTheNewUser');
|
|
|
|
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->assertTrue(key_exists(
|
2019-06-21 17:38:25 +03:00
|
|
|
'id',
|
2019-06-14 18:07:40 +03:00
|
|
|
$api->addUser('NewUser', 'PasswordOfTheNewUser', 'DisplayNameOfTheNewUser')->getData()
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddUserSuccessfulGenerateUserID() {
|
|
|
|
$this->config
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getAppValue')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($appid, $key, $default) {
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($key === 'newUser.generateUserID') {
|
2019-06-21 11:18:44 +03:00
|
|
|
return 'yes';
|
2019-06-14 18:07:40 +03:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->any())
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->anything())
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('createUser')
|
|
|
|
->with($this->anything(), 'PasswordOfTheNewUser');
|
|
|
|
$this->logger
|
|
|
|
->expects($this->once())
|
|
|
|
->method('info')
|
|
|
|
->with($this->stringStartsWith('Successful addUser call with userid: '), ['app' => 'ocs_api']);
|
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('adminUser');
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('adminUser')
|
|
|
|
->willReturn(true);
|
|
|
|
$this->secureRandom->expects($this->any())
|
|
|
|
->method('generate')
|
|
|
|
->with(10)
|
2020-04-10 15:19:56 +03:00
|
|
|
->willReturnCallback(function () {
|
|
|
|
return (string)rand(1000000000, 9999999999);
|
|
|
|
});
|
2019-06-14 18:07:40 +03:00
|
|
|
|
|
|
|
$this->assertTrue(key_exists(
|
2019-06-21 17:38:25 +03:00
|
|
|
'id',
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->api->addUser('', 'PasswordOfTheNewUser')->getData()
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2020-08-09 17:36:19 +03:00
|
|
|
public function testAddUserSuccessfulGeneratePassword() {
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with('NewUser')
|
|
|
|
->willReturn(false);
|
2020-10-05 13:39:00 +03:00
|
|
|
$newUser = $this->createMock(IUser::class);
|
|
|
|
$newUser->expects($this->once())
|
|
|
|
->method('setEMailAddress');
|
2020-08-09 17:36:19 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
2020-10-05 13:39:00 +03:00
|
|
|
->method('createUser')
|
|
|
|
->willReturn($newUser);
|
2020-08-09 17:36:19 +03:00
|
|
|
$this->logger
|
|
|
|
->expects($this->once())
|
|
|
|
->method('info')
|
|
|
|
->with('Successful addUser call with userid: NewUser', ['app' => 'ocs_api']);
|
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
|
|
|
->willReturn('adminUser');
|
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
|
|
|
->willReturn($loggedInUser);
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('adminUser')
|
|
|
|
->willReturn(true);
|
|
|
|
$this->eventDispatcher
|
|
|
|
->expects($this->once())
|
|
|
|
->method('dispatchTyped')
|
|
|
|
->with(new GenerateSecurePasswordEvent());
|
|
|
|
|
|
|
|
$this->assertTrue(key_exists(
|
|
|
|
'id',
|
|
|
|
$this->api->addUser('NewUser', '', '', 'foo@bar')->getData()
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2019-06-14 18:07:40 +03:00
|
|
|
public function testAddUserFailedToGenerateUserID() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('Could not create non-existing user id');
|
|
|
|
$this->expectExceptionCode(111);
|
|
|
|
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->config
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getAppValue')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($appid, $key, $default) {
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($key === 'newUser.generateUserID') {
|
2019-06-21 11:18:44 +03:00
|
|
|
return 'yes';
|
2019-06-14 18:07:40 +03:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->any())
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->anything())
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->never())
|
|
|
|
->method('createUser');
|
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('adminUser');
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('adminUser')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$this->api->addUser('', 'PasswordOfTheNewUser')->getData();
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2019-06-14 18:07:40 +03:00
|
|
|
public function testAddUserEmailRequired() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('Required email address was not provided');
|
|
|
|
$this->expectExceptionCode(110);
|
|
|
|
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->config
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getAppValue')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($appid, $key, $default) {
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($key === 'newUser.requireEmail') {
|
2019-06-21 11:18:44 +03:00
|
|
|
return 'yes';
|
2019-06-14 18:07:40 +03:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with('NewUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->never())
|
|
|
|
->method('createUser');
|
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('adminUser');
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('adminUser')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$this->assertTrue(key_exists(
|
2019-06-21 17:38:25 +03:00
|
|
|
'id',
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->api->addUser('NewUser', 'PasswordOfTheNewUser')->getData()
|
|
|
|
));
|
2018-04-19 01:12:06 +03:00
|
|
|
}
|
|
|
|
|
2015-10-30 11:30:00 +03:00
|
|
|
public function testAddUserExistingGroup() {
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with('NewUser')
|
|
|
|
->willReturn(false);
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-30 11:30:00 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('adminUser');
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('adminUser')
|
|
|
|
->willReturn(true);
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('groupExists')
|
|
|
|
->with('ExistingGroup')
|
|
|
|
->willReturn(true);
|
2017-02-28 12:40:49 +03:00
|
|
|
$user = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('createUser')
|
|
|
|
->with('NewUser', 'PasswordOfTheNewUser')
|
|
|
|
->willReturn($user);
|
2016-07-12 09:38:56 +03:00
|
|
|
$group = $this->getMockBuilder('OCP\IGroup')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-30 11:30:00 +03:00
|
|
|
$group
|
|
|
|
->expects($this->once())
|
|
|
|
->method('addUser')
|
|
|
|
->with($user);
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('ExistingGroup')
|
|
|
|
->willReturn($group);
|
|
|
|
$this->logger
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('info')
|
|
|
|
->withConsecutive(
|
|
|
|
['Successful addUser call with userid: NewUser', ['app' => 'ocs_api']],
|
|
|
|
['Added userid NewUser to group ExistingGroup', ['app' => 'ocs_api']]
|
|
|
|
);
|
|
|
|
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->assertTrue(key_exists(
|
2019-06-21 17:38:25 +03:00
|
|
|
'id',
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData()
|
|
|
|
));
|
2015-10-30 11:30:00 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testAddUserUnsuccessful() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('Bad request');
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2018-01-17 17:21:56 +03:00
|
|
|
$exception = new Exception('User backend not found.');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with('NewUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('createUser')
|
|
|
|
->with('NewUser', 'PasswordOfTheNewUser')
|
2018-01-17 17:21:56 +03:00
|
|
|
->will($this->throwException($exception));
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->logger
|
|
|
|
->expects($this->once())
|
2018-01-17 17:21:56 +03:00
|
|
|
->method('logException')
|
|
|
|
->with($exception, [
|
|
|
|
'message' => 'Failed addUser attempt with exception.',
|
2018-04-25 16:22:28 +03:00
|
|
|
'level' => ILogger::ERROR,
|
2018-01-17 17:21:56 +03:00
|
|
|
'app' => 'ocs_api',
|
|
|
|
]);
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-08-27 19:29:28 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('adminUser');
|
2015-08-27 19:29:28 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-08-27 19:29:28 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('adminUser')
|
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->addUser('NewUser', 'PasswordOfTheNewUser');
|
2015-10-30 11:30:00 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-30 11:30:00 +03:00
|
|
|
public function testAddUserAsSubAdminNoGroup() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('no group specified (required for subadmins)');
|
|
|
|
$this->expectExceptionCode(106);
|
|
|
|
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-30 11:30:00 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('regularUser');
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('regularUser')
|
|
|
|
->willReturn(false);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-30 11:30:00 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
|
|
|
->with()
|
|
|
|
->willReturn($subAdminManager);
|
|
|
|
|
2018-04-19 01:12:06 +03:00
|
|
|
$this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', []);
|
2015-10-30 11:30:00 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-30 11:30:00 +03:00
|
|
|
public function testAddUserAsSubAdminValidGroupNotSubAdmin() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('insufficient privileges for group ExistingGroup');
|
|
|
|
$this->expectExceptionCode(105);
|
|
|
|
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-30 11:30:00 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('regularUser');
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('regularUser')
|
|
|
|
->willReturn(false);
|
2016-07-12 09:38:56 +03:00
|
|
|
$existingGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('ExistingGroup')
|
|
|
|
->willReturn($existingGroup);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-30 11:30:00 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isSubAdminOfGroup')
|
|
|
|
->with($loggedInUser, $existingGroup)
|
2016-04-07 18:22:21 +03:00
|
|
|
->willReturn(false);
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
|
|
|
->with()
|
|
|
|
->willReturn($subAdminManager);
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('groupExists')
|
|
|
|
->with('ExistingGroup')
|
|
|
|
->willReturn(true);
|
|
|
|
|
2018-04-19 01:12:06 +03:00
|
|
|
$this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData();
|
2015-10-30 11:30:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddUserAsSubAdminExistingGroups() {
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with('NewUser')
|
|
|
|
->willReturn(false);
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-30 11:30:00 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subAdminUser');
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('subAdminUser')
|
|
|
|
->willReturn(false);
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('groupExists')
|
|
|
|
->withConsecutive(
|
|
|
|
['ExistingGroup1'],
|
|
|
|
['ExistingGroup2']
|
|
|
|
)
|
|
|
|
->willReturn(true);
|
2017-02-28 12:40:49 +03:00
|
|
|
$user = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('createUser')
|
|
|
|
->with('NewUser', 'PasswordOfTheNewUser')
|
|
|
|
->willReturn($user);
|
2016-07-12 09:38:56 +03:00
|
|
|
$existingGroup1 = $this->getMockBuilder('OCP\IGroup')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$existingGroup2 = $this->getMockBuilder('OCP\IGroup')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-30 11:30:00 +03:00
|
|
|
$existingGroup1
|
|
|
|
->expects($this->once())
|
|
|
|
->method('addUser')
|
|
|
|
->with($user);
|
|
|
|
$existingGroup2
|
|
|
|
->expects($this->once())
|
|
|
|
->method('addUser')
|
|
|
|
->with($user);
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->exactly(4))
|
|
|
|
->method('get')
|
|
|
|
->withConsecutive(
|
|
|
|
['ExistingGroup1'],
|
|
|
|
['ExistingGroup2'],
|
|
|
|
['ExistingGroup1'],
|
|
|
|
['ExistingGroup2']
|
|
|
|
)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnMap([
|
2015-10-30 11:30:00 +03:00
|
|
|
['ExistingGroup1', $existingGroup1],
|
|
|
|
['ExistingGroup2', $existingGroup2]
|
2020-03-26 00:21:27 +03:00
|
|
|
]);
|
2015-10-30 11:30:00 +03:00
|
|
|
$this->logger
|
|
|
|
->expects($this->exactly(3))
|
|
|
|
->method('info')
|
|
|
|
->withConsecutive(
|
|
|
|
['Successful addUser call with userid: NewUser', ['app' => 'ocs_api']],
|
|
|
|
['Added userid NewUser to group ExistingGroup1', ['app' => 'ocs_api']],
|
|
|
|
['Added userid NewUser to group ExistingGroup2', ['app' => 'ocs_api']]
|
|
|
|
);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-30 11:30:00 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
|
|
|
->willReturn($subAdminManager);
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('isSubAdminOfGroup')
|
|
|
|
->withConsecutive(
|
|
|
|
[$loggedInUser, $existingGroup1],
|
|
|
|
[$loggedInUser, $existingGroup2]
|
|
|
|
)
|
2016-04-07 18:22:21 +03:00
|
|
|
->willReturn(true);
|
2015-10-30 11:30:00 +03:00
|
|
|
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->assertTrue(key_exists(
|
2019-06-21 17:38:25 +03:00
|
|
|
'id',
|
2019-06-14 18:07:40 +03:00
|
|
|
$this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup1', 'ExistingGroup2'])->getData()
|
|
|
|
));
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testGetUserTargetDoesNotExist() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('User does not exist');
|
|
|
|
$this->expectExceptionCode(404);
|
|
|
|
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToGet')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->getUser('UserToGet');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2017-01-26 13:31:08 +03:00
|
|
|
public function testGetUserDataAsAdmin() {
|
2017-02-09 18:12:57 +03:00
|
|
|
$group = $this->getMockBuilder(IGroup::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2018-03-16 13:44:20 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('admin');
|
2017-02-28 12:40:49 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-12-01 14:05:40 +03:00
|
|
|
$targetUser->expects($this->once())
|
|
|
|
->method('getEMailAddress')
|
2018-03-16 13:44:20 +03:00
|
|
|
->willReturn('demo@nextcloud.com');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
2018-03-16 13:44:20 +03:00
|
|
|
->expects($this->exactly(2))
|
2015-10-27 16:09:45 +03:00
|
|
|
->method('get')
|
2018-03-16 13:44:20 +03:00
|
|
|
->with('UID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('admin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-02-09 18:12:57 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUserGroups')
|
|
|
|
->willReturn([$group, $group, $group]);
|
2018-03-16 13:44:20 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2018-03-16 13:44:20 +03:00
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdminsGroups')
|
|
|
|
->willReturn([$group]);
|
2017-02-09 18:12:57 +03:00
|
|
|
$group->expects($this->at(0))
|
2018-06-15 17:51:53 +03:00
|
|
|
->method('getGID')
|
2017-02-09 18:12:57 +03:00
|
|
|
->willReturn('group0');
|
|
|
|
$group->expects($this->at(1))
|
2018-06-15 17:51:53 +03:00
|
|
|
->method('getGID')
|
2017-02-09 18:12:57 +03:00
|
|
|
->willReturn('group1');
|
|
|
|
$group->expects($this->at(2))
|
2018-06-15 17:51:53 +03:00
|
|
|
->method('getGID')
|
2017-02-09 18:12:57 +03:00
|
|
|
->willReturn('group2');
|
2018-03-16 13:44:20 +03:00
|
|
|
$group->expects($this->at(3))
|
|
|
|
->method('getGID')
|
|
|
|
->willReturn('group3');
|
2017-01-24 16:07:52 +03:00
|
|
|
$this->accountManager->expects($this->any())->method('getUser')
|
|
|
|
->with($targetUser)
|
|
|
|
->willReturn(
|
|
|
|
[
|
2020-12-01 16:33:22 +03:00
|
|
|
IAccountManager::PROPERTY_ADDRESS => ['value' => 'address'],
|
|
|
|
IAccountManager::PROPERTY_PHONE => ['value' => 'phone'],
|
|
|
|
IAccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
|
|
|
|
IAccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
|
2017-01-24 16:07:52 +03:00
|
|
|
]
|
|
|
|
);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->config
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getUserValue')
|
2017-04-24 10:43:44 +03:00
|
|
|
->with('UID', 'core', 'enabled', 'true')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('true');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->api
|
|
|
|
->expects($this->once())
|
|
|
|
->method('fillStorageInfo')
|
2017-04-24 10:43:44 +03:00
|
|
|
->with('UID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['DummyValue']);
|
2018-11-07 18:35:51 +03:00
|
|
|
|
|
|
|
$backend = $this->createMock(UserInterface::class);
|
|
|
|
$backend->expects($this->any())
|
|
|
|
->method('implementsActions')
|
|
|
|
->willReturn(true);
|
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getDisplayName')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('Demo User');
|
2017-01-24 17:45:55 +03:00
|
|
|
$targetUser
|
2018-03-16 13:44:20 +03:00
|
|
|
->expects($this->once())
|
|
|
|
->method('getHome')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('/var/www/newtcloud/data/UID');
|
2018-03-16 13:44:20 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getLastLogin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(1521191471);
|
2018-03-16 13:44:20 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getBackendClassName')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('Database');
|
2018-11-07 18:35:51 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getBackend')
|
|
|
|
->willReturn($backend);
|
2018-06-27 20:09:09 +03:00
|
|
|
$targetUser
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2020-06-23 09:45:01 +03:00
|
|
|
$this->l10nFactory
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUserLanguage')
|
|
|
|
->with($targetUser)
|
|
|
|
->willReturn('de');
|
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$expected = [
|
2017-01-24 17:45:55 +03:00
|
|
|
'id' => 'UID',
|
2018-04-12 20:12:17 +03:00
|
|
|
'enabled' => true,
|
2018-03-16 13:44:20 +03:00
|
|
|
'storageLocation' => '/var/www/newtcloud/data/UID',
|
|
|
|
'lastLogin' => 1521191471000,
|
|
|
|
'backend' => 'Database',
|
2018-03-16 17:37:05 +03:00
|
|
|
'subadmin' => ['group3'],
|
2016-08-11 20:49:45 +03:00
|
|
|
'quota' => ['DummyValue'],
|
2018-03-16 13:44:20 +03:00
|
|
|
'email' => 'demo@nextcloud.com',
|
2016-08-11 20:49:45 +03:00
|
|
|
'displayname' => 'Demo User',
|
2017-01-24 16:07:52 +03:00
|
|
|
'phone' => 'phone',
|
|
|
|
'address' => 'address',
|
2017-04-05 15:51:55 +03:00
|
|
|
'website' => 'website',
|
2017-02-09 18:12:57 +03:00
|
|
|
'twitter' => 'twitter',
|
2017-06-21 12:22:05 +03:00
|
|
|
'groups' => ['group0', 'group1', 'group2'],
|
|
|
|
'language' => 'de',
|
2017-07-07 12:17:54 +03:00
|
|
|
'locale' => null,
|
2018-11-07 18:35:51 +03:00
|
|
|
'backendCapabilities' => [
|
|
|
|
'setDisplayName' => true,
|
|
|
|
'setPassword' => true,
|
|
|
|
]
|
2016-08-11 20:49:45 +03:00
|
|
|
];
|
2018-03-16 13:44:20 +03:00
|
|
|
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2017-01-26 13:31:08 +03:00
|
|
|
public function testGetUserDataAsSubAdminAndUserIsAccessible() {
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2017-02-28 12:40:49 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-12-01 14:05:40 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getEMailAddress')
|
2018-03-16 13:44:20 +03:00
|
|
|
->willReturn('demo@nextcloud.com');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
2018-03-16 13:44:20 +03:00
|
|
|
->expects($this->exactly(2))
|
2015-10-27 16:09:45 +03:00
|
|
|
->method('get')
|
2018-03-16 13:44:20 +03:00
|
|
|
->with('UID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('subadmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2017-02-09 18:12:57 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUserGroups')
|
|
|
|
->willReturn([]);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2018-03-16 13:44:20 +03:00
|
|
|
$subAdminManager
|
2015-10-27 16:09:45 +03:00
|
|
|
->expects($this->once())
|
2018-03-16 13:44:20 +03:00
|
|
|
->method('getSubAdminsGroups')
|
|
|
|
->willReturn([]);
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->exactly(2))
|
2015-10-27 16:09:45 +03:00
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->config
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('getUserValue')
|
2017-04-24 10:43:44 +03:00
|
|
|
->with('UID', 'core', 'enabled', 'true')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('true');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->api
|
|
|
|
->expects($this->once())
|
|
|
|
->method('fillStorageInfo')
|
2017-04-24 10:43:44 +03:00
|
|
|
->with('UID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['DummyValue']);
|
2018-11-07 18:35:51 +03:00
|
|
|
|
|
|
|
$backend = $this->createMock(UserInterface::class);
|
|
|
|
$backend->expects($this->any())
|
|
|
|
->method('implementsActions')
|
|
|
|
->willReturn(true);
|
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getDisplayName')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('Demo User');
|
2017-01-24 17:45:55 +03:00
|
|
|
$targetUser
|
2018-03-16 13:44:20 +03:00
|
|
|
->expects($this->once())
|
|
|
|
->method('getHome')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('/var/www/newtcloud/data/UID');
|
2018-03-16 13:44:20 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getLastLogin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(1521191471);
|
2018-03-16 13:44:20 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getBackendClassName')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('Database');
|
2018-11-07 18:35:51 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getBackend')
|
|
|
|
->willReturn($backend);
|
2018-03-16 13:44:20 +03:00
|
|
|
$targetUser
|
2017-01-24 17:45:55 +03:00
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2017-01-24 16:07:52 +03:00
|
|
|
$this->accountManager->expects($this->any())->method('getUser')
|
|
|
|
->with($targetUser)
|
|
|
|
->willReturn(
|
|
|
|
[
|
2020-12-01 16:33:22 +03:00
|
|
|
IAccountManager::PROPERTY_ADDRESS => ['value' => 'address'],
|
|
|
|
IAccountManager::PROPERTY_PHONE => ['value' => 'phone'],
|
|
|
|
IAccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
|
|
|
|
IAccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
|
2017-01-24 16:07:52 +03:00
|
|
|
]
|
|
|
|
);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2020-06-23 09:45:01 +03:00
|
|
|
$this->l10nFactory
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUserLanguage')
|
|
|
|
->with($targetUser)
|
|
|
|
->willReturn('da');
|
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$expected = [
|
2017-01-24 17:45:55 +03:00
|
|
|
'id' => 'UID',
|
2018-04-12 20:12:17 +03:00
|
|
|
'enabled' => true,
|
2018-03-16 13:44:20 +03:00
|
|
|
'storageLocation' => '/var/www/newtcloud/data/UID',
|
|
|
|
'lastLogin' => 1521191471000,
|
|
|
|
'backend' => 'Database',
|
2018-03-16 17:37:05 +03:00
|
|
|
'subadmin' => [],
|
2016-08-11 20:49:45 +03:00
|
|
|
'quota' => ['DummyValue'],
|
2018-03-16 13:44:20 +03:00
|
|
|
'email' => 'demo@nextcloud.com',
|
2016-08-11 20:49:45 +03:00
|
|
|
'displayname' => 'Demo User',
|
2017-01-24 16:07:52 +03:00
|
|
|
'phone' => 'phone',
|
|
|
|
'address' => 'address',
|
2017-04-05 15:51:55 +03:00
|
|
|
'website' => 'website',
|
2017-02-09 18:12:57 +03:00
|
|
|
'twitter' => 'twitter',
|
2017-06-21 12:22:05 +03:00
|
|
|
'groups' => [],
|
|
|
|
'language' => 'da',
|
2017-07-07 12:17:54 +03:00
|
|
|
'locale' => null,
|
2018-11-07 18:35:51 +03:00
|
|
|
'backendCapabilities' => [
|
|
|
|
'setDisplayName' => true,
|
|
|
|
'setPassword' => true,
|
|
|
|
]
|
2016-08-11 20:49:45 +03:00
|
|
|
];
|
2018-03-16 13:44:20 +03:00
|
|
|
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2017-01-26 13:31:08 +03:00
|
|
|
public function testGetUserDataAsSubAdminAndUserIsNotAccessible() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(997);
|
|
|
|
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2017-02-28 12:40:49 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToGet')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('subadmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-08-11 12:08:57 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2018-03-16 13:44:20 +03:00
|
|
|
$this->invokePrivate($this->api, 'getUser', ['UserToGet']);
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
2015-08-11 12:08:57 +03:00
|
|
|
|
2017-01-26 13:31:08 +03:00
|
|
|
public function testGetUserDataAsSubAdminSelfLookup() {
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2017-02-28 12:40:49 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
2018-03-16 13:44:20 +03:00
|
|
|
->expects($this->exactly(2))
|
2015-10-27 16:09:45 +03:00
|
|
|
->method('get')
|
2018-03-16 13:44:20 +03:00
|
|
|
->with('UID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
2017-04-24 10:43:44 +03:00
|
|
|
->with('UID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-08-11 12:08:57 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2018-03-16 13:44:20 +03:00
|
|
|
$subAdminManager
|
2015-10-27 16:09:45 +03:00
|
|
|
->expects($this->once())
|
2018-03-16 13:44:20 +03:00
|
|
|
->method('getSubAdminsGroups')
|
|
|
|
->willReturn([]);
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->exactly(2))
|
2015-10-27 16:09:45 +03:00
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2017-02-09 18:12:57 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUserGroups')
|
|
|
|
->willReturn([]);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->api
|
|
|
|
->expects($this->once())
|
|
|
|
->method('fillStorageInfo')
|
2017-04-24 10:43:44 +03:00
|
|
|
->with('UID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['DummyValue']);
|
2018-11-07 18:35:51 +03:00
|
|
|
|
|
|
|
$backend = $this->createMock(UserInterface::class);
|
|
|
|
$backend->expects($this->atLeastOnce())
|
|
|
|
->method('implementsActions')
|
|
|
|
->willReturn(false);
|
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getDisplayName')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('Subadmin User');
|
2015-12-01 14:05:40 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getEMailAddress')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin@nextcloud.com');
|
2017-01-24 17:45:55 +03:00
|
|
|
$targetUser
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2018-03-16 13:44:20 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getHome')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('/var/www/newtcloud/data/UID');
|
2018-03-16 13:44:20 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getLastLogin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(1521191471);
|
2018-03-16 13:44:20 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getBackendClassName')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('Database');
|
2018-11-07 18:35:51 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getBackend')
|
|
|
|
->willReturn($backend);
|
2017-01-24 16:07:52 +03:00
|
|
|
$this->accountManager->expects($this->any())->method('getUser')
|
|
|
|
->with($targetUser)
|
|
|
|
->willReturn(
|
|
|
|
[
|
2020-12-01 16:33:22 +03:00
|
|
|
IAccountManager::PROPERTY_ADDRESS => ['value' => 'address'],
|
|
|
|
IAccountManager::PROPERTY_PHONE => ['value' => 'phone'],
|
|
|
|
IAccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
|
|
|
|
IAccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
|
2017-01-24 16:07:52 +03:00
|
|
|
]
|
|
|
|
);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2020-06-23 09:45:01 +03:00
|
|
|
$this->l10nFactory
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUserLanguage')
|
|
|
|
->with($targetUser)
|
|
|
|
->willReturn('ru');
|
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$expected = [
|
2017-01-24 17:45:55 +03:00
|
|
|
'id' => 'UID',
|
2018-03-16 13:44:20 +03:00
|
|
|
'storageLocation' => '/var/www/newtcloud/data/UID',
|
|
|
|
'lastLogin' => 1521191471000,
|
|
|
|
'backend' => 'Database',
|
2018-03-16 17:37:05 +03:00
|
|
|
'subadmin' => [],
|
2015-10-27 16:09:45 +03:00
|
|
|
'quota' => ['DummyValue'],
|
2018-03-16 13:44:20 +03:00
|
|
|
'email' => 'subadmin@nextcloud.com',
|
2015-10-27 16:09:45 +03:00
|
|
|
'displayname' => 'Subadmin User',
|
2017-01-24 16:07:52 +03:00
|
|
|
'phone' => 'phone',
|
|
|
|
'address' => 'address',
|
2017-04-05 15:51:55 +03:00
|
|
|
'website' => 'website',
|
2017-02-09 18:12:57 +03:00
|
|
|
'twitter' => 'twitter',
|
2017-06-21 12:22:05 +03:00
|
|
|
'groups' => [],
|
|
|
|
'language' => 'ru',
|
2017-07-07 12:17:54 +03:00
|
|
|
'locale' => null,
|
2018-11-07 18:35:51 +03:00
|
|
|
'backendCapabilities' => [
|
|
|
|
'setDisplayName' => false,
|
|
|
|
'setPassword' => false,
|
|
|
|
]
|
2016-08-11 20:49:45 +03:00
|
|
|
];
|
2018-03-16 13:44:20 +03:00
|
|
|
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-12-03 22:44:29 +03:00
|
|
|
public function dataSearchByPhoneNumbers(): array {
|
|
|
|
return [
|
|
|
|
'Invalid country' => ['Not a country code', ['12345' => ['NaN']], 400, null, null, []],
|
|
|
|
'No number to search' => ['DE', ['12345' => ['NaN']], 200, null, null, []],
|
|
|
|
'Valid number but no match' => ['DE', ['12345' => ['0711 / 25 24 28-90']], 200, ['+4971125242890'], [], []],
|
|
|
|
'Invalid number' => ['FR', ['12345' => ['0711 / 25 24 28-90']], 200, null, null, []],
|
|
|
|
'Invalid and valid number' => ['DE', ['12345' => ['NaN', '0711 / 25 24 28-90']], 200, ['+4971125242890'], [], []],
|
|
|
|
'Valid and invalid number' => ['DE', ['12345' => ['0711 / 25 24 28-90', 'NaN']], 200, ['+4971125242890'], [], []],
|
|
|
|
'Valid number and a match' => ['DE', ['12345' => ['0711 / 25 24 28-90']], 200, ['+4971125242890'], ['+4971125242890' => 'admin'], ['12345' => 'admin@localhost']],
|
|
|
|
'Same number twice, later hits' => ['DE', ['12345' => ['0711 / 25 24 28-90'], '23456' => ['0711 / 25 24 28-90']], 200, ['+4971125242890'], ['+4971125242890' => 'admin'], ['23456' => 'admin@localhost']],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataSearchByPhoneNumbers
|
|
|
|
* @param string $location
|
|
|
|
* @param array $search
|
|
|
|
* @param int $status
|
|
|
|
* @param array $expected
|
|
|
|
*/
|
|
|
|
public function testSearchByPhoneNumbers(string $location, array $search, int $status, ?array $searchUsers, ?array $userMatches, array $expected) {
|
|
|
|
if ($searchUsers === null) {
|
|
|
|
$this->accountManager->expects($this->never())
|
|
|
|
->method('searchUsers');
|
|
|
|
} else {
|
|
|
|
$this->accountManager->expects($this->once())
|
|
|
|
->method('searchUsers')
|
|
|
|
->with(IAccountManager::PROPERTY_PHONE, $searchUsers)
|
|
|
|
->willReturn($userMatches);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->urlGenerator->method('getAbsoluteURL')
|
|
|
|
->with('/')
|
|
|
|
->willReturn('https://localhost/');
|
|
|
|
|
|
|
|
$response = $this->api->searchByPhoneNumbers($location, $search);
|
|
|
|
|
|
|
|
self::assertEquals($status, $response->getStatus());
|
|
|
|
self::assertEquals($expected, $response->getData());
|
|
|
|
}
|
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testEditUserRegularUserSelfEditChangeDisplayName() {
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2017-02-28 12:40:49 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('setDisplayName')
|
|
|
|
->with('NewDisplayName');
|
2017-04-24 10:43:44 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals([], $this->api->editUser('UserToEdit', 'display', 'NewDisplayName')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testEditUserRegularUserSelfEditChangeEmailValid() {
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2017-02-28 12:40:49 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2016-01-18 22:27:43 +03:00
|
|
|
$targetUser
|
2015-10-27 16:09:45 +03:00
|
|
|
->expects($this->once())
|
2016-01-18 22:27:43 +03:00
|
|
|
->method('setEMailAddress')
|
2018-03-16 13:44:20 +03:00
|
|
|
->with('demo@nextcloud.com');
|
2017-04-24 10:43:44 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2018-03-16 13:44:20 +03:00
|
|
|
$this->assertEquals([], $this->api->editUser('UserToEdit', 'email', 'demo@nextcloud.com')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testEditUserRegularUserSelfEditChangeEmailInvalid() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(102);
|
|
|
|
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2017-02-28 12:40:49 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2017-04-24 10:43:44 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->editUser('UserToEdit', 'email', 'demo.org');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testEditUserRegularUserSelfEditChangePassword() {
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2017-02-28 12:40:49 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2019-03-01 12:11:37 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('canChangePassword')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('setPassword')
|
|
|
|
->with('NewPassword');
|
2017-04-24 10:43:44 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals([], $this->api->editUser('UserToEdit', 'password', 'NewPassword')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testEditUserRegularUserSelfEditChangeQuota() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(997);
|
|
|
|
|
2017-02-28 12:40:49 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2017-02-28 12:40:49 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)
|
2016-07-12 09:38:56 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2017-04-24 10:43:44 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->editUser('UserToEdit', 'quota', 'NewQuota');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testEditUserAdminUserSelfEditChangeValidQuota() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-02-09 20:11:30 +03:00
|
|
|
$targetUser->expects($this->once())
|
|
|
|
->method('setQuota')
|
|
|
|
->with('2.9 MB');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
2018-06-27 20:09:09 +03:00
|
|
|
->expects($this->exactly(3))
|
2015-10-27 16:09:45 +03:00
|
|
|
->method('isAdmin')
|
2017-04-24 10:43:44 +03:00
|
|
|
->with('UID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-04-24 10:43:44 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals([], $this->api->editUser('UserToEdit', 'quota', '3042824')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testEditUserAdminUserSelfEditChangeInvalidQuota() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('Invalid quota value ABC');
|
|
|
|
$this->expectExceptionCode(103);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
2015-08-11 12:08:57 +03:00
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
2018-06-27 20:09:09 +03:00
|
|
|
->expects($this->exactly(3))
|
2015-10-27 16:09:45 +03:00
|
|
|
->method('isAdmin')
|
2017-04-24 10:43:44 +03:00
|
|
|
->with('UID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-04-24 10:43:44 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->editUser('UserToEdit', 'quota', 'ABC');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
2015-08-11 12:08:57 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testEditUserAdminUserEditChangeValidQuota() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('admin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-02-09 20:11:30 +03:00
|
|
|
$targetUser->expects($this->once())
|
|
|
|
->method('setQuota')
|
|
|
|
->with('2.9 MB');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('admin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-08-11 12:08:57 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2017-04-24 10:43:44 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals([], $this->api->editUser('UserToEdit', 'quota', '3042824')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
2015-08-11 12:08:57 +03:00
|
|
|
|
2017-06-21 13:21:21 +03:00
|
|
|
public function testEditUserSelfEditChangeLanguage() {
|
|
|
|
$this->l10nFactory->expects($this->once())
|
|
|
|
->method('findAvailableLanguages')
|
|
|
|
->willReturn(['en', 'de', 'sv']);
|
|
|
|
$this->config->expects($this->any())
|
|
|
|
->method('getSystemValue')
|
|
|
|
->willReturnMap([
|
|
|
|
['allow_user_to_change_display_name', true, true],
|
|
|
|
['force_language', false, false],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$loggedInUser = $this->createMock(IUser::class);
|
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UserToEdit');
|
2017-06-21 13:21:21 +03:00
|
|
|
$targetUser = $this->createMock(IUser::class);
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('setUserValue')
|
|
|
|
->with('UserToEdit', 'core', 'lang', 'de');
|
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2017-06-21 13:21:21 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2017-06-21 13:21:21 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->atLeastOnce())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2017-06-21 13:21:21 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UserToEdit');
|
2017-06-21 13:21:21 +03:00
|
|
|
|
|
|
|
$this->assertEquals([], $this->api->editUser('UserToEdit', 'language', 'de')->getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataEditUserSelfEditChangeLanguageButForced() {
|
|
|
|
return [
|
|
|
|
['de'],
|
|
|
|
[true],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataEditUserSelfEditChangeLanguageButForced
|
|
|
|
*/
|
|
|
|
public function testEditUserSelfEditChangeLanguageButForced($forced) {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
|
2017-06-21 13:21:21 +03:00
|
|
|
$this->config->expects($this->any())
|
|
|
|
->method('getSystemValue')
|
|
|
|
->willReturnMap([
|
|
|
|
['allow_user_to_change_display_name', true, true],
|
|
|
|
['force_language', false, $forced],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$loggedInUser = $this->createMock(IUser::class);
|
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UserToEdit');
|
2017-06-21 13:21:21 +03:00
|
|
|
$targetUser = $this->createMock(IUser::class);
|
|
|
|
$this->config->expects($this->never())
|
|
|
|
->method('setUserValue');
|
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2017-06-21 13:21:21 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2017-06-21 13:21:21 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->atLeastOnce())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2017-06-21 13:21:21 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UserToEdit');
|
2017-06-21 13:21:21 +03:00
|
|
|
|
|
|
|
$this->assertEquals([], $this->api->editUser('UserToEdit', 'language', 'de')->getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testEditUserAdminEditChangeLanguage() {
|
|
|
|
$this->l10nFactory->expects($this->once())
|
|
|
|
->method('findAvailableLanguages')
|
|
|
|
->willReturn(['en', 'de', 'sv']);
|
|
|
|
|
|
|
|
$loggedInUser = $this->createMock(IUser::class);
|
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('admin');
|
2017-06-21 13:21:21 +03:00
|
|
|
$targetUser = $this->createMock(IUser::class);
|
|
|
|
$this->config->expects($this->once())
|
|
|
|
->method('setUserValue')
|
|
|
|
->with('UserToEdit', 'core', 'lang', 'de');
|
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2017-06-21 13:21:21 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2017-06-21 13:21:21 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('admin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-06-21 13:21:21 +03:00
|
|
|
$subAdminManager = $this->createMock(SubAdmin::class);
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2017-06-21 13:21:21 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UserToEdit');
|
2017-06-21 13:21:21 +03:00
|
|
|
|
|
|
|
$this->assertEquals([], $this->api->editUser('UserToEdit', 'language', 'de')->getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataEditUserSelfEditChangeLanguageButForced
|
|
|
|
*/
|
|
|
|
public function testEditUserAdminEditChangeLanguageInvalidLanguage() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
|
2017-06-21 13:21:21 +03:00
|
|
|
|
|
|
|
$this->l10nFactory->expects($this->once())
|
|
|
|
->method('findAvailableLanguages')
|
|
|
|
->willReturn(['en', 'de', 'sv']);
|
|
|
|
|
|
|
|
$loggedInUser = $this->createMock(IUser::class);
|
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('admin');
|
2017-06-21 13:21:21 +03:00
|
|
|
$targetUser = $this->createMock(IUser::class);
|
|
|
|
$this->config->expects($this->never())
|
|
|
|
->method('setUserValue');
|
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2017-06-21 13:21:21 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2017-06-21 13:21:21 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('admin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-06-21 13:21:21 +03:00
|
|
|
$subAdminManager = $this->createMock(SubAdmin::class);
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2017-06-21 13:21:21 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UserToEdit');
|
2017-06-21 13:21:21 +03:00
|
|
|
|
|
|
|
$this->assertEquals([], $this->api->editUser('UserToEdit', 'language', 'ru')->getData());
|
|
|
|
}
|
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testEditUserSubadminUserAccessible() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-02-09 20:11:30 +03:00
|
|
|
$targetUser->expects($this->once())
|
|
|
|
->method('setQuota')
|
|
|
|
->with('2.9 MB');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-08-11 12:08:57 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2017-04-24 10:43:44 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals([], $this->api->editUser('UserToEdit', 'quota', '3042824')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testEditUserSubadminUserInaccessible() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(997);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
2015-08-11 12:08:57 +03:00
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToEdit')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-08-11 12:08:57 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2017-04-24 10:43:44 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->editUser('UserToEdit', 'quota', 'value');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testDeleteUserNotExistingUser() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UserToEdit');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToDelete')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->deleteUser('UserToDelete');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testDeleteUserSelf() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToDelete')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->deleteUser('UserToDelete');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteSuccessfulUserAsAdmin() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('admin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToDelete')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
2015-08-11 12:08:57 +03:00
|
|
|
->method('isAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->with('admin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('delete')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-08-11 12:08:57 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals([], $this->api->deleteUser('UserToDelete')->getData());
|
2015-08-11 12:08:57 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testDeleteUnsuccessfulUserAsAdmin() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('admin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToDelete')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('admin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('delete')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2015-08-11 12:08:57 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->deleteUser('UserToDelete');
|
2015-08-11 12:08:57 +03:00
|
|
|
}
|
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testDeleteSuccessfulUserAsSubadmin() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToDelete')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('subadmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('delete')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals([], $this->api->deleteUser('UserToDelete')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
2015-08-11 12:08:57 +03:00
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testDeleteUnsuccessfulUserAsSubadmin() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToDelete')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('subadmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('delete')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->deleteUser('UserToDelete');
|
2015-08-11 12:08:57 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testDeleteUserAsSubAdminAndUserIsNotAccessible() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(997);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UID');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToDelete')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('subadmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->deleteUser('UserToDelete');
|
2015-08-11 12:08:57 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testGetUsersGroupsTargetUserNotExisting() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(998);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-08-11 12:08:57 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->getUsersGroups('UserToLookup');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
2015-08-11 12:08:57 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testGetUsersGroupsSelfTargetted() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UserToLookup');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UserToLookup');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToLookup')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['DummyValue']);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals(['groups' => ['DummyValue']], $this->api->getUsersGroups('UserToLookup')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
2015-04-13 11:32:18 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testGetUsersGroupsForAdminUser() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('admin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UserToLookup');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToLookup')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['DummyValue']);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('admin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals(['groups' => ['DummyValue']], $this->api->getUsersGroups('UserToLookup')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetUsersGroupsForSubAdminUserAndUserIsAccessible() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UserToLookup');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToLookup')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('subadmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2016-07-12 09:38:56 +03:00
|
|
|
$group1 = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$group1
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getGID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('Group1');
|
2016-07-12 09:38:56 +03:00
|
|
|
$group2 = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$group2
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getGID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('Group2');
|
2015-10-27 16:09:45 +03:00
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdminsGroups')
|
|
|
|
->with($loggedInUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([$group1, $group2]);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['Group1']);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals(['groups' => ['Group1']], $this->api->getUsersGroups('UserToLookup')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testGetUsersGroupsForSubAdminUserAndUserIsInaccessible() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(997);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('UserToLookup');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToLookup')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('subadmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['Group1']);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->getUsersGroups('UserToLookup');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testAddToGroupWithTargetGroupNotExisting() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(102);
|
|
|
|
|
2017-01-18 16:34:38 +03:00
|
|
|
$this->groupManager->expects($this->once())
|
2015-10-27 16:09:45 +03:00
|
|
|
->method('get')
|
|
|
|
->with('GroupToAddTo')
|
2017-01-18 16:34:38 +03:00
|
|
|
->willReturn(null);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->addToGroup('TargetUser', 'GroupToAddTo');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testAddToGroupWithNoGroupSpecified() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->addToGroup('TargetUser');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testAddToGroupWithTargetUserNotExisting() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(103);
|
|
|
|
|
2017-01-18 16:34:38 +03:00
|
|
|
$targetGroup = $this->createMock(IGroup::class);
|
|
|
|
$this->groupManager->expects($this->once())
|
2015-10-27 16:09:45 +03:00
|
|
|
->method('get')
|
|
|
|
->with('GroupToAddTo')
|
2017-01-18 16:34:38 +03:00
|
|
|
->willReturn($targetGroup);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->addToGroup('TargetUser', 'GroupToAddTo');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2017-01-18 16:34:38 +03:00
|
|
|
public function testAddToGroupNoSubadmin() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(104);
|
|
|
|
|
2017-01-18 16:34:38 +03:00
|
|
|
$targetUser = $this->createMock(IUser::class);
|
|
|
|
$loggedInUser = $this->createMock(IUser::class);
|
|
|
|
$loggedInUser->expects($this->once())
|
|
|
|
->method('getUID')
|
|
|
|
->willReturn('subadmin');
|
|
|
|
|
|
|
|
$targetGroup = $this->createMock(IGroup::class);
|
|
|
|
$targetGroup->expects($this->never())
|
|
|
|
->method('addUser')
|
|
|
|
->with($targetUser);
|
|
|
|
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('GroupToAddTo')
|
|
|
|
->willReturn($targetGroup);
|
|
|
|
|
|
|
|
|
2017-02-28 12:40:49 +03:00
|
|
|
$subAdminManager = $this->createMock(SubAdmin::class);
|
2017-01-18 16:34:38 +03:00
|
|
|
$subAdminManager->expects($this->once())
|
|
|
|
->method('isSubAdminOfGroup')
|
|
|
|
->with($loggedInUser, $targetGroup)
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
|
|
|
->willReturn($subAdminManager);
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('subadmin')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
$this->userManager->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('TargetUser')
|
|
|
|
->willReturn($targetUser);
|
|
|
|
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
|
|
|
->willReturn($loggedInUser);
|
|
|
|
|
|
|
|
$this->api->addToGroup('TargetUser', 'GroupToAddTo');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddToGroupSuccessAsSubadmin() {
|
|
|
|
$targetUser = $this->createMock(IUser::class);
|
|
|
|
$loggedInUser = $this->createMock(IUser::class);
|
|
|
|
$loggedInUser->expects($this->once())
|
|
|
|
->method('getUID')
|
|
|
|
->willReturn('subadmin');
|
|
|
|
|
|
|
|
$targetGroup = $this->createMock(IGroup::class);
|
|
|
|
$targetGroup->expects($this->once())
|
|
|
|
->method('addUser')
|
|
|
|
->with($targetUser);
|
|
|
|
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('GroupToAddTo')
|
|
|
|
->willReturn($targetGroup);
|
|
|
|
|
|
|
|
|
2017-02-28 12:40:49 +03:00
|
|
|
$subAdminManager = $this->createMock(SubAdmin::class);
|
2017-01-18 16:34:38 +03:00
|
|
|
$subAdminManager->expects($this->once())
|
|
|
|
->method('isSubAdminOfGroup')
|
|
|
|
->with($loggedInUser, $targetGroup)
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
|
|
|
->willReturn($subAdminManager);
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('subadmin')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
$this->userManager->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('TargetUser')
|
|
|
|
->willReturn($targetUser);
|
|
|
|
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
|
|
|
->willReturn($loggedInUser);
|
|
|
|
|
|
|
|
$this->assertEquals(new DataResponse(), $this->api->addToGroup('TargetUser', 'GroupToAddTo'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddToGroupSuccessAsAdmin() {
|
|
|
|
$targetUser = $this->createMock(IUser::class);
|
|
|
|
$loggedInUser = $this->createMock(IUser::class);
|
|
|
|
$loggedInUser->expects($this->once())
|
|
|
|
->method('getUID')
|
|
|
|
->willReturn('admin');
|
|
|
|
|
|
|
|
$targetGroup = $this->createMock(IGroup::class);
|
|
|
|
$targetGroup->expects($this->once())
|
|
|
|
->method('addUser')
|
|
|
|
->with($targetUser);
|
|
|
|
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('GroupToAddTo')
|
|
|
|
->willReturn($targetGroup);
|
|
|
|
|
|
|
|
|
2017-02-28 12:40:49 +03:00
|
|
|
$subAdminManager = $this->createMock(SubAdmin::class);
|
2017-01-18 16:34:38 +03:00
|
|
|
$subAdminManager->expects($this->never())
|
|
|
|
->method('isSubAdminOfGroup');
|
|
|
|
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
|
|
|
->willReturn($subAdminManager);
|
|
|
|
$this->groupManager->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('admin')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$this->userManager->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('TargetUser')
|
|
|
|
->willReturn($targetUser);
|
|
|
|
|
|
|
|
$this->userSession->expects($this->once())
|
|
|
|
->method('getUser')
|
|
|
|
->willReturn($loggedInUser);
|
|
|
|
|
|
|
|
$this->assertEquals(new DataResponse(), $this->api->addToGroup('TargetUser', 'GroupToAddTo'));
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-11-05 19:01:47 +03:00
|
|
|
public function testRemoveFromGroupWithNoTargetGroup() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-11-05 19:01:47 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2016-08-11 20:49:45 +03:00
|
|
|
|
2018-02-28 00:03:40 +03:00
|
|
|
$this->api->removeFromGroup('TargetUser', '');
|
2015-11-05 19:01:47 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2017-09-18 11:56:13 +03:00
|
|
|
public function testRemoveFromGroupWithEmptyTargetGroup() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2017-09-18 11:56:13 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2017-09-18 11:56:13 +03:00
|
|
|
|
|
|
|
$this->api->removeFromGroup('TargetUser', '');
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testRemoveFromGroupWithNotExistingTargetGroup() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(102);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('TargetGroup')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->removeFromGroup('TargetUser', 'TargetGroup');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testRemoveFromGroupWithNotExistingTargetUser() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(103);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-07-12 09:38:56 +03:00
|
|
|
$targetGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('TargetGroup')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetGroup);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('TargetUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->removeFromGroup('TargetUser', 'TargetGroup');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testRemoveFromGroupWithoutPermission() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(104);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('unauthorizedUser');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-07-12 09:38:56 +03:00
|
|
|
$targetGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('TargetGroup')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetGroup);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('TargetUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('unauthorizedUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->removeFromGroup('TargetUser', 'TargetGroup');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testRemoveFromGroupAsAdminFromAdmin() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('Cannot remove yourself from the admin group');
|
|
|
|
$this->expectExceptionCode(105);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('admin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2017-04-24 10:43:44 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('admin');
|
2016-07-12 09:38:56 +03:00
|
|
|
$targetGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetGroup
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getGID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('admin');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('admin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetGroup);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
2017-04-24 10:43:44 +03:00
|
|
|
->with('Admin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->any())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('admin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2017-04-24 10:43:44 +03:00
|
|
|
$this->api->removeFromGroup('Admin', 'admin');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testRemoveFromGroupAsSubAdminFromSubAdmin() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('Cannot remove yourself from this group as you are a SubAdmin');
|
|
|
|
$this->expectExceptionCode(105);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2017-04-24 10:43:44 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2016-07-12 09:38:56 +03:00
|
|
|
$targetGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetGroup
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getGID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('subadmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetGroup);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
2017-04-24 10:43:44 +03:00
|
|
|
->with('SubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
2018-03-20 21:06:08 +03:00
|
|
|
->method('isSubAdminOfGroup')
|
2015-10-27 16:09:45 +03:00
|
|
|
->with($loggedInUser, $targetGroup)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->any())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('subadmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2017-04-24 10:43:44 +03:00
|
|
|
$this->api->removeFromGroup('SubAdmin', 'subadmin');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2017-01-18 13:56:24 +03:00
|
|
|
public function testRemoveFromGroupAsSubAdminFromLastSubAdminGroup() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('Not viable to remove user from the last group you are SubAdmin of');
|
|
|
|
$this->expectExceptionCode(105);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2017-01-18 13:56:24 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2017-01-18 13:56:24 +03:00
|
|
|
$targetGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
|
|
|
$targetGroup
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getGID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2017-01-18 13:56:24 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2017-01-18 13:56:24 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('subadmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetGroup);
|
2017-01-18 13:56:24 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('AnotherUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2017-01-18 13:56:24 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
2018-03-20 21:06:08 +03:00
|
|
|
->method('isSubAdminOfGroup')
|
2017-01-18 13:56:24 +03:00
|
|
|
->with($loggedInUser, $targetGroup)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-01-18 13:56:24 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2017-01-18 13:56:24 +03:00
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdminsGroups')
|
|
|
|
->with($loggedInUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([$targetGroup]);
|
2017-01-18 13:56:24 +03:00
|
|
|
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->any())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('subadmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2017-01-18 13:56:24 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUserGroupIds')
|
|
|
|
->with($targetUser)
|
|
|
|
->willReturn(['subadmin', 'other group']);
|
|
|
|
|
|
|
|
$this->api->removeFromGroup('AnotherUser', 'subadmin');
|
|
|
|
}
|
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testRemoveFromGroupSuccessful() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('admin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-07-12 09:38:56 +03:00
|
|
|
$targetGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('admin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetGroup);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('AnotherUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->any())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('admin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetGroup
|
|
|
|
->expects($this->once())
|
|
|
|
->method('removeUser')
|
|
|
|
->with($targetUser);
|
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals([], $this->api->removeFromGroup('AnotherUser', 'admin')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testAddSubAdminWithNotExistingTargetUser() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('User does not exist');
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('NotExistingUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2018-02-28 00:03:40 +03:00
|
|
|
$this->api->addSubAdmin('NotExistingUser', '');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testAddSubAdminWithNotExistingTargetGroup() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('Group does not exist');
|
|
|
|
$this->expectExceptionCode(102);
|
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('ExistingUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('NotExistingGroup')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->addSubAdmin('ExistingUser', 'NotExistingGroup');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testAddSubAdminToAdminGroup() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('Cannot create subadmins for admin group');
|
|
|
|
$this->expectExceptionCode(103);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-07-12 09:38:56 +03:00
|
|
|
$targetGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
2017-04-24 11:15:03 +03:00
|
|
|
$targetGroup
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getGID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('admin');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('ExistingUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('ADmiN')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetGroup);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->addSubAdmin('ExistingUser', 'ADmiN');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddSubAdminTwice() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-07-12 09:38:56 +03:00
|
|
|
$targetGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('ExistingUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('TargetGroup')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetGroup);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isSubAdminOfGroup')
|
|
|
|
->with($targetUser, $targetGroup)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals([], $this->api->addSubAdmin('ExistingUser', 'TargetGroup')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddSubAdminSuccessful() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-07-12 09:38:56 +03:00
|
|
|
$targetGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('ExistingUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('TargetGroup')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetGroup);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isSubAdminOfGroup')
|
|
|
|
->with($targetUser, $targetGroup)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2015-10-27 16:09:45 +03:00
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('createSubAdmin')
|
2020-06-23 09:45:01 +03:00
|
|
|
->with($targetUser, $targetGroup);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals([], $this->api->addSubAdmin('ExistingUser', 'TargetGroup')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testRemoveSubAdminNotExistingTargetUser() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('User does not exist');
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('NotExistingUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->removeSubAdmin('NotExistingUser', 'GroupToDeleteFrom');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testRemoveSubAdminNotExistingTargetGroup() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('Group does not exist');
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('ExistingUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('GroupToDeleteFrom')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->removeSubAdmin('ExistingUser', 'GroupToDeleteFrom');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testRemoveSubAdminFromNotASubadmin() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('User is not a subadmin of this group');
|
|
|
|
$this->expectExceptionCode(102);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-07-12 09:38:56 +03:00
|
|
|
$targetGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('ExistingUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('GroupToDeleteFrom')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetGroup);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isSubAdminOfGroup')
|
|
|
|
->with($targetUser, $targetGroup)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->removeSubAdmin('ExistingUser', 'GroupToDeleteFrom');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRemoveSubAdminSuccessful() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-07-12 09:38:56 +03:00
|
|
|
$targetGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('ExistingUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('GroupToDeleteFrom')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetGroup);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isSubAdminOfGroup')
|
|
|
|
->with($targetUser, $targetGroup)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2015-10-27 16:09:45 +03:00
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('deleteSubAdmin')
|
2020-06-23 09:45:01 +03:00
|
|
|
->with($targetUser, $targetGroup);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals([], $this->api->removeSubAdmin('ExistingUser', 'GroupToDeleteFrom')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
public function testGetUserSubAdminGroupsNotExistingTargetUser() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('User does not exist');
|
|
|
|
$this->expectExceptionCode(404);
|
|
|
|
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('RequestedUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->api->getUserSubAdminGroups('RequestedUser');
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetUserSubAdminGroupsWithGroups() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-07-12 09:38:56 +03:00
|
|
|
$targetGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
2015-10-27 16:09:45 +03:00
|
|
|
$targetGroup
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getGID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('TargetGroup');
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('RequestedUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2016-05-11 20:38:49 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
2015-10-27 16:09:45 +03:00
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdminsGroups')
|
|
|
|
->with($targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn([$targetGroup]);
|
2015-10-27 16:09:45 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2015-10-27 16:09:45 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals(['TargetGroup'], $this->api->getUserSubAdminGroups('RequestedUser')->getData());
|
2015-10-27 16:09:45 +03:00
|
|
|
}
|
|
|
|
|
2016-04-07 18:22:21 +03:00
|
|
|
public function testEnableUser() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-04-07 18:22:21 +03:00
|
|
|
$targetUser->expects($this->once())
|
|
|
|
->method('setEnabled')
|
|
|
|
->with(true);
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('RequestedUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-04-07 18:22:21 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('admin');
|
2016-04-07 18:22:21 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2016-04-07 18:22:21 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2016-04-07 18:22:21 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals([], $this->api->enableUser('RequestedUser')->getData());
|
2016-04-07 18:22:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDisableUser() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-04-07 18:22:21 +03:00
|
|
|
$targetUser->expects($this->once())
|
|
|
|
->method('setEnabled')
|
|
|
|
->with(false);
|
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('RequestedUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2016-04-07 18:22:21 +03:00
|
|
|
$loggedInUser
|
|
|
|
->expects($this->exactly(2))
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('admin');
|
2016-04-07 18:22:21 +03:00
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2016-04-07 18:22:21 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2016-04-07 18:22:21 +03:00
|
|
|
|
2016-08-11 20:49:45 +03:00
|
|
|
$this->assertEquals([], $this->api->disableUser('RequestedUser')->getData());
|
2016-04-07 18:22:21 +03:00
|
|
|
}
|
2017-01-24 17:45:55 +03:00
|
|
|
|
|
|
|
public function testGetCurrentUserLoggedIn() {
|
2017-02-28 12:40:49 +03:00
|
|
|
$user = $this->createMock(IUser::class);
|
2017-01-24 17:45:55 +03:00
|
|
|
$user->expects($this->once())->method('getUID')->willReturn('UID');
|
|
|
|
|
|
|
|
$this->userSession->expects($this->once())->method('getUser')
|
|
|
|
->willReturn($user);
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var UsersController | MockObject $api */
|
2020-12-02 16:11:47 +03:00
|
|
|
$api = $this->getMockBuilder(UsersController::class)
|
2017-01-24 17:45:55 +03:00
|
|
|
->setConstructorArgs([
|
|
|
|
'provisioning_api',
|
|
|
|
$this->request,
|
|
|
|
$this->userManager,
|
|
|
|
$this->config,
|
2017-06-02 11:09:42 +03:00
|
|
|
$this->appManager,
|
2017-01-24 17:45:55 +03:00
|
|
|
$this->groupManager,
|
|
|
|
$this->userSession,
|
|
|
|
$this->accountManager,
|
2020-12-02 16:11:47 +03:00
|
|
|
$this->urlGenerator,
|
2017-01-24 17:45:55 +03:00
|
|
|
$this->logger,
|
2017-04-07 15:51:05 +03:00
|
|
|
$this->l10nFactory,
|
2018-01-26 14:47:59 +03:00
|
|
|
$this->newUserMailHelper,
|
2020-07-13 17:23:59 +03:00
|
|
|
$this->federatedShareProviderFactory,
|
2019-07-09 10:05:30 +03:00
|
|
|
$this->secureRandom,
|
|
|
|
$this->remoteWipe,
|
2020-08-09 17:36:19 +03:00
|
|
|
$this->eventDispatcher,
|
2017-01-24 17:45:55 +03:00
|
|
|
])
|
2017-01-26 13:31:08 +03:00
|
|
|
->setMethods(['getUserData'])
|
2017-01-24 17:45:55 +03:00
|
|
|
->getMock();
|
|
|
|
|
2017-01-26 13:31:08 +03:00
|
|
|
$api->expects($this->once())->method('getUserData')->with('UID')
|
2017-01-24 17:45:55 +03:00
|
|
|
->willReturn(
|
|
|
|
[
|
|
|
|
'id' => 'UID',
|
|
|
|
'enabled' => 'true',
|
|
|
|
'quota' => ['DummyValue'],
|
2018-03-16 13:44:20 +03:00
|
|
|
'email' => 'demo@nextcloud.com',
|
2017-01-24 17:45:55 +03:00
|
|
|
'displayname' => 'Demo User',
|
|
|
|
'phone' => 'phone',
|
|
|
|
'address' => 'address',
|
2017-04-05 15:51:55 +03:00
|
|
|
'website' => 'website',
|
2017-01-24 17:45:55 +03:00
|
|
|
'twitter' => 'twitter'
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'id' => 'UID',
|
|
|
|
'enabled' => 'true',
|
|
|
|
'quota' => ['DummyValue'],
|
2018-03-16 13:44:20 +03:00
|
|
|
'email' => 'demo@nextcloud.com',
|
2017-01-24 17:45:55 +03:00
|
|
|
'phone' => 'phone',
|
|
|
|
'address' => 'address',
|
2017-04-05 15:51:55 +03:00
|
|
|
'website' => 'website',
|
2017-01-24 17:45:55 +03:00
|
|
|
'twitter' => 'twitter',
|
|
|
|
'display-name' => 'Demo User'
|
|
|
|
];
|
|
|
|
|
2017-01-26 13:31:08 +03:00
|
|
|
$this->assertSame($expected, $api->getCurrentUser()->getData());
|
2017-01-24 17:45:55 +03:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2017-01-24 17:45:55 +03:00
|
|
|
public function testGetCurrentUserNotLoggedIn() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
|
2017-01-24 17:45:55 +03:00
|
|
|
|
|
|
|
$this->userSession->expects($this->once())->method('getUser')
|
|
|
|
->willReturn(null);
|
|
|
|
|
|
|
|
$this->api->getCurrentUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-26 13:31:08 +03:00
|
|
|
public function testGetUser() {
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var UsersController | MockObject $api */
|
2020-12-02 16:11:47 +03:00
|
|
|
$api = $this->getMockBuilder(UsersController::class)
|
2017-01-26 13:31:08 +03:00
|
|
|
->setConstructorArgs([
|
|
|
|
'provisioning_api',
|
|
|
|
$this->request,
|
|
|
|
$this->userManager,
|
|
|
|
$this->config,
|
2017-06-02 11:09:42 +03:00
|
|
|
$this->appManager,
|
2017-01-26 13:31:08 +03:00
|
|
|
$this->groupManager,
|
|
|
|
$this->userSession,
|
|
|
|
$this->accountManager,
|
2020-12-02 16:11:47 +03:00
|
|
|
$this->urlGenerator,
|
2017-01-26 13:31:08 +03:00
|
|
|
$this->logger,
|
2017-04-07 15:51:05 +03:00
|
|
|
$this->l10nFactory,
|
2018-01-26 14:47:59 +03:00
|
|
|
$this->newUserMailHelper,
|
2020-07-13 17:23:59 +03:00
|
|
|
$this->federatedShareProviderFactory,
|
2019-07-09 10:05:30 +03:00
|
|
|
$this->secureRandom,
|
|
|
|
$this->remoteWipe,
|
2020-08-09 17:36:19 +03:00
|
|
|
$this->eventDispatcher,
|
2017-01-26 13:31:08 +03:00
|
|
|
])
|
|
|
|
->setMethods(['getUserData'])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'id' => 'UID',
|
|
|
|
'enabled' => 'true',
|
|
|
|
'quota' => ['DummyValue'],
|
2018-03-16 13:44:20 +03:00
|
|
|
'email' => 'demo@nextcloud.com',
|
2017-01-26 13:31:08 +03:00
|
|
|
'phone' => 'phone',
|
|
|
|
'address' => 'address',
|
2017-04-05 15:51:55 +03:00
|
|
|
'website' => 'website',
|
2017-01-26 13:31:08 +03:00
|
|
|
'twitter' => 'twitter',
|
|
|
|
'displayname' => 'Demo User'
|
|
|
|
];
|
|
|
|
|
|
|
|
$api->expects($this->once())->method('getUserData')
|
|
|
|
->with('uid')
|
|
|
|
->willReturn($expected);
|
|
|
|
|
|
|
|
$this->assertSame($expected, $api->getUser('uid')->getData());
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2017-02-24 09:01:13 +03:00
|
|
|
public function testResendWelcomeMessageWithNotExistingTargetUser() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(998);
|
|
|
|
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('NotExistingUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2017-02-24 09:01:13 +03:00
|
|
|
|
|
|
|
$this->api->resendWelcomeMessage('NotExistingUser');
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2017-02-24 09:01:13 +03:00
|
|
|
public function testResendWelcomeMessageAsSubAdminAndUserIsNotAccessible() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(997);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2017-02-24 09:01:13 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$loggedInUser
|
|
|
|
->expects($this->exactly(1))
|
|
|
|
->method('getUID')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('subadmin');
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)
|
2017-02-24 09:01:13 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToGet')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('subadmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2017-02-24 09:01:13 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2017-02-24 09:01:13 +03:00
|
|
|
|
|
|
|
$this->api->resendWelcomeMessage('UserToGet');
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2017-02-24 09:01:13 +03:00
|
|
|
public function testResendWelcomeMessageNoEmail() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('Email address not available');
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2017-02-24 09:01:13 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)
|
2017-02-24 09:01:13 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToGet')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2017-02-24 09:01:13 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2017-02-24 09:01:13 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getEmailAddress')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('');
|
2017-02-24 09:01:13 +03:00
|
|
|
|
|
|
|
$this->api->resendWelcomeMessage('UserToGet');
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2017-02-24 09:01:13 +03:00
|
|
|
public function testResendWelcomeMessageNullEmail() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('Email address not available');
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2017-02-24 09:01:13 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)
|
2017-02-24 09:01:13 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToGet')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2017-02-24 09:01:13 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2017-02-24 09:01:13 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getEmailAddress')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(null);
|
2017-02-24 09:01:13 +03:00
|
|
|
|
|
|
|
$this->api->resendWelcomeMessage('UserToGet');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testResendWelcomeMessageSuccess() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2017-02-24 09:01:13 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)
|
2017-02-24 09:01:13 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$targetUser
|
|
|
|
->method('getUID')
|
|
|
|
->willReturn('user-id');
|
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToGet')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2017-02-24 09:01:13 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2017-02-24 09:01:13 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getEmailAddress')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('abc@example.org');
|
2017-04-07 15:51:05 +03:00
|
|
|
$emailTemplate = $this->createMock(IEMailTemplate::class);
|
|
|
|
$this->newUserMailHelper
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('generateTemplate')
|
|
|
|
->willReturn($emailTemplate);
|
|
|
|
$this->newUserMailHelper
|
2018-09-24 23:54:57 +03:00
|
|
|
->expects($this->at(1))
|
2017-04-07 15:51:05 +03:00
|
|
|
->method('sendMail')
|
|
|
|
->with($targetUser, $emailTemplate);
|
2017-02-24 09:01:13 +03:00
|
|
|
|
|
|
|
$this->api->resendWelcomeMessage('UserToGet');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testResendWelcomeMessageSuccessWithFallbackLanguage() {
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2017-02-24 09:01:13 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)
|
2017-02-24 09:01:13 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$targetUser
|
|
|
|
->method('getUID')
|
|
|
|
->willReturn('user-id');
|
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToGet')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2017-02-24 09:01:13 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2017-02-24 09:01:13 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getEmailAddress')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('abc@example.org');
|
2017-02-24 09:01:13 +03:00
|
|
|
$l10n = $this->getMockBuilder(IL10N::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2017-04-07 15:51:05 +03:00
|
|
|
$emailTemplate = $this->createMock(IEMailTemplate::class);
|
|
|
|
$this->newUserMailHelper
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('generateTemplate')
|
|
|
|
->willReturn($emailTemplate);
|
|
|
|
$this->newUserMailHelper
|
2018-09-24 23:54:57 +03:00
|
|
|
->expects($this->at(1))
|
2017-04-07 15:51:05 +03:00
|
|
|
->method('sendMail')
|
|
|
|
->with($targetUser, $emailTemplate);
|
2017-02-24 09:01:13 +03:00
|
|
|
|
|
|
|
$this->api->resendWelcomeMessage('UserToGet');
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:42:07 +03:00
|
|
|
|
2017-02-24 09:01:13 +03:00
|
|
|
public function testResendWelcomeMessageFailed() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('Sending email failed');
|
|
|
|
$this->expectExceptionCode(102);
|
|
|
|
|
2017-10-24 16:26:53 +03:00
|
|
|
$loggedInUser = $this->getMockBuilder(IUser::class)
|
2017-02-24 09:01:13 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2017-10-24 16:26:53 +03:00
|
|
|
$targetUser = $this->getMockBuilder(IUser::class)
|
2017-02-24 09:01:13 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$targetUser
|
|
|
|
->method('getUID')
|
|
|
|
->willReturn('user-id');
|
|
|
|
$this->userSession
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getUser')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($loggedInUser);
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->userManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('get')
|
|
|
|
->with('UserToGet')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($targetUser);
|
2017-02-24 09:01:13 +03:00
|
|
|
$subAdminManager = $this->getMockBuilder('OC\SubAdmin')
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isUserAccessible')
|
|
|
|
->with($loggedInUser, $targetUser)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-02-24 09:01:13 +03:00
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getSubAdmin')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn($subAdminManager);
|
2017-02-24 09:01:13 +03:00
|
|
|
$targetUser
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getEmailAddress')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('abc@example.org');
|
2017-04-07 15:51:05 +03:00
|
|
|
$emailTemplate = $this->createMock(IEMailTemplate::class);
|
|
|
|
$this->newUserMailHelper
|
|
|
|
->expects($this->at(0))
|
|
|
|
->method('generateTemplate')
|
|
|
|
->willReturn($emailTemplate);
|
|
|
|
$this->newUserMailHelper
|
2018-09-24 23:54:57 +03:00
|
|
|
->expects($this->at(1))
|
2017-04-07 15:51:05 +03:00
|
|
|
->method('sendMail')
|
|
|
|
->with($targetUser, $emailTemplate)
|
|
|
|
->willThrowException(new \Exception());
|
2017-02-24 09:01:13 +03:00
|
|
|
|
|
|
|
$this->api->resendWelcomeMessage('UserToGet');
|
|
|
|
}
|
2018-01-26 14:47:59 +03:00
|
|
|
|
|
|
|
|
|
|
|
public function dataGetEditableFields() {
|
|
|
|
return [
|
|
|
|
[false, false, []],
|
|
|
|
[false, true, [
|
2020-12-01 16:33:22 +03:00
|
|
|
IAccountManager::PROPERTY_PHONE,
|
|
|
|
IAccountManager::PROPERTY_ADDRESS,
|
|
|
|
IAccountManager::PROPERTY_WEBSITE,
|
|
|
|
IAccountManager::PROPERTY_TWITTER,
|
2018-01-26 14:47:59 +03:00
|
|
|
]],
|
|
|
|
[ true, false, [
|
2020-12-01 16:33:22 +03:00
|
|
|
IAccountManager::PROPERTY_DISPLAYNAME,
|
|
|
|
IAccountManager::PROPERTY_EMAIL,
|
2018-01-26 14:47:59 +03:00
|
|
|
]],
|
|
|
|
[ true, true ,[
|
2020-12-01 16:33:22 +03:00
|
|
|
IAccountManager::PROPERTY_DISPLAYNAME,
|
|
|
|
IAccountManager::PROPERTY_EMAIL,
|
|
|
|
IAccountManager::PROPERTY_PHONE,
|
|
|
|
IAccountManager::PROPERTY_ADDRESS,
|
|
|
|
IAccountManager::PROPERTY_WEBSITE,
|
|
|
|
IAccountManager::PROPERTY_TWITTER,
|
2018-01-26 14:47:59 +03:00
|
|
|
]]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataGetEditableFields
|
|
|
|
*
|
|
|
|
* @param bool $allowedToChangeDisplayName
|
|
|
|
* @param bool $federatedSharingEnabled
|
|
|
|
* @param array $expected
|
|
|
|
*/
|
|
|
|
public function testGetEditableFields(bool $allowedToChangeDisplayName, bool $federatedSharingEnabled, array $expected) {
|
|
|
|
$this->config
|
|
|
|
->method('getSystemValue')
|
|
|
|
->with(
|
|
|
|
$this->equalTo('allow_user_to_change_display_name'),
|
|
|
|
$this->anything()
|
|
|
|
)->willReturn($allowedToChangeDisplayName);
|
|
|
|
$this->appManager
|
|
|
|
->method('isEnabledForUser')
|
|
|
|
->with($this->equalTo('federatedfilesharing'))
|
|
|
|
->willReturn($federatedSharingEnabled);
|
|
|
|
|
|
|
|
$shareprovider = $this->createMock(FederatedShareProvider::class);
|
|
|
|
$shareprovider->method('isLookupServerUploadEnabled')->willReturn(true);
|
|
|
|
|
2020-07-13 17:23:59 +03:00
|
|
|
$this->federatedShareProviderFactory
|
2018-01-26 14:47:59 +03:00
|
|
|
->method('get')
|
2020-07-13 17:23:59 +03:00
|
|
|
->willReturn($shareprovider);
|
2018-01-26 14:47:59 +03:00
|
|
|
|
|
|
|
$expectedResp = new DataResponse($expected);
|
|
|
|
$this->assertEquals($expectedResp, $this->api->getEditableFields());
|
|
|
|
}
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|