summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2015-08-29 18:05:32 +0200
committerMorris Jobke <hey@morrisjobke.de>2015-08-29 18:05:32 +0200
commit90dfa981c58a58ad7625e42bc0dce9bcf46dc74f (patch)
treefae17c58a0f12dc7c62b607beabea34ed7f0ac28
parent723f8c8f1ba8c9859ec2d46515dc06e7236f89c0 (diff)
parentae62537adf19e4c83bf4ed336d2a21e931f6d330 (diff)
downloadnextcloud-server-90dfa981c58a58ad7625e42bc0dce9bcf46dc74f.tar.gz
nextcloud-server-90dfa981c58a58ad7625e42bc0dce9bcf46dc74f.zip
Merge pull request #14856 from rullzer/remote_avatars
Allow Remote avatars
-rw-r--r--core/avatar/avatarcontroller.php6
-rw-r--r--tests/core/avatar/avatarcontrollertest.php29
2 files changed, 22 insertions, 13 deletions
diff --git a/core/avatar/avatarcontroller.php b/core/avatar/avatarcontroller.php
index 945e022600a..0c270bee53e 100644
--- a/core/avatar/avatarcontroller.php
+++ b/core/avatar/avatarcontroller.php
@@ -90,14 +90,18 @@ class AvatarController extends Controller {
}
/**
- * @NoAdminRequired
* @NoCSRFRequired
+ * @PublicPage
*
* @param string $userId
* @param int $size
* @return DataResponse|DataDisplayResponse
*/
public function getAvatar($userId, $size) {
+ if (!$this->userManager->userExists($userId)) {
+ return new DataResponse([], Http::STATUS_NOT_FOUND);
+ }
+
if ($size > 2048) {
$size = 2048;
} elseif ($size <= 0) {
diff --git a/tests/core/avatar/avatarcontrollertest.php b/tests/core/avatar/avatarcontrollertest.php
index e8fb977fae1..9accd5181c6 100644
--- a/tests/core/avatar/avatarcontrollertest.php
+++ b/tests/core/avatar/avatarcontrollertest.php
@@ -96,8 +96,12 @@ class AvatarControllerTest extends \Test\TestCase {
// Configure userMock
$this->userMock->method('getDisplayName')->willReturn($this->user);
$this->userMock->method('getUID')->willReturn($this->user);
- $this->container['UserManager']->method('get')
+ $this->container['UserManager']
+ ->method('get')
->willReturnMap([[$this->user, $this->userMock]]);
+ $this->container['UserManager']
+ ->method('userExists')
+ ->willReturnMap([[$this->user, true]]);
$this->container['UserSession']->method('getUser')->willReturn($this->userMock);
}
@@ -120,11 +124,10 @@ class AvatarControllerTest extends \Test\TestCase {
* Fetch an avatar if a user has no avatar
*/
public function testGetAvatarNoAvatar() {
- $this->container['AvatarManager']->method('getAvatar')->willReturn($this->avatarMock);
+ $this->container['UserManager']->expects($this->once())->method('userExists');
+ $this->container['AvatarManager']->expects($this->once())->method('getAvatar')->willReturn($this->avatarMock);
$response = $this->avatarController->getAvatar($this->user, 32);
- //Comment out until JS is fixed
- //$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
$this->assertEquals(Http::STATUS_OK, $response->getStatus());
$this->assertEquals($this->user, $response->getData()['data']['displayname']);
}
@@ -133,9 +136,11 @@ class AvatarControllerTest extends \Test\TestCase {
* Fetch the user's avatar
*/
public function testGetAvatar() {
+ $this->container['UserManager']->expects($this->once())->method('userExists');
+
$image = new Image(OC::$SERVERROOT.'/tests/data/testimage.jpg');
- $this->avatarMock->method('get')->willReturn($image);
- $this->container['AvatarManager']->method('getAvatar')->willReturn($this->avatarMock);
+ $this->avatarMock->expects($this->once())->method('get')->willReturn($image);
+ $this->container['AvatarManager']->expects($this->once())->method('getAvatar')->willReturn($this->avatarMock);
$response = $this->avatarController->getAvatar($this->user, 32);
@@ -150,21 +155,19 @@ class AvatarControllerTest extends \Test\TestCase {
* Fetch the avatar of a non-existing user
*/
public function testGetAvatarNoUser() {
- $this->avatarMock->method('get')->willReturn(null);
- $this->container['AvatarManager']->method('getAvatar')->willReturn($this->avatarMock);
-
+ $this->container['UserManager']->expects($this->once())->method('userExists');
$response = $this->avatarController->getAvatar($this->user . 'doesnotexist', 32);
//Comment out until JS is fixed
- //$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
- $this->assertEquals(Http::STATUS_OK, $response->getStatus());
- $this->assertEquals('', $response->getData()['data']['displayname']);
+ $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
+ $this->assertEquals([], $response->getData());
}
/**
* Make sure we get the correct size
*/
public function testGetAvatarSize() {
+ $this->container['UserManager']->expects($this->once())->method('userExists');
$this->avatarMock->expects($this->once())
->method('get')
->with($this->equalTo(32));
@@ -178,6 +181,7 @@ class AvatarControllerTest extends \Test\TestCase {
* We cannot get avatars that are 0 or negative
*/
public function testGetAvatarSizeMin() {
+ $this->container['UserManager']->expects($this->once())->method('userExists');
$this->avatarMock->expects($this->once())
->method('get')
->with($this->equalTo(64));
@@ -191,6 +195,7 @@ class AvatarControllerTest extends \Test\TestCase {
* We do not support avatars larger than 2048*2048
*/
public function testGetAvatarSizeMax() {
+ $this->container['UserManager']->expects($this->once())->method('userExists');
$this->avatarMock->expects($this->once())
->method('get')
->with($this->equalTo(2048));