Fix getting the avatar of a non-existing user
This commit is contained in:
parent
c546f0bf46
commit
8304f5f508
|
@ -101,11 +101,13 @@ class AvatarController extends Controller {
|
||||||
['Content-Type' => $image->mimeType()]);
|
['Content-Type' => $image->mimeType()]);
|
||||||
$resp->setETag(crc32($image->data()));
|
$resp->setETag(crc32($image->data()));
|
||||||
} else {
|
} else {
|
||||||
$resp = new DataResponse(
|
$user = $this->userManager->get($userId);
|
||||||
['data' => [
|
$userName = $user ? $user->getDisplayName() : '';
|
||||||
'displayname' => $this->userManager->get($userId)->getDisplayName()
|
$resp = new DataResponse([
|
||||||
]
|
'data' => [
|
||||||
]);
|
'displayname' => $userName,
|
||||||
|
],
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$resp->addHeader('Pragma', 'public');
|
$resp->addHeader('Pragma', 'public');
|
||||||
|
|
|
@ -74,7 +74,6 @@ class AvatarControllerTest extends \Test\TestCase {
|
||||||
$this->container['Request'] = $this->getMockBuilder('OCP\IRequest')
|
$this->container['Request'] = $this->getMockBuilder('OCP\IRequest')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
|
|
||||||
|
|
||||||
$this->avatarMock = $this->getMockBuilder('OCP\IAvatar')
|
$this->avatarMock = $this->getMockBuilder('OCP\IAvatar')
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$this->userMock = $this->getMockBuilder('OCP\IUser')
|
$this->userMock = $this->getMockBuilder('OCP\IUser')
|
||||||
|
@ -86,7 +85,7 @@ class AvatarControllerTest extends \Test\TestCase {
|
||||||
$this->oldUser = \OC_User::getUser();
|
$this->oldUser = \OC_User::getUser();
|
||||||
|
|
||||||
// Create a dummy user
|
// Create a dummy user
|
||||||
$this->user = \OC::$server->getSecureRandom()->getLowStrengthGenerator()->generate(12, ISecureRandom::CHAR_LOWER);
|
$this->user = $this->getUniqueID('user');
|
||||||
|
|
||||||
OC::$server->getUserManager()->createUser($this->user, $this->user);
|
OC::$server->getUserManager()->createUser($this->user, $this->user);
|
||||||
\OC_Util::tearDownFS();
|
\OC_Util::tearDownFS();
|
||||||
|
@ -102,7 +101,8 @@ class AvatarControllerTest extends \Test\TestCase {
|
||||||
// Configure userMock
|
// Configure userMock
|
||||||
$this->userMock->method('getDisplayName')->willReturn($this->user);
|
$this->userMock->method('getDisplayName')->willReturn($this->user);
|
||||||
$this->userMock->method('getUID')->willReturn($this->user);
|
$this->userMock->method('getUID')->willReturn($this->user);
|
||||||
$this->container['UserManager']->method('get')->willReturn($this->userMock);
|
$this->container['UserManager']->method('get')
|
||||||
|
->willReturnMap([[$this->user, $this->userMock]]);
|
||||||
$this->container['UserSession']->method('getUser')->willReturn($this->userMock);
|
$this->container['UserSession']->method('getUser')->willReturn($this->userMock);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ class AvatarControllerTest extends \Test\TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the users avatar
|
* Fetch the user's avatar
|
||||||
*/
|
*/
|
||||||
public function testGetAvatar() {
|
public function testGetAvatar() {
|
||||||
$image = new Image(OC::$SERVERROOT.'/tests/data/testimage.jpg');
|
$image = new Image(OC::$SERVERROOT.'/tests/data/testimage.jpg');
|
||||||
|
@ -150,6 +150,23 @@ class AvatarControllerTest extends \Test\TestCase {
|
||||||
$this->assertEquals(crc32($response->getData()), $response->getEtag());
|
$this->assertEquals(crc32($response->getData()), $response->getEtag());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the avatar of a non-existing user
|
||||||
|
*/
|
||||||
|
public function testGetAvatarNoUser() {
|
||||||
|
$image = new Image(OC::$SERVERROOT.'/tests/data/testimage.jpg');
|
||||||
|
$this->avatarMock->method('get')->willReturn($image);
|
||||||
|
$this->container['AvatarManager']->method('getAvatar')->willReturn($this->avatarMock);
|
||||||
|
|
||||||
|
$response = $this->avatarController->getAvatar($this->user . 'doesnotexist', 32);
|
||||||
|
|
||||||
|
$this->assertEquals($response->getStatus(), Http::STATUS_OK);
|
||||||
|
|
||||||
|
$image2 = new Image($response->getData());
|
||||||
|
$this->assertEquals($image->mimeType(), $image2->mimeType());
|
||||||
|
$this->assertEquals(crc32($response->getData()), $response->getEtag());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure we get the correct size
|
* Make sure we get the correct size
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue