Merge pull request #7611 from nextcloud/fix-7445

Don't attempt to translate login names to uids when uids are provided
This commit is contained in:
Morris Jobke 2018-01-03 23:45:31 +01:00 committed by GitHub
commit 19280adc0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 47 deletions

View File

@ -1343,10 +1343,6 @@ class User_LDAPTest extends TestCase {
} }
return true; return true;
})); }));
$access->userManager->expects($this->atLeastOnce())
->method('get')
->willReturn($this->createMock(User::class));
} }
/** /**
@ -1357,6 +1353,9 @@ class User_LDAPTest extends TestCase {
$access = $this->getAccessMock(); $access = $this->getAccessMock();
$this->prepareAccessForSetPassword($access); $this->prepareAccessForSetPassword($access);
$access->userManager->expects($this->atLeastOnce())
->method('get')
->willReturn($this->createMock(User::class));
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock()); $backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
\OC_User::useBackend($backend); \OC_User::useBackend($backend);

View File

@ -224,6 +224,12 @@ class LostController extends Controller {
return new JSONResponse($this->error($this->l10n->t('Password reset is disabled'))); 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 // FIXME: use HTTP error codes
try { try {
$this->sendEmail($user); $this->sendEmail($user);

View File

@ -152,16 +152,6 @@ class Manager extends PublicEmitter implements IUserManager {
return $this->cachedUsers[$uid]; 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); $user = new User($uid, $backend, $this, $this->config);
if ($cacheUser) { if ($cacheUser) {
$this->cachedUsers[$uid] = $user; $this->cachedUsers[$uid] = $user;

View File

@ -368,39 +368,6 @@ class FilesystemTest extends \Test\TestCase {
$this->assertEquals(2, $thrown); $this->assertEquals(2, $thrown);
} }
public function testUserNameCasing() {
$this->logout();
$userId = $this->getUniqueID('user_');
\OC_User::clearBackends();
// needed for loginName2UserName mapping
$userBackend = $this->createMock(\OC\User\Database::class);
\OC::$server->getUserManager()->registerBackend($userBackend);
$userBackend->expects($this->once())
->method('userExists')
->with(strtoupper($userId))
->will($this->returnValue(true));
$userBackend->expects($this->once())
->method('loginName2UserName')
->with(strtoupper($userId))
->will($this->returnValue($userId));
$view = new \OC\Files\View();
$this->assertFalse($view->file_exists('/' . $userId));
\OC\Files\Filesystem::initMountPoints(strtoupper($userId));
list($storage1, $path1) = $view->resolvePath('/' . $userId);
list($storage2, $path2) = $view->resolvePath('/' . strtoupper($userId));
$this->assertTrue($storage1->instanceOfStorage('\OCP\Files\IHomeStorage'));
$this->assertEquals('', $path1);
// not mounted, still on the local root storage
$this->assertEquals(strtoupper($userId), $path2);
}
/** /**
* Tests that the home storage is used for the user's mount point * Tests that the home storage is used for the user's mount point
*/ */

View File

@ -185,6 +185,8 @@ class ManagerTest extends TestCase {
->method('userExists') ->method('userExists')
->with($this->equalTo('foo')) ->with($this->equalTo('foo'))
->will($this->returnValue(true)); ->will($this->returnValue(true));
$backend->expects($this->never())
->method('loginName2UserName');
$manager = new \OC\User\Manager($this->config); $manager = new \OC\User\Manager($this->config);
$manager->registerBackend($backend); $manager->registerBackend($backend);
@ -208,6 +210,24 @@ class ManagerTest extends TestCase {
$this->assertEquals(null, $manager->get('foo')); $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() { public function testSearchOneBackend() {
/** /**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend * @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
@ -217,6 +237,8 @@ class ManagerTest extends TestCase {
->method('getUsers') ->method('getUsers')
->with($this->equalTo('fo')) ->with($this->equalTo('fo'))
->will($this->returnValue(array('foo', 'afoo'))); ->will($this->returnValue(array('foo', 'afoo')));
$backend->expects($this->never())
->method('loginName2UserName');
$manager = new \OC\User\Manager($this->config); $manager = new \OC\User\Manager($this->config);
$manager->registerBackend($backend); $manager->registerBackend($backend);
@ -236,6 +258,8 @@ class ManagerTest extends TestCase {
->method('getUsers') ->method('getUsers')
->with($this->equalTo('fo'), $this->equalTo(3), $this->equalTo(1)) ->with($this->equalTo('fo'), $this->equalTo(3), $this->equalTo(1))
->will($this->returnValue(array('foo1', 'foo2'))); ->will($this->returnValue(array('foo1', 'foo2')));
$backend1->expects($this->never())
->method('loginName2UserName');
/** /**
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend2 * @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend2
@ -245,6 +269,8 @@ class ManagerTest extends TestCase {
->method('getUsers') ->method('getUsers')
->with($this->equalTo('fo'), $this->equalTo(3), $this->equalTo(1)) ->with($this->equalTo('fo'), $this->equalTo(3), $this->equalTo(1))
->will($this->returnValue(array('foo3'))); ->will($this->returnValue(array('foo3')));
$backend2->expects($this->never())
->method('loginName2UserName');
$manager = new \OC\User\Manager($this->config); $manager = new \OC\User\Manager($this->config);
$manager->registerBackend($backend1); $manager->registerBackend($backend1);
@ -324,6 +350,8 @@ class ManagerTest extends TestCase {
->method('userExists') ->method('userExists')
->with($this->equalTo('foo')) ->with($this->equalTo('foo'))
->will($this->returnValue(false)); ->will($this->returnValue(false));
$backend->expects($this->never())
->method('loginName2UserName');
$manager = new \OC\User\Manager($this->config); $manager = new \OC\User\Manager($this->config);
$manager->registerBackend($backend); $manager->registerBackend($backend);

View File

@ -108,6 +108,13 @@ class Dummy extends Backend implements \OCP\IUserBackend {
return false; return false;
} }
public function loginName2UserName($loginName) {
if(isset($this->users[strtolower($loginName)])) {
return strtolower($loginName);
}
return false;
}
/** /**
* Get a list of all users * Get a list of all users
* *