diff --git a/core/Controller/LostController.php b/core/Controller/LostController.php index 13fb6fee5c..86f9e7478e 100644 --- a/core/Controller/LostController.php +++ b/core/Controller/LostController.php @@ -223,6 +223,12 @@ class LostController extends Controller { return new JSONResponse($this->error($this->l10n->t('Password reset is disabled'))); } + \OCP\Util::emitHook( + '\OCA\Files_Sharing\API\Server2Server', + 'preLoginNameUsedAsUserName', + ['uid' => &$user] + ); + // FIXME: use HTTP error codes try { $this->sendEmail($user); diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index 8f3c98d4b5..2d3ce7ebe3 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -154,16 +154,6 @@ class Manager extends PublicEmitter implements IUserManager { return $this->cachedUsers[$uid]; } - if (method_exists($backend, 'loginName2UserName')) { - $loginName = $backend->loginName2UserName($uid); - if ($loginName !== false) { - $uid = $loginName; - } - if (isset($this->cachedUsers[$uid])) { - return $this->cachedUsers[$uid]; - } - } - $user = new User($uid, $backend, $this, $this->config); if ($cacheUser) { $this->cachedUsers[$uid] = $user; diff --git a/tests/lib/User/ManagerTest.php b/tests/lib/User/ManagerTest.php index 02200b05d0..badcfb551b 100644 --- a/tests/lib/User/ManagerTest.php +++ b/tests/lib/User/ManagerTest.php @@ -184,9 +184,8 @@ class ManagerTest extends TestCase { ->method('userExists') ->with($this->equalTo('foo')) ->will($this->returnValue(true)); - $backend->expects($this->once()) - ->method('loginName2UserName') - ->willReturn(false); + $backend->expects($this->never()) + ->method('loginName2UserName'); $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend); @@ -210,6 +209,24 @@ class ManagerTest extends TestCase { $this->assertEquals(null, $manager->get('foo')); } + public function testGetOneBackendDoNotTranslateLoginNames() { + /** + * @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend + */ + $backend = $this->createMock(\Test\Util\User\Dummy::class); + $backend->expects($this->once()) + ->method('userExists') + ->with($this->equalTo('bLeNdEr')) + ->will($this->returnValue(true)); + $backend->expects($this->never()) + ->method('loginName2UserName'); + + $manager = new \OC\User\Manager($this->config); + $manager->registerBackend($backend); + + $this->assertEquals('bLeNdEr', $manager->get('bLeNdEr')->getUID()); + } + public function testSearchOneBackend() { /** * @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend @@ -219,6 +236,8 @@ class ManagerTest extends TestCase { ->method('getUsers') ->with($this->equalTo('fo')) ->will($this->returnValue(array('foo', 'afoo'))); + $backend->expects($this->never()) + ->method('loginName2UserName'); $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend); @@ -238,9 +257,8 @@ class ManagerTest extends TestCase { ->method('getUsers') ->with($this->equalTo('fo'), $this->equalTo(3), $this->equalTo(1)) ->will($this->returnValue(array('foo1', 'foo2'))); - $backend1->expects($this->exactly(2)) - ->method('loginName2UserName') - ->willReturn(false); + $backend1->expects($this->never()) + ->method('loginName2UserName'); /** * @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend2 @@ -250,9 +268,8 @@ class ManagerTest extends TestCase { ->method('getUsers') ->with($this->equalTo('fo'), $this->equalTo(3), $this->equalTo(1)) ->will($this->returnValue(array('foo3'))); - $backend2->expects($this->once()) - ->method('loginName2UserName') - ->willReturn(false); + $backend2->expects($this->never()) + ->method('loginName2UserName'); $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend1); @@ -333,9 +350,8 @@ class ManagerTest extends TestCase { ->method('userExists') ->with($this->equalTo('foo')) ->will($this->returnValue(false)); - $backend->expects($this->once()) - ->method('loginName2UserName') - ->willReturn(false); + $backend->expects($this->never()) + ->method('loginName2UserName'); $manager = new \OC\User\Manager($this->config); $manager->registerBackend($backend);