2013-05-29 01:46:57 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Test\User;
|
2020-04-09 12:48:10 +03:00
|
|
|
|
2018-12-20 13:09:10 +03:00
|
|
|
use OC\AllConfig;
|
2016-09-12 22:53:21 +03:00
|
|
|
use OC\User\Database;
|
2017-08-17 13:08:40 +03:00
|
|
|
use OC\User\Manager;
|
2019-11-20 16:22:00 +03:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2021-02-02 17:45:34 +03:00
|
|
|
use OCP\ICache;
|
|
|
|
use OCP\ICacheFactory;
|
2016-10-28 10:07:40 +03:00
|
|
|
use OCP\IConfig;
|
2016-10-19 11:03:29 +03:00
|
|
|
use OCP\IUser;
|
2019-02-22 15:07:26 +03:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2016-10-19 11:03:29 +03:00
|
|
|
use Test\TestCase;
|
2013-05-29 01:46:57 +04:00
|
|
|
|
2015-11-19 16:39:05 +03:00
|
|
|
/**
|
2016-05-20 16:38:20 +03:00
|
|
|
* Class ManagerTest
|
2015-11-19 16:39:05 +03:00
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
|
|
|
* @package Test\User
|
|
|
|
*/
|
2016-10-19 11:03:29 +03:00
|
|
|
class ManagerTest extends TestCase {
|
2016-10-28 10:07:40 +03:00
|
|
|
|
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
2019-02-22 15:07:26 +03:00
|
|
|
/** @var EventDispatcherInterface */
|
2019-11-20 16:22:00 +03:00
|
|
|
private $oldDispatcher;
|
|
|
|
/** @var IEventDispatcher */
|
|
|
|
private $eventDispatcher;
|
2021-02-02 17:45:34 +03:00
|
|
|
/** @var ICacheFactory */
|
|
|
|
private $cacheFactory;
|
|
|
|
/** @var ICache */
|
|
|
|
private $cache;
|
2016-10-28 10:07:40 +03:00
|
|
|
|
2019-11-27 17:27:18 +03:00
|
|
|
protected function setUp(): void {
|
2016-10-28 10:07:40 +03:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
2019-11-20 16:22:00 +03:00
|
|
|
$this->oldDispatcher = $this->createMock(EventDispatcherInterface::class);
|
|
|
|
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
|
2021-02-02 17:45:34 +03:00
|
|
|
$this->cacheFactory = $this->createMock(ICacheFactory::class);
|
|
|
|
$this->cache = $this->createMock(ICache::class);
|
|
|
|
|
|
|
|
$this->cacheFactory->method('createDistributed')
|
|
|
|
->with('user_backend_map')
|
|
|
|
->willReturn($this->cache);
|
2016-10-28 10:07:40 +03:00
|
|
|
}
|
|
|
|
|
2014-12-09 20:36:40 +03:00
|
|
|
public function testGetBackends() {
|
2016-09-12 22:53:21 +03:00
|
|
|
$userDummyBackend = $this->createMock(\Test\Util\User\Dummy::class);
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2014-12-09 20:36:40 +03:00
|
|
|
$manager->registerBackend($userDummyBackend);
|
|
|
|
$this->assertEquals([$userDummyBackend], $manager->getBackends());
|
2016-09-12 22:53:21 +03:00
|
|
|
$dummyDatabaseBackend = $this->createMock(Database::class);
|
2014-12-09 20:36:40 +03:00
|
|
|
$manager->registerBackend($dummyDatabaseBackend);
|
|
|
|
$this->assertEquals([$userDummyBackend, $dummyDatabaseBackend], $manager->getBackends());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-29 01:46:57 +04:00
|
|
|
public function testUserExistsSingleBackendExists() {
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->equalTo('foo'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-05-29 01:46:57 +04:00
|
|
|
$manager->registerBackend($backend);
|
|
|
|
|
|
|
|
$this->assertTrue($manager->userExists('foo'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUserExistsSingleBackendNotExists() {
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->equalTo('foo'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-05-29 01:46:57 +04:00
|
|
|
$manager->registerBackend($backend);
|
|
|
|
|
|
|
|
$this->assertFalse($manager->userExists('foo'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUserExistsNoBackends() {
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
|
|
|
$this->assertFalse($manager->userExists('foo'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUserExistsTwoBackendsSecondExists() {
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend1
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend1 = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend1->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->equalTo('foo'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend2
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend2 = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend2->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->equalTo('foo'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-05-29 01:46:57 +04:00
|
|
|
$manager->registerBackend($backend1);
|
|
|
|
$manager->registerBackend($backend2);
|
|
|
|
|
|
|
|
$this->assertTrue($manager->userExists('foo'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUserExistsTwoBackendsFirstExists() {
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend1
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend1 = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend1->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->equalTo('foo'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend2
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend2 = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend2->expects($this->never())
|
|
|
|
->method('userExists');
|
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-05-29 01:46:57 +04:00
|
|
|
$manager->registerBackend($backend1);
|
|
|
|
$manager->registerBackend($backend2);
|
|
|
|
|
|
|
|
$this->assertTrue($manager->userExists('foo'));
|
|
|
|
}
|
|
|
|
|
2013-09-24 19:10:01 +04:00
|
|
|
public function testCheckPassword() {
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\User\Backend | \PHPUnit\Framework\MockObject\MockObject $backend
|
2013-09-24 19:10:01 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-09-24 19:10:01 +04:00
|
|
|
$backend->expects($this->once())
|
|
|
|
->method('checkPassword')
|
|
|
|
->with($this->equalTo('foo'), $this->equalTo('bar'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2013-09-24 19:10:01 +04:00
|
|
|
|
|
|
|
$backend->expects($this->any())
|
|
|
|
->method('implementsActions')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturnCallback(function ($actions) {
|
2016-07-13 10:26:19 +03:00
|
|
|
if ($actions === \OC\USER\BACKEND::CHECK_PASSWORD) {
|
2013-09-24 19:10:01 +04:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2013-09-24 19:10:01 +04:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-09-24 19:10:01 +04:00
|
|
|
$manager->registerBackend($backend);
|
|
|
|
|
|
|
|
$user = $manager->checkPassword('foo', 'bar');
|
|
|
|
$this->assertTrue($user instanceof \OC\User\User);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCheckPasswordNotSupported() {
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \OC\User\Backend | \PHPUnit\Framework\MockObject\MockObject $backend
|
2013-09-24 19:10:01 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-09-24 19:10:01 +04:00
|
|
|
$backend->expects($this->never())
|
|
|
|
->method('checkPassword');
|
|
|
|
|
|
|
|
$backend->expects($this->any())
|
|
|
|
->method('implementsActions')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2013-09-24 19:10:01 +04:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-09-24 19:10:01 +04:00
|
|
|
$manager->registerBackend($backend);
|
|
|
|
|
|
|
|
$this->assertFalse($manager->checkPassword('foo', 'bar'));
|
|
|
|
}
|
|
|
|
|
2013-05-29 01:46:57 +04:00
|
|
|
public function testGetOneBackendExists() {
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->equalTo('foo'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-12-22 17:22:49 +03:00
|
|
|
$backend->expects($this->never())
|
|
|
|
->method('loginName2UserName');
|
2013-05-29 01:46:57 +04:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-05-29 01:46:57 +04:00
|
|
|
$manager->registerBackend($backend);
|
|
|
|
|
|
|
|
$this->assertEquals('foo', $manager->get('foo')->getUID());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetOneBackendNotExists() {
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->equalTo('foo'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-05-29 01:46:57 +04:00
|
|
|
$manager->registerBackend($backend);
|
|
|
|
|
|
|
|
$this->assertEquals(null, $manager->get('foo'));
|
|
|
|
}
|
|
|
|
|
2017-12-22 17:22:49 +03:00
|
|
|
public function testGetOneBackendDoNotTranslateLoginNames() {
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend
|
2017-12-22 17:22:49 +03:00
|
|
|
*/
|
|
|
|
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
|
|
|
$backend->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->equalTo('bLeNdEr'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2017-12-22 17:22:49 +03:00
|
|
|
$backend->expects($this->never())
|
|
|
|
->method('loginName2UserName');
|
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2017-12-22 17:22:49 +03:00
|
|
|
$manager->registerBackend($backend);
|
|
|
|
|
|
|
|
$this->assertEquals('bLeNdEr', $manager->get('bLeNdEr')->getUID());
|
|
|
|
}
|
|
|
|
|
2013-05-29 01:46:57 +04:00
|
|
|
public function testSearchOneBackend() {
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend->expects($this->once())
|
|
|
|
->method('getUsers')
|
|
|
|
->with($this->equalTo('fo'))
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn(['foo', 'afoo', 'Afoo1', 'Bfoo']);
|
2017-12-22 17:22:49 +03:00
|
|
|
$backend->expects($this->never())
|
|
|
|
->method('loginName2UserName');
|
2013-05-29 01:46:57 +04:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-05-29 01:46:57 +04:00
|
|
|
$manager->registerBackend($backend);
|
|
|
|
|
|
|
|
$result = $manager->search('fo');
|
2018-05-26 13:07:49 +03:00
|
|
|
$this->assertEquals(4, count($result));
|
2014-03-14 16:51:17 +04:00
|
|
|
$this->assertEquals('afoo', array_shift($result)->getUID());
|
2018-05-26 13:07:49 +03:00
|
|
|
$this->assertEquals('Afoo1', array_shift($result)->getUID());
|
|
|
|
$this->assertEquals('Bfoo', array_shift($result)->getUID());
|
2014-03-14 16:51:17 +04:00
|
|
|
$this->assertEquals('foo', array_shift($result)->getUID());
|
2013-05-29 01:46:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testSearchTwoBackendLimitOffset() {
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend1
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend1 = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend1->expects($this->once())
|
|
|
|
->method('getUsers')
|
|
|
|
->with($this->equalTo('fo'), $this->equalTo(3), $this->equalTo(1))
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn(['foo1', 'foo2']);
|
2017-12-22 17:22:49 +03:00
|
|
|
$backend1->expects($this->never())
|
|
|
|
->method('loginName2UserName');
|
2013-05-29 01:46:57 +04:00
|
|
|
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend2
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend2 = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend2->expects($this->once())
|
|
|
|
->method('getUsers')
|
2014-04-15 19:53:57 +04:00
|
|
|
->with($this->equalTo('fo'), $this->equalTo(3), $this->equalTo(1))
|
2020-03-26 11:30:18 +03:00
|
|
|
->willReturn(['foo3']);
|
2017-12-22 17:22:49 +03:00
|
|
|
$backend2->expects($this->never())
|
|
|
|
->method('loginName2UserName');
|
2013-05-29 01:46:57 +04:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-05-29 01:46:57 +04:00
|
|
|
$manager->registerBackend($backend1);
|
|
|
|
$manager->registerBackend($backend2);
|
|
|
|
|
|
|
|
$result = $manager->search('fo', 3, 1);
|
|
|
|
$this->assertEquals(3, count($result));
|
2014-03-14 16:51:17 +04:00
|
|
|
$this->assertEquals('foo1', array_shift($result)->getUID());
|
|
|
|
$this->assertEquals('foo2', array_shift($result)->getUID());
|
|
|
|
$this->assertEquals('foo3', array_shift($result)->getUID());
|
2013-05-29 01:46:57 +04:00
|
|
|
}
|
|
|
|
|
2017-04-12 11:29:28 +03:00
|
|
|
public function dataCreateUserInvalid() {
|
|
|
|
return [
|
|
|
|
['te?st', 'foo', 'Only the following characters are allowed in a username:'
|
|
|
|
. ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
|
|
|
|
["te\tst", '', 'Only the following characters are allowed in a username:'
|
|
|
|
. ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
|
|
|
|
["te\nst", '', 'Only the following characters are allowed in a username:'
|
|
|
|
. ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
|
|
|
|
["te\rst", '', 'Only the following characters are allowed in a username:'
|
|
|
|
. ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
|
|
|
|
["te\0st", '', 'Only the following characters are allowed in a username:'
|
|
|
|
. ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
|
|
|
|
["te\x0Bst", '', 'Only the following characters are allowed in a username:'
|
|
|
|
. ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
|
|
|
|
["te\xe2st", '', 'Only the following characters are allowed in a username:'
|
|
|
|
. ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
|
|
|
|
["te\x80st", '', 'Only the following characters are allowed in a username:'
|
|
|
|
. ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
|
|
|
|
["te\x8bst", '', 'Only the following characters are allowed in a username:'
|
|
|
|
. ' "a-z", "A-Z", "0-9", and "_.@-\'"'],
|
|
|
|
['', 'foo', 'A valid username must be provided'],
|
|
|
|
[' ', 'foo', 'A valid username must be provided'],
|
|
|
|
[' test', 'foo', 'Username contains whitespace at the beginning or at the end'],
|
|
|
|
['test ', 'foo', 'Username contains whitespace at the beginning or at the end'],
|
|
|
|
['.', 'foo', 'Username must not consist of dots only'],
|
|
|
|
['..', 'foo', 'Username must not consist of dots only'],
|
|
|
|
['.test', '', 'A valid password must be provided'],
|
|
|
|
['test', '', 'A valid password must be provided'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataCreateUserInvalid
|
|
|
|
*/
|
|
|
|
public function testCreateUserInvalid($uid, $password, $exception) {
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \Test\Util\User\Dummy|\PHPUnit\Framework\MockObject\MockObject $backend */
|
2017-04-27 09:56:51 +03:00
|
|
|
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
|
|
|
$backend->expects($this->once())
|
|
|
|
->method('implementsActions')
|
|
|
|
->with(\OC\User\Backend::CREATE_USER)
|
|
|
|
->willReturn(true);
|
2017-04-12 11:29:28 +03:00
|
|
|
|
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2017-04-27 09:56:51 +03:00
|
|
|
$manager->registerBackend($backend);
|
|
|
|
|
2018-01-24 20:10:16 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class, $exception);
|
2017-04-12 11:29:28 +03:00
|
|
|
$manager->createUser($uid, $password);
|
|
|
|
}
|
|
|
|
|
2013-05-29 01:46:57 +04:00
|
|
|
public function testCreateUserSingleBackendNotExists() {
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend->expects($this->any())
|
|
|
|
->method('implementsActions')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
|
|
|
$backend->expects($this->once())
|
|
|
|
->method('createUser')
|
|
|
|
->with($this->equalTo('foo'), $this->equalTo('bar'));
|
|
|
|
|
|
|
|
$backend->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->equalTo('foo'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2017-12-22 17:22:49 +03:00
|
|
|
$backend->expects($this->never())
|
|
|
|
->method('loginName2UserName');
|
2013-05-29 01:46:57 +04:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-05-29 01:46:57 +04:00
|
|
|
$manager->registerBackend($backend);
|
|
|
|
|
|
|
|
$user = $manager->createUser('foo', 'bar');
|
|
|
|
$this->assertEquals('foo', $user->getUID());
|
|
|
|
}
|
|
|
|
|
2019-11-20 16:22:00 +03:00
|
|
|
|
2013-05-29 01:46:57 +04:00
|
|
|
public function testCreateUserSingleBackendExists() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
|
2013-05-29 01:46:57 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend->expects($this->any())
|
|
|
|
->method('implementsActions')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
|
|
|
$backend->expects($this->never())
|
|
|
|
->method('createUser');
|
|
|
|
|
|
|
|
$backend->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->equalTo('foo'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-05-29 01:46:57 +04:00
|
|
|
$manager->registerBackend($backend);
|
|
|
|
|
|
|
|
$manager->createUser('foo', 'bar');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateUserSingleBackendNotSupported() {
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend->expects($this->any())
|
|
|
|
->method('implementsActions')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
|
|
|
$backend->expects($this->never())
|
|
|
|
->method('createUser');
|
|
|
|
|
2017-04-27 09:56:51 +03:00
|
|
|
$backend->expects($this->never())
|
|
|
|
->method('userExists');
|
2013-05-29 01:46:57 +04:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-05-29 01:46:57 +04:00
|
|
|
$manager->registerBackend($backend);
|
|
|
|
|
|
|
|
$this->assertFalse($manager->createUser('foo', 'bar'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCreateUserNoBackends() {
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
|
|
|
$this->assertFalse($manager->createUser('foo', 'bar'));
|
|
|
|
}
|
|
|
|
|
2019-11-20 16:22:00 +03:00
|
|
|
|
2017-08-17 13:08:40 +03:00
|
|
|
public function testCreateUserFromBackendWithBackendError() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
$this->expectExceptionMessage('Could not create user');
|
|
|
|
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var IConfig|\PHPUnit\Framework\MockObject\MockObject $config */
|
2017-08-17 13:08:40 +03:00
|
|
|
$config = $this->createMock(IConfig::class);
|
2020-08-11 22:32:18 +03:00
|
|
|
/** @var \Test\Util\User\Dummy|\PHPUnit\Framework\MockObject\MockObject $backend */
|
2017-08-17 13:08:40 +03:00
|
|
|
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
|
|
|
$backend
|
|
|
|
->expects($this->once())
|
|
|
|
->method('createUser')
|
|
|
|
->with('MyUid', 'MyPassword')
|
|
|
|
->willReturn(false);
|
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2017-08-17 13:08:40 +03:00
|
|
|
$manager->createUserFromBackend('MyUid', 'MyPassword', $backend);
|
|
|
|
}
|
|
|
|
|
2019-11-20 16:22:00 +03:00
|
|
|
|
2013-05-29 01:46:57 +04:00
|
|
|
public function testCreateUserTwoBackendExists() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\Exception::class);
|
|
|
|
|
2013-05-29 01:46:57 +04:00
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend1
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend1 = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend1->expects($this->any())
|
|
|
|
->method('implementsActions')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
|
|
|
$backend1->expects($this->never())
|
|
|
|
->method('createUser');
|
|
|
|
|
|
|
|
$backend1->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->equalTo('foo'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend2
|
2013-05-29 01:46:57 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend2 = $this->createMock(\Test\Util\User\Dummy::class);
|
2013-05-29 01:46:57 +04:00
|
|
|
$backend2->expects($this->any())
|
|
|
|
->method('implementsActions')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
|
|
|
$backend2->expects($this->never())
|
|
|
|
->method('createUser');
|
|
|
|
|
|
|
|
$backend2->expects($this->once())
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->equalTo('foo'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2013-05-29 01:46:57 +04:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2013-05-29 01:46:57 +04:00
|
|
|
$manager->registerBackend($backend1);
|
|
|
|
$manager->registerBackend($backend2);
|
|
|
|
|
|
|
|
$manager->createUser('foo', 'bar');
|
|
|
|
}
|
2014-01-08 16:26:48 +04:00
|
|
|
|
|
|
|
public function testCountUsersNoBackend() {
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2014-01-08 16:26:48 +04:00
|
|
|
|
|
|
|
$result = $manager->countUsers();
|
|
|
|
$this->assertTrue(is_array($result));
|
|
|
|
$this->assertTrue(empty($result));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCountUsersOneBackend() {
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend
|
2014-01-08 16:26:48 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
2014-01-08 16:26:48 +04:00
|
|
|
$backend->expects($this->once())
|
|
|
|
->method('countUsers')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(7);
|
2014-01-08 16:26:48 +04:00
|
|
|
|
|
|
|
$backend->expects($this->once())
|
|
|
|
->method('implementsActions')
|
2016-07-13 10:26:19 +03:00
|
|
|
->with(\OC\USER\BACKEND::COUNT_USERS)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-01-08 16:26:48 +04:00
|
|
|
|
2014-12-12 19:25:03 +03:00
|
|
|
$backend->expects($this->once())
|
|
|
|
->method('getBackendName')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('Mock_Test_Util_User_Dummy');
|
2014-12-12 19:25:03 +03:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2014-01-08 16:26:48 +04:00
|
|
|
$manager->registerBackend($backend);
|
|
|
|
|
|
|
|
$result = $manager->countUsers();
|
|
|
|
$keys = array_keys($result);
|
2015-09-22 01:56:36 +03:00
|
|
|
$this->assertTrue(strpos($keys[0], 'Mock_Test_Util_User_Dummy') !== false);
|
2014-01-08 16:26:48 +04:00
|
|
|
|
|
|
|
$users = array_shift($result);
|
|
|
|
$this->assertEquals(7, $users);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCountUsersTwoBackends() {
|
|
|
|
/**
|
2020-08-11 22:32:18 +03:00
|
|
|
* @var \Test\Util\User\Dummy | \PHPUnit\Framework\MockObject\MockObject $backend
|
2014-01-08 16:26:48 +04:00
|
|
|
*/
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend1 = $this->createMock(\Test\Util\User\Dummy::class);
|
2014-01-08 16:26:48 +04:00
|
|
|
$backend1->expects($this->once())
|
|
|
|
->method('countUsers')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(7);
|
2014-01-08 16:26:48 +04:00
|
|
|
|
|
|
|
$backend1->expects($this->once())
|
|
|
|
->method('implementsActions')
|
2016-07-13 10:26:19 +03:00
|
|
|
->with(\OC\USER\BACKEND::COUNT_USERS)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-12-12 19:25:03 +03:00
|
|
|
$backend1->expects($this->once())
|
|
|
|
->method('getBackendName')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('Mock_Test_Util_User_Dummy');
|
2014-01-08 16:26:48 +04:00
|
|
|
|
2016-09-12 22:53:21 +03:00
|
|
|
$backend2 = $this->createMock(\Test\Util\User\Dummy::class);
|
2014-01-08 16:26:48 +04:00
|
|
|
$backend2->expects($this->once())
|
|
|
|
->method('countUsers')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(16);
|
2014-01-08 16:26:48 +04:00
|
|
|
|
|
|
|
$backend2->expects($this->once())
|
|
|
|
->method('implementsActions')
|
2016-07-13 10:26:19 +03:00
|
|
|
->with(\OC\USER\BACKEND::COUNT_USERS)
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2014-12-12 19:25:03 +03:00
|
|
|
$backend2->expects($this->once())
|
|
|
|
->method('getBackendName')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn('Mock_Test_Util_User_Dummy');
|
2014-01-08 16:26:48 +04:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2014-01-08 16:26:48 +04:00
|
|
|
$manager->registerBackend($backend1);
|
|
|
|
$manager->registerBackend($backend2);
|
|
|
|
|
|
|
|
$result = $manager->countUsers();
|
|
|
|
//because the backends have the same class name, only one value expected
|
|
|
|
$this->assertEquals(1, count($result));
|
|
|
|
$keys = array_keys($result);
|
2015-09-22 01:56:36 +03:00
|
|
|
$this->assertTrue(strpos($keys[0], 'Mock_Test_Util_User_Dummy') !== false);
|
2014-01-08 16:26:48 +04:00
|
|
|
|
|
|
|
$users = array_shift($result);
|
|
|
|
//users from backends shall be summed up
|
2014-11-05 17:45:58 +03:00
|
|
|
$this->assertEquals(7 + 16, $users);
|
|
|
|
}
|
|
|
|
|
2017-04-26 13:37:48 +03:00
|
|
|
public function testCountUsersOnlyDisabled() {
|
|
|
|
$manager = \OC::$server->getUserManager();
|
|
|
|
// count other users in the db before adding our own
|
|
|
|
$countBefore = $manager->countDisabledUsers();
|
|
|
|
|
|
|
|
//Add test users
|
|
|
|
$user1 = $manager->createUser('testdisabledcount1', 'testdisabledcount1');
|
|
|
|
|
|
|
|
$user2 = $manager->createUser('testdisabledcount2', 'testdisabledcount2');
|
|
|
|
$user2->setEnabled(false);
|
|
|
|
|
|
|
|
$user3 = $manager->createUser('testdisabledcount3', 'testdisabledcount3');
|
|
|
|
|
|
|
|
$user4 = $manager->createUser('testdisabledcount4', 'testdisabledcount4');
|
|
|
|
$user4->setEnabled(false);
|
|
|
|
|
|
|
|
$this->assertEquals($countBefore + 2, $manager->countDisabledUsers());
|
|
|
|
|
|
|
|
//cleanup
|
|
|
|
$user1->delete();
|
|
|
|
$user2->delete();
|
|
|
|
$user3->delete();
|
|
|
|
$user4->delete();
|
|
|
|
}
|
|
|
|
|
2016-10-19 11:03:29 +03:00
|
|
|
public function testCountUsersOnlySeen() {
|
|
|
|
$manager = \OC::$server->getUserManager();
|
|
|
|
// count other users in the db before adding our own
|
|
|
|
$countBefore = $manager->countUsers(true);
|
|
|
|
|
|
|
|
//Add test users
|
|
|
|
$user1 = $manager->createUser('testseencount1', 'testseencount1');
|
|
|
|
$user1->updateLastLoginTimestamp();
|
|
|
|
|
|
|
|
$user2 = $manager->createUser('testseencount2', 'testseencount2');
|
|
|
|
$user2->updateLastLoginTimestamp();
|
|
|
|
|
|
|
|
$user3 = $manager->createUser('testseencount3', 'testseencount3');
|
|
|
|
|
|
|
|
$user4 = $manager->createUser('testseencount4', 'testseencount4');
|
|
|
|
$user4->updateLastLoginTimestamp();
|
|
|
|
|
|
|
|
$this->assertEquals($countBefore + 3, $manager->countUsers(true));
|
|
|
|
|
|
|
|
//cleanup
|
|
|
|
$user1->delete();
|
|
|
|
$user2->delete();
|
|
|
|
$user3->delete();
|
|
|
|
$user4->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testCallForSeenUsers() {
|
|
|
|
$manager = \OC::$server->getUserManager();
|
|
|
|
// count other users in the db before adding our own
|
|
|
|
$count = 0;
|
|
|
|
$function = function (IUser $user) use (&$count) {
|
|
|
|
$count++;
|
|
|
|
};
|
|
|
|
$manager->callForAllUsers($function, '', true);
|
|
|
|
$countBefore = $count;
|
|
|
|
|
|
|
|
//Add test users
|
|
|
|
$user1 = $manager->createUser('testseen1', 'testseen1');
|
|
|
|
$user1->updateLastLoginTimestamp();
|
|
|
|
|
|
|
|
$user2 = $manager->createUser('testseen2', 'testseen2');
|
|
|
|
$user2->updateLastLoginTimestamp();
|
|
|
|
|
|
|
|
$user3 = $manager->createUser('testseen3', 'testseen3');
|
|
|
|
|
|
|
|
$user4 = $manager->createUser('testseen4', 'testseen4');
|
|
|
|
$user4->updateLastLoginTimestamp();
|
|
|
|
|
|
|
|
$count = 0;
|
|
|
|
$manager->callForAllUsers($function, '', true);
|
|
|
|
|
|
|
|
$this->assertEquals($countBefore + 3, $count);
|
|
|
|
|
|
|
|
//cleanup
|
|
|
|
$user1->delete();
|
|
|
|
$user2->delete();
|
|
|
|
$user3->delete();
|
|
|
|
$user4->delete();
|
|
|
|
}
|
|
|
|
|
2014-11-05 17:45:58 +03:00
|
|
|
public function testDeleteUser() {
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($this->config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2015-09-22 01:56:36 +03:00
|
|
|
$backend = new \Test\Util\User\Dummy();
|
2014-11-05 17:45:58 +03:00
|
|
|
|
|
|
|
$manager->registerBackend($backend);
|
2015-11-19 16:39:05 +03:00
|
|
|
$backend->createUser('foo', 'bar');
|
2014-11-05 17:45:58 +03:00
|
|
|
$this->assertTrue($manager->userExists('foo'));
|
|
|
|
$manager->get('foo')->delete();
|
|
|
|
$this->assertFalse($manager->userExists('foo'));
|
2014-01-08 16:26:48 +04:00
|
|
|
}
|
2018-10-14 20:09:55 +03:00
|
|
|
|
|
|
|
public function testGetByEmail() {
|
2018-12-20 13:09:10 +03:00
|
|
|
$config = $this->getMockBuilder(AllConfig::class)
|
2018-10-14 20:09:55 +03:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$config
|
|
|
|
->expects($this->at(0))
|
2018-12-20 13:09:10 +03:00
|
|
|
->method('getUsersForUserValueCaseInsensitive')
|
2018-10-14 20:09:55 +03:00
|
|
|
->with('settings', 'email', 'test@example.com')
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(['uid1', 'uid99', 'uid2']);
|
2018-10-14 20:09:55 +03:00
|
|
|
|
|
|
|
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
|
|
|
$backend->expects($this->at(0))
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->equalTo('uid1'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2018-10-14 20:09:55 +03:00
|
|
|
$backend->expects($this->at(1))
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->equalTo('uid99'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(false);
|
2018-10-14 20:09:55 +03:00
|
|
|
$backend->expects($this->at(2))
|
|
|
|
->method('userExists')
|
|
|
|
->with($this->equalTo('uid2'))
|
2020-03-26 00:21:27 +03:00
|
|
|
->willReturn(true);
|
2018-10-14 20:09:55 +03:00
|
|
|
|
2021-02-02 17:45:34 +03:00
|
|
|
$manager = new \OC\User\Manager($config, $this->oldDispatcher, $this->cacheFactory, $this->eventDispatcher);
|
2018-10-14 20:09:55 +03:00
|
|
|
$manager->registerBackend($backend);
|
|
|
|
|
|
|
|
$users = $manager->getByEmail('test@example.com');
|
|
|
|
$this->assertCount(2, $users);
|
|
|
|
$this->assertEquals('uid1', $users[0]->getUID());
|
|
|
|
$this->assertEquals('uid2', $users[1]->getUID());
|
|
|
|
}
|
2013-05-29 01:46:57 +04:00
|
|
|
}
|