Merge pull request #1595 from nextcloud/fix-avatar-username

Use proper casing of username in avatar filesystem setup
This commit is contained in:
Morris Jobke 2016-10-03 17:07:32 +02:00 committed by GitHub
commit 657c8da811
2 changed files with 67 additions and 19 deletions

View File

@ -92,11 +92,19 @@ class AvatarManager implements IAvatarManager {
throw new \Exception('user does not exist'); throw new \Exception('user does not exist');
} }
// sanitize userID - fixes casing issue (needed for the filesystem stuff that is done below)
$userId = $user->getUID();
/* /*
* Fix for #22119 * Fix for #22119
* Basically we do not want to copy the skeleton folder * Basically we do not want to copy the skeleton folder.
*
* For unit test purposes this is ignored when run in PHPUnit.
*/ */
\OC\Files\Filesystem::initMountPoints($userId); if(!defined('PHPUNIT_RUN')) {
\OC\Files\Filesystem::initMountPoints($userId);
}
$dir = '/' . $userId; $dir = '/' . $userId;
/** @var Folder $folder */ /** @var Folder $folder */
$folder = $this->rootFolder->get($dir); $folder = $this->rootFolder->get($dir);

View File

@ -1,8 +1,11 @@
<?php <?php
/** /**
* @author Roeland Jago Douma <rullzer@owncloud.com> * @author Roeland Jago Douma <rullzer@owncloud.com>
* @author Lukas Reschke <lukas@statuscode.ch>
* *
* @copyright Copyright (c) 2015, ownCloud, Inc. * @copyright Copyright (c) 2015, ownCloud, Inc.
* @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
*
* @license AGPL-3.0 * @license AGPL-3.0
* *
* This code is free software: you can redistribute it and/or modify * This code is free software: you can redistribute it and/or modify
@ -21,33 +24,49 @@
namespace Test; namespace Test;
use OC\Avatar;
use OC\AvatarManager; use OC\AvatarManager;
use Test\Traits\UserTrait; use OCP\Files\Folder;
use Test\Traits\MountProviderTrait; use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IUser;
use OCP\IUserManager;
/** /**
* Class AvatarManagerTest * Class AvatarManagerTest
* @group DB
*/ */
class AvatarManagerTest extends \Test\TestCase { class AvatarManagerTest extends \Test\TestCase {
use UserTrait; /** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
use MountProviderTrait; private $userManager;
/** @var IRootFolder|\PHPUnit_Framework_MockObject_MockObject */
private $rootFolder;
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
private $l10n;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
private $logger;
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
private $config;
/** @var AvatarManager */ /** @var AvatarManager */
private $avatarManager; private $avatarManager;
/** @var \OC\Files\Storage\Temporary */
private $storage;
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->createUser('valid-user', 'valid-user'); $this->userManager = $this->createMock(IUserManager::class);
$this->rootFolder = $this->createMock(IRootFolder::class);
$this->l10n = $this->createMock(IL10N::class);
$this->logger = $this->createMock(ILogger::class);
$this->config = $this->createMock(IConfig::class);
$this->storage = new \OC\Files\Storage\Temporary(); $this->avatarManager = new AvatarManager(
$this->registerMount('valid-user', $this->storage, '/valid-user/'); $this->userManager,
$this->rootFolder,
$this->avatarManager = \OC::$server->getAvatarManager(); $this->l10n,
$this->logger,
$this->config
);
} }
/** /**
@ -55,14 +74,35 @@ class AvatarManagerTest extends \Test\TestCase {
* @expectedExceptionMessage user does not exist * @expectedExceptionMessage user does not exist
*/ */
public function testGetAvatarInvalidUser() { public function testGetAvatarInvalidUser() {
$this->userManager
->expects($this->once())
->method('get')
->with('invalidUser')
->willReturn(null);
$this->avatarManager->getAvatar('invalidUser'); $this->avatarManager->getAvatar('invalidUser');
} }
public function testGetAvatarValidUser() { public function testGetAvatarValidUser() {
$avatar = $this->avatarManager->getAvatar('valid-user'); $user = $this->createMock(IUser::class);
$user
->expects($this->once())
->method('getUID')
->willReturn('valid-user');
$this->userManager
->expects($this->once())
->method('get')
->with('valid-user')
->willReturn($user);
$folder = $this->createMock(Folder::class);
$this->rootFolder
->expects($this->once())
->method('get')
->with('/valid-user')
->willReturn($folder);
$this->assertInstanceOf('\OCP\IAvatar', $avatar); $expected = new Avatar($folder, $this->l10n, $user, $this->logger, $this->config);;
$this->assertFalse($this->storage->file_exists('files')); $this->assertEquals($expected, $this->avatarManager->getAvatar('valid-user'));
} }
} }