Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-02-04 14:12:48 +0300
committerJoas Schilling <coding@schilljs.com>2022-02-07 18:47:51 +0300
commit6dd60b6d304648acf542a84ba76ad5fc0b693b43 (patch)
tree74a9ab5e9f0c9a212211b417320f3453e10b5647 /tests
parenteb340734192e44acc3e4e80442fe54371431ad12 (diff)
Only allow avatars in 64 and 512 pixel size
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Core/Controller/AvatarControllerTest.php62
-rw-r--r--tests/Core/Controller/GuestAvatarControllerTest.php2
2 files changed, 52 insertions, 12 deletions
diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php
index 35d89c24a45..8d3cd73a656 100644
--- a/tests/Core/Controller/AvatarControllerTest.php
+++ b/tests/Core/Controller/AvatarControllerTest.php
@@ -193,46 +193,86 @@ class AvatarControllerTest extends \Test\TestCase {
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
}
+ public function testGetAvatarSize64(): void {
+ $this->avatarMock->expects($this->once())
+ ->method('getFile')
+ ->with($this->equalTo(64))
+ ->willReturn($this->avatarFile);
+
+ $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
+
+ $this->logger->expects($this->never())
+ ->method('debug');
+
+ $this->avatarController->getAvatar('userId', 64);
+ }
+
+ public function testGetAvatarSize512(): void {
+ $this->avatarMock->expects($this->once())
+ ->method('getFile')
+ ->with($this->equalTo(512))
+ ->willReturn($this->avatarFile);
+
+ $this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
+
+ $this->logger->expects($this->never())
+ ->method('debug');
+
+ $this->avatarController->getAvatar('userId', 512);
+ }
+
/**
- * Make sure we get the correct size
+ * Small sizes return 64 and generate a log
*/
- public function testGetAvatarSize() {
+ public function testGetAvatarSizeTooSmall(): void {
$this->avatarMock->expects($this->once())
->method('getFile')
- ->with($this->equalTo(32))
+ ->with($this->equalTo(64))
->willReturn($this->avatarFile);
$this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
+ $this->logger->expects($this->once())
+ ->method('debug')
+ ->with('Avatar requested in deprecated size 32');
+
$this->avatarController->getAvatar('userId', 32);
}
/**
- * We cannot get avatars that are 0 or negative
+ * Avatars between 64 and 512 are upgraded to 512
*/
- public function testGetAvatarSizeMin() {
+ public function testGetAvatarSizeBetween(): void {
$this->avatarMock->expects($this->once())
->method('getFile')
- ->with($this->equalTo(64))
+ ->with($this->equalTo(512))
->willReturn($this->avatarFile);
$this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
- $this->avatarController->getAvatar('userId', 0);
+ $this->logger->expects($this->once())
+ ->method('debug')
+ ->with('Avatar requested in deprecated size 65');
+
+ $this->avatarController->getAvatar('userId', 65);
}
/**
- * We do not support avatars larger than 2048*2048
+ * We do not support avatars larger than 512
*/
- public function testGetAvatarSizeMax() {
+ public function testGetAvatarSizeTooBig(): void {
$this->avatarMock->expects($this->once())
->method('getFile')
- ->with($this->equalTo(2048))
+ ->with($this->equalTo(512))
->willReturn($this->avatarFile);
$this->avatarManager->method('getAvatar')->willReturn($this->avatarMock);
- $this->avatarController->getAvatar('userId', 2049);
+ $this->logger->expects($this->once())
+ ->method('debug')
+ ->with('Avatar requested in deprecated size 513');
+
+ $this->avatarController->getAvatar('userId', 513);
}
/**
diff --git a/tests/Core/Controller/GuestAvatarControllerTest.php b/tests/Core/Controller/GuestAvatarControllerTest.php
index e14a5416c49..b5682d2d716 100644
--- a/tests/Core/Controller/GuestAvatarControllerTest.php
+++ b/tests/Core/Controller/GuestAvatarControllerTest.php
@@ -77,7 +77,7 @@ class GuestAvatarControllerTest extends \Test\TestCase {
$this->avatar->expects($this->once())
->method('getFile')
- ->with(128)
+ ->with(512)
->willReturn($this->file);
$this->file->method('getMimeType')