diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-10-04 12:28:41 +0200 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-11-02 22:21:46 +0100 |
commit | f737426eca338dbc65db6210a09f3034d372701b (patch) | |
tree | 10fbeb022517900955aff8a69e571652ee48d073 /tests | |
parent | c1feae1684934bb52b1edaa67d33d01b377b875a (diff) | |
download | nextcloud-server-f737426eca338dbc65db6210a09f3034d372701b.tar.gz nextcloud-server-f737426eca338dbc65db6210a09f3034d372701b.zip |
Add using casing check/fix for initMountPoints
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/AvatarManagerTest.php | 26 | ||||
-rw-r--r-- | tests/lib/Files/FilesystemTest.php | 35 | ||||
-rw-r--r-- | tests/lib/Files/Node/RootTest.php | 57 | ||||
-rw-r--r-- | tests/lib/TestCase.php | 3 |
4 files changed, 119 insertions, 2 deletions
diff --git a/tests/lib/AvatarManagerTest.php b/tests/lib/AvatarManagerTest.php index 8ccc51d12e0..83a5cfd9b30 100644 --- a/tests/lib/AvatarManagerTest.php +++ b/tests/lib/AvatarManagerTest.php @@ -26,6 +26,7 @@ namespace Test; use OC\Avatar; use OC\AvatarManager; +use OC\Files\AppData\AppData; use OCP\Files\IAppData; use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IConfig; @@ -48,7 +49,7 @@ class AvatarManagerTest extends \Test\TestCase { private $logger; /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ private $config; - /** @var AvatarManager */ + /** @var AvatarManager | \PHPUnit_Framework_MockObject_MockObject */ private $avatarManager; public function setUp() { @@ -101,8 +102,29 @@ class AvatarManagerTest extends \Test\TestCase { ->with('valid-user') ->willReturn($folder); - $expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config);; + $expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config); $this->assertEquals($expected, $this->avatarManager->getAvatar('valid-user')); } + public function testGetAvatarValidUserDifferentCasing() { + $user = $this->createMock(IUser::class); + $this->userManager->expects($this->once()) + ->method('get') + ->with('vaLid-USER') + ->willReturn($user); + + $user->expects($this->once()) + ->method('getUID') + ->willReturn('valid-user'); + + $folder = $this->createMock(ISimpleFolder::class); + $this->appData + ->expects($this->once()) + ->method('getFolder') + ->with('valid-user') + ->willReturn($folder); + + $expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config); + $this->assertEquals($expected, $this->avatarManager->getAvatar('vaLid-USER')); + } } diff --git a/tests/lib/Files/FilesystemTest.php b/tests/lib/Files/FilesystemTest.php index 210ce4edc69..fb9dee15051 100644 --- a/tests/lib/Files/FilesystemTest.php +++ b/tests/lib/Files/FilesystemTest.php @@ -79,6 +79,7 @@ class FilesystemTest extends \Test\TestCase { protected function setUp() { parent::setUp(); + \OC_User::clearBackends(); $userBackend = new \Test\Util\User\Dummy(); $userBackend->createUser(self::TEST_FILESYSTEM_USER1, self::TEST_FILESYSTEM_USER1); $userBackend->createUser(self::TEST_FILESYSTEM_USER2, self::TEST_FILESYSTEM_USER2); @@ -93,6 +94,7 @@ class FilesystemTest extends \Test\TestCase { $this->logout(); $this->invokePrivate('\OC\Files\Filesystem', 'normalizedPathCache', [null]); + \OC_User::clearBackends(); parent::tearDown(); } @@ -368,6 +370,39 @@ class FilesystemTest extends \Test\TestCase { $this->assertEquals(2, $thrown); } + public function testUserNameCasing() { + $this->logout(); + $userId = $this->getUniqueID('user_'); + + \OC_User::clearBackends(); + // needed for loginName2UserName mapping + $userBackend = $this->getMock('\OC\User\Database'); + \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 */ diff --git a/tests/lib/Files/Node/RootTest.php b/tests/lib/Files/Node/RootTest.php index f42a42c42b1..35ba8a6c223 100644 --- a/tests/lib/Files/Node/RootTest.php +++ b/tests/lib/Files/Node/RootTest.php @@ -9,6 +9,8 @@ namespace Test\Files\Node; use OC\Files\FileInfo; +use OC\Files\Mount\Manager; +use OC\User\NoUserException; class RootTest extends \Test\TestCase { /** @var \OC\User\User */ @@ -125,4 +127,59 @@ class RootTest extends \Test\TestCase { $root->get('/bar/foo'); } + + public function testGetUserFolder() { + $this->logout(); + $manager = new Manager(); + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = new \OC\Files\View(); + + $user1 = $this->getUniqueID('user1_'); + $user2 = $this->getUniqueID('user2_'); + + \OC_User::clearBackends(); + // needed for loginName2UserName mapping + $userBackend = $this->getMock('\OC\User\Database'); + \OC::$server->getUserManager()->registerBackend($userBackend); + + $userBackend->expects($this->any()) + ->method('userExists') + ->will($this->returnValueMap([ + [$user1, true], + [$user2, true], + [strtoupper($user1), true], + [strtoupper($user2), true], + ])); + $userBackend->expects($this->any()) + ->method('loginName2UserName') + ->will($this->returnValueMap([ + [strtoupper($user1), $user1], + [$user1, $user1], + [strtoupper($user2), $user2], + [$user2, $user2], + ])); + + $this->loginAsUser($user1); + $root = new \OC\Files\Node\Root($manager, $view, null, $this->userMountCache); + + $folder = $root->getUserFolder($user1); + $this->assertEquals('/' . $user1 . '/files', $folder->getPath()); + + $folder = $root->getUserFolder($user2); + $this->assertEquals('/' . $user2 . '/files', $folder->getPath()); + + // case difference must not matter here + $folder = $root->getUserFolder(strtoupper($user2)); + $this->assertEquals('/' . $user2 . '/files', $folder->getPath()); + + $thrown = false; + try { + $folder = $root->getUserFolder($this->getUniqueID('unexist')); + } catch (NoUserException $e) { + $thrown = true; + } + $this->assertTrue($thrown); + } } diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php index 61372d4ae90..1ca896e0914 100644 --- a/tests/lib/TestCase.php +++ b/tests/lib/TestCase.php @@ -273,6 +273,9 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase { self::tearDownAfterClassCleanStrayHooks(); self::tearDownAfterClassCleanStrayLocks(); + \OC_User::clearBackends(); + \OC_User::useBackend('dummy'); + parent::tearDownAfterClass(); } |