diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-12-22 15:22:49 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-01-04 11:47:31 +0100 |
commit | 776d9e6805a8c100fd746c577a6442ff0bcffb57 (patch) | |
tree | 3f7aa4f77128a801c944269b2254047b8f5e7435 | |
parent | c94c2c48a613d3ca4f77fb3b77b7d453ee3eea46 (diff) | |
download | nextcloud-server-776d9e6805a8c100fd746c577a6442ff0bcffb57.tar.gz nextcloud-server-776d9e6805a8c100fd746c577a6442ff0bcffb57.zip |
never translate login names when requiring with a user id
where appropriate, the preLoginNameUsedAsUserName hook should be thrown.
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
-rw-r--r-- | core/Controller/LostController.php | 6 | ||||
-rw-r--r-- | lib/private/User/Manager.php | 10 | ||||
-rw-r--r-- | tests/lib/User/ManagerTest.php | 40 |
3 files changed, 34 insertions, 22 deletions
diff --git a/core/Controller/LostController.php b/core/Controller/LostController.php index 13fb6fee5cb..86f9e7478e3 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 8f3c98d4b5e..2d3ce7ebe39 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 02200b05d05..badcfb551b7 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); |