diff --git a/apps/files/lib/Command/TransferOwnership.php b/apps/files/lib/Command/TransferOwnership.php
index 742948b7ac32755a990de930b9ce4aedbe163daf..3b51e4a9e6d5c4352f79c859a080f20902994e04 100644
--- a/apps/files/lib/Command/TransferOwnership.php
+++ b/apps/files/lib/Command/TransferOwnership.php
@@ -91,23 +91,21 @@ class TransferOwnership extends Command {
 	}
 
 	protected function execute(InputInterface $input, OutputInterface $output) {
-		$this->sourceUser = $input->getArgument('source-user');
-		$this->destinationUser = $input->getArgument('destination-user');
-		$source = $this->userManager->get($this->sourceUser);
-		$destination = $this->userManager->get($this->destinationUser);
+		$sourceUserObject = $this->userManager->get($input->getArgument('source-user'));
+		$destinationUserObject = $this->userManager->get($input->getArgument('destination-user'));
 
-		if (!$source instanceof IUser) {
+		if (!$sourceUserObject instanceof IUser) {
 			$output->writeln("<error>Unknown source user $this->sourceUser</error>");
 			return;
 		}
 
-		if (!$destination instanceof IUser) {
+		if (!$destinationUserObject instanceof IUser) {
 			$output->writeln("<error>Unknown destination user $this->destinationUser</error>");
 			return;
 		}
 
-		$this->sourceUser = $source->getUID();
-		$this->destinationUser = $destination->getUID();
+		$this->sourceUser = $sourceUserObject->getUID();
+		$this->destinationUser = $destinationUserObject->getUID();
 
 		// target user has to be ready
 		if (!\OC::$server->getEncryptionManager()->isReadyForUser($this->destinationUser)) {
diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php
index 113bb5a85c63f16993129e64549054b3610f1ad3..d2662af527a69b256f4cf339aca364a19a7e0687 100644
--- a/lib/private/Files/Filesystem.php
+++ b/lib/private/Files/Filesystem.php
@@ -394,9 +394,6 @@ class Filesystem {
 		if ($user === null || $user === false || $user === '') {
 			throw new \OC\User\NoUserException('Attempted to initialize mount points for null user and no user in session');
 		}
-		if (isset(self::$usersSetup[$user])) {
-			return;
-		}
 
 		$userManager = \OC::$server->getUserManager();
 		$userObject = $userManager->get($user);
@@ -406,6 +403,17 @@ class Filesystem {
 			throw new \OC\User\NoUserException('Backends provided no user object for ' . $user);
 		}
 
+		// workaround in case of different casings
+		if ($user !== $userObject->getUID()) {
+			$stack = json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 50));
+			\OCP\Util::writeLog('files', 'initMountPoints() called with wrong user casing. This could be a bug. Expected: "' . $userObject->getUID() . '" got "' . $user . '". Stack: ' . $stack, \OCP\Util::WARN);
+		}
+		$user = $userObject->getUID();
+
+		if (isset(self::$usersSetup[$user])) {
+			return;
+		}
+
 		self::$usersSetup[$user] = true;
 
 		/** @var \OC\Files\Config\MountProviderCollection $mountConfigManager */
diff --git a/lib/private/Files/Node/Root.php b/lib/private/Files/Node/Root.php
index 0cda2c8b822891c77fdef7468003e2ef4a8a847d..28438e8adbb3da3fcbde7f81091d9c4861238252 100644
--- a/lib/private/Files/Node/Root.php
+++ b/lib/private/Files/Node/Root.php
@@ -347,6 +347,15 @@ class Root extends Folder implements IRootFolder {
 	 * @return \OCP\Files\Folder
 	 */
 	public function getUserFolder($userId) {
+		$userObject = \OC::$server->getUserManager()->get($userId);
+
+		if (is_null($userObject)) {
+			\OCP\Util::writeLog('files', 'Backends provided no user object for ' . $userId, \OCP\Util::ERROR);
+			throw new \OC\User\NoUserException('Backends provided no user object for ' . $userId);
+		}
+
+		$userId = $userObject->getUID();
+
 		if (!$this->userFolderCache->hasKey($userId)) {
 			\OC\Files\Filesystem::initMountPoints($userId);
 
diff --git a/lib/private/Share/Share.php b/lib/private/Share/Share.php
index 33801cd634704e8561260b0a51cbc0b11ca2b1df..842dded067132e3d0490db01b5eea6b6bc0f9e12 100644
--- a/lib/private/Share/Share.php
+++ b/lib/private/Share/Share.php
@@ -136,6 +136,15 @@ class Share extends Constants {
 	 *       not '/admin/data/file.txt'
 	 */
 	public static function getUsersSharingFile($path, $ownerUser, $includeOwner = false, $returnUserPaths = false, $recursive = true) {
+		$userManager = \OC::$server->getUserManager();
+		$userObject = $userManager->get($ownerUser);
+
+		if (is_null($ownerUser)) {
+			\OCP\Util::writeLog('files', ' Backends provided no user object for ' . $ownerUser, \OCP\Util::ERROR);
+			throw new \OC\User\NoUserException('Backends provided no user object for ' . $ownerUser);
+		}
+
+		$ownerUser = $userObject->getUID();
 
 		Filesystem::initMountPoints($ownerUser);
 		$shares = $sharePaths = $fileTargets = array();
diff --git a/tests/lib/AvatarManagerTest.php b/tests/lib/AvatarManagerTest.php
index 8ccc51d12e0f60d03018edfe81b0a9fab23c65df..83a5cfd9b30ce06eb4348973370c55776ab24de2 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 210ce4edc69cac077c45e3edbafa2cc824129b59..fb9dee150518c766deb04dcac10e9646e46f3428 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 f42a42c42b103acf3be5de7cb20c281a7423eda0..35ba8a6c223c8b3b671cb20fffcfc23b28ef1fe5 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 61372d4ae90ccbc8f6b90aa30235661e8a82fabb..1ca896e09141acfdf11587f9c44e4388b7e5ea1e 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();
 	}