Skip to content

Commit 19280ad

Browse files
authored
Merge pull request #7611 from nextcloud/fix-7445
Don't attempt to translate login names to uids when uids are provided
2 parents 5011142 + e9eccf3 commit 19280ad

6 files changed

Lines changed: 44 additions & 47 deletions

File tree

apps/user_ldap/tests/User_LDAPTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,10 +1343,6 @@ private function prepareAccessForSetPassword(&$access, $enablePasswordChange = t
13431343
}
13441344
return true;
13451345
}));
1346-
1347-
$access->userManager->expects($this->atLeastOnce())
1348-
->method('get')
1349-
->willReturn($this->createMock(User::class));
13501346
}
13511347

13521348
/**
@@ -1357,6 +1353,9 @@ public function testSetPasswordInvalid() {
13571353
$access = $this->getAccessMock();
13581354

13591355
$this->prepareAccessForSetPassword($access);
1356+
$access->userManager->expects($this->atLeastOnce())
1357+
->method('get')
1358+
->willReturn($this->createMock(User::class));
13601359
$backend = new UserLDAP($access, $this->createMock(IConfig::class), $this->createMock(INotificationManager::class), $this->createMock(Session::class), $this->getDefaultPluginManagerMock());
13611360
\OC_User::useBackend($backend);
13621361

core/Controller/LostController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ public function email($user){
224224
return new JSONResponse($this->error($this->l10n->t('Password reset is disabled')));
225225
}
226226

227+
\OCP\Util::emitHook(
228+
'\OCA\Files_Sharing\API\Server2Server',
229+
'preLoginNameUsedAsUserName',
230+
['uid' => &$user]
231+
);
232+
227233
// FIXME: use HTTP error codes
228234
try {
229235
$this->sendEmail($user);

lib/private/User/Manager.php

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

155-
if (method_exists($backend, 'loginName2UserName')) {
156-
$loginName = $backend->loginName2UserName($uid);
157-
if ($loginName !== false) {
158-
$uid = $loginName;
159-
}
160-
if (isset($this->cachedUsers[$uid])) {
161-
return $this->cachedUsers[$uid];
162-
}
163-
}
164-
165155
$user = new User($uid, $backend, $this, $this->config);
166156
if ($cacheUser) {
167157
$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
@@ -185,6 +185,8 @@ public function testGetOneBackendExists() {
185185
->method('userExists')
186186
->with($this->equalTo('foo'))
187187
->will($this->returnValue(true));
188+
$backend->expects($this->never())
189+
->method('loginName2UserName');
188190

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

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

221243
$manager = new \OC\User\Manager($this->config);
222244
$manager->registerBackend($backend);
@@ -236,6 +258,8 @@ public function testSearchTwoBackendLimitOffset() {
236258
->method('getUsers')
237259
->with($this->equalTo('fo'), $this->equalTo(3), $this->equalTo(1))
238260
->will($this->returnValue(array('foo1', 'foo2')));
261+
$backend1->expects($this->never())
262+
->method('loginName2UserName');
239263

240264
/**
241265
* @var \Test\Util\User\Dummy | \PHPUnit_Framework_MockObject_MockObject $backend2
@@ -245,6 +269,8 @@ public function testSearchTwoBackendLimitOffset() {
245269
->method('getUsers')
246270
->with($this->equalTo('fo'), $this->equalTo(3), $this->equalTo(1))
247271
->will($this->returnValue(array('foo3')));
272+
$backend2->expects($this->never())
273+
->method('loginName2UserName');
248274

249275
$manager = new \OC\User\Manager($this->config);
250276
$manager->registerBackend($backend1);
@@ -324,6 +350,8 @@ public function testCreateUserSingleBackendNotExists() {
324350
->method('userExists')
325351
->with($this->equalTo('foo'))
326352
->will($this->returnValue(false));
353+
$backend->expects($this->never())
354+
->method('loginName2UserName');
327355

328356
$manager = new \OC\User\Manager($this->config);
329357
$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
return false;
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)