Skip to content

Commit bb59107

Browse files
authored
Merge pull request #7695 from nextcloud/stable11-7694
[stable11] Don't attempt to translate login names to uids when uids are provided
2 parents ca90fe3 + 9ac1c48 commit bb59107

File tree

8 files changed

+57
-65
lines changed

8 files changed

+57
-65
lines changed

apps/user_ldap/tests/User_LDAPTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,11 @@ private function prepareAccessForSetPassword(&$access, $enablePasswordChange = t
10131013
->will($this->returnValue('roland'));
10141014

10151015
$access->expects($this->any())
1016-
->method('stringResemblesDN')
1017-
->with($this->equalTo('dnOfRoland,dc=test'))
1018-
->will($this->returnValue(true));
1016+
->method('stringResemblesDN')
1017+
->will($this->returnCallback(function($string) {
1018+
// very simplified
1019+
return strpos($string, ',') !== false;
1020+
}));
10191021

10201022
$access->expects($this->any())
10211023
->method('setPassword')

core/Controller/LostController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ private function success() {
206206
* @return array
207207
*/
208208
public function email($user){
209+
\OCP\Util::emitHook(
210+
'\OCA\Files_Sharing\API\Server2Server',
211+
'preLoginNameUsedAsUserName',
212+
['uid' => &$user]
213+
);
214+
209215
// FIXME: use HTTP error codes
210216
try {
211217
$this->sendEmail($user);

lib/composer/composer/ClassLoader.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
class ClassLoader
4444
{
4545
// PSR-4
46-
private $prefixLengthsPsr4 = array();
46+
private $firstCharsPsr4 = array();
4747
private $prefixDirsPsr4 = array();
4848
private $fallbackDirsPsr4 = array();
4949

@@ -170,11 +170,10 @@ public function addPsr4($prefix, $paths, $prepend = false)
170170
}
171171
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
172172
// Register directories for a new namespace.
173-
$length = strlen($prefix);
174-
if ('\\' !== $prefix[$length - 1]) {
173+
if ('\\' !== substr($prefix, -1)) {
175174
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
176175
}
177-
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
176+
$this->firstCharsPsr4[$prefix[0]] = true;
178177
$this->prefixDirsPsr4[$prefix] = (array) $paths;
179178
} elseif ($prepend) {
180179
// Prepend directories for an already registered namespace.
@@ -221,11 +220,10 @@ public function setPsr4($prefix, $paths)
221220
if (!$prefix) {
222221
$this->fallbackDirsPsr4 = (array) $paths;
223222
} else {
224-
$length = strlen($prefix);
225-
if ('\\' !== $prefix[$length - 1]) {
223+
if ('\\' !== substr($prefix, -1)) {
226224
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
227225
}
228-
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
226+
$this->firstCharsPsr4[$prefix[0]] = true;
229227
$this->prefixDirsPsr4[$prefix] = (array) $paths;
230228
}
231229
}
@@ -373,15 +371,15 @@ private function findFileWithExtension($class, $ext)
373371
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
374372

375373
$first = $class[0];
376-
if (isset($this->prefixLengthsPsr4[$first])) {
374+
if (isset($this->firstCharsPsr4[$first])) {
377375
$subPath = $class;
378376
while (false !== $lastPos = strrpos($subPath, '\\')) {
379377
$subPath = substr($subPath, 0, $lastPos);
380378
$search = $subPath.'\\';
381379
if (isset($this->prefixDirsPsr4[$search])) {
380+
$pathEnd = substr($logicalPathPsr4, $lastPos + 1);
382381
foreach ($this->prefixDirsPsr4[$search] as $dir) {
383-
$length = $this->prefixLengthsPsr4[$first][$search];
384-
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
382+
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $pathEnd)) {
385383
return $file;
386384
}
387385
}

lib/composer/composer/autoload_static.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,8 @@
66

77
class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
88
{
9-
public static $prefixLengthsPsr4 = array (
10-
'O' =>
11-
array (
12-
'OC\\Settings\\' => 12,
13-
'OC\\Core\\' => 8,
14-
'OC\\' => 3,
15-
'OCP\\' => 4,
16-
),
9+
public static $firstCharsPsr4 = array (
10+
'O' => true,
1711
);
1812

1913
public static $prefixDirsPsr4 = array (
@@ -848,7 +842,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
848842
public static function getInitializer(ClassLoader $loader)
849843
{
850844
return \Closure::bind(function () use ($loader) {
851-
$loader->prefixLengthsPsr4 = ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c::$prefixLengthsPsr4;
845+
$loader->firstCharsPsr4 = ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c::$firstCharsPsr4;
852846
$loader->prefixDirsPsr4 = ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c::$prefixDirsPsr4;
853847
$loader->classMap = ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c::$classMap;
854848

lib/private/User/Manager.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,6 @@ protected function getUserObject($uid, $backend, $cacheUser = true) {
149149
return $this->cachedUsers[$uid];
150150
}
151151

152-
if (method_exists($backend, 'loginName2UserName')) {
153-
$loginName = $backend->loginName2UserName($uid);
154-
if ($loginName !== false) {
155-
$uid = $loginName;
156-
}
157-
if (isset($this->cachedUsers[$uid])) {
158-
return $this->cachedUsers[$uid];
159-
}
160-
}
161-
162152
$user = new User($uid, $backend, $this, $this->config);
163153
if ($cacheUser) {
164154
$this->cachedUsers[$uid] = $user;

tests/lib/Files/FilesystemTest.php

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -368,39 +368,6 @@ public function testLocalMountWhenUserDoesNotExistTwice() {
368368
$this->assertEquals(2, $thrown);
369369
}
370370

371-
public function testUserNameCasing() {
372-
$this->logout();
373-
$userId = $this->getUniqueID('user_');
374-
375-
\OC_User::clearBackends();
376-
// needed for loginName2UserName mapping
377-
$userBackend = $this->createMock(\OC\User\Database::class);
378-
\OC::$server->getUserManager()->registerBackend($userBackend);
379-
380-
$userBackend->expects($this->once())
381-
->method('userExists')
382-
->with(strtoupper($userId))
383-
->will($this->returnValue(true));
384-
$userBackend->expects($this->once())
385-
->method('loginName2UserName')
386-
->with(strtoupper($userId))
387-
->will($this->returnValue($userId));
388-
389-
$view = new \OC\Files\View();
390-
$this->assertFalse($view->file_exists('/' . $userId));
391-
392-
\OC\Files\Filesystem::initMountPoints(strtoupper($userId));
393-
394-
list($storage1, $path1) = $view->resolvePath('/' . $userId);
395-
list($storage2, $path2) = $view->resolvePath('/' . strtoupper($userId));
396-
397-
$this->assertTrue($storage1->instanceOfStorage('\OCP\Files\IHomeStorage'));
398-
$this->assertEquals('', $path1);
399-
400-
// not mounted, still on the local root storage
401-
$this->assertEquals(strtoupper($userId), $path2);
402-
}
403-
404371
/**
405372
* Tests that the home storage is used for the user's mount point
406373
*/

tests/lib/User/ManagerTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ public function testGetOneBackendExists() {
184184
->method('userExists')
185185
->with($this->equalTo('foo'))
186186
->will($this->returnValue(true));
187+
$backend->expects($this->never())
188+
->method('loginName2UserName');
187189

188190
$manager = new \OC\User\Manager($this->config);
189191
$manager->registerBackend($backend);
@@ -207,6 +209,24 @@ public function testGetOneBackendNotExists() {
207209
$this->assertEquals(null, $manager->get('foo'));
208210
}
209211

212+
public function testGetOneBackendDoNotTranslateLoginNames() {
213+
/**
214+
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
215+
*/
216+
$backend = $this->createMock(\Test\Util\User\Dummy::class);
217+
$backend->expects($this->once())
218+
->method('userExists')
219+
->with($this->equalTo('bLeNdEr'))
220+
->will($this->returnValue(true));
221+
$backend->expects($this->never())
222+
->method('loginName2UserName');
223+
224+
$manager = new \OC\User\Manager($this->config);
225+
$manager->registerBackend($backend);
226+
227+
$this->assertEquals('bLeNdEr', $manager->get('bLeNdEr')->getUID());
228+
}
229+
210230
public function testSearchOneBackend() {
211231
/**
212232
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend
@@ -216,6 +236,8 @@ public function testSearchOneBackend() {
216236
->method('getUsers')
217237
->with($this->equalTo('fo'))
218238
->will($this->returnValue(array('foo', 'afoo')));
239+
$backend->expects($this->never())
240+
->method('loginName2UserName');
219241

220242
$manager = new \OC\User\Manager($this->config);
221243
$manager->registerBackend($backend);
@@ -235,6 +257,8 @@ public function testSearchTwoBackendLimitOffset() {
235257
->method('getUsers')
236258
->with($this->equalTo('fo'), $this->equalTo(3), $this->equalTo(1))
237259
->will($this->returnValue(array('foo1', 'foo2')));
260+
$backend1->expects($this->never())
261+
->method('loginName2UserName');
238262

239263
/**
240264
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend2
@@ -244,6 +268,8 @@ public function testSearchTwoBackendLimitOffset() {
244268
->method('getUsers')
245269
->with($this->equalTo('fo'), $this->equalTo(3), $this->equalTo(1))
246270
->will($this->returnValue(array('foo3')));
271+
$backend2->expects($this->never())
272+
->method('loginName2UserName');
247273

248274
$manager = new \OC\User\Manager($this->config);
249275
$manager->registerBackend($backend1);
@@ -316,6 +342,8 @@ public function testCreateUserSingleBackendNotExists() {
316342
->method('userExists')
317343
->with($this->equalTo('foo'))
318344
->will($this->returnValue(false));
345+
$backend->expects($this->never())
346+
->method('loginName2UserName');
319347

320348
$manager = new \OC\User\Manager($this->config);
321349
$manager->registerBackend($backend);

tests/lib/Util/User/Dummy.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ public function checkPassword($uid, $password) {
108108
}
109109
}
110110

111+
public function loginName2UserName($loginName) {
112+
if(isset($this->users[strtolower($loginName)])) {
113+
return strtolower($loginName);
114+
}
115+
return false;
116+
}
117+
111118
/**
112119
* Get a list of all users
113120
*

0 commit comments

Comments
 (0)