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 <213943+nickvergessen@users.noreply.github.com>2019-12-04 12:28:45 +0300
committerGitHub <noreply@github.com>2019-12-04 12:28:45 +0300
commit738e6bf07926f05791b4eb80d7e63d72f299cd5a (patch)
treee23cd7b7f5c060ebdccdb88931a33b4ecb476e11 /tests
parent7f80859ce46c25484b9a2a207f2ae26b123f3f5d (diff)
parent54eb27dab2e3b5fe7a91b0fc388ae52de311d660 (diff)
Merge pull request #17715 from nextcloud/fix/5456/respect_avatar_privacy
Honor avatar visibility settings
Diffstat (limited to 'tests')
-rw-r--r--tests/Core/Controller/AvatarControllerTest.php43
1 files changed, 42 insertions, 1 deletions
diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php
index 9135a6bc92f..284c82310a1 100644
--- a/tests/Core/Controller/AvatarControllerTest.php
+++ b/tests/Core/Controller/AvatarControllerTest.php
@@ -33,6 +33,9 @@ namespace Tests\Core\Controller;
use OC\AppFramework\Utility\TimeFactory;
use OC\Core\Controller\AvatarController;
+use OCP\Accounts\IAccount;
+use OCP\Accounts\IAccountManager;
+use OCP\Accounts\IAccountProperty;
use OCP\AppFramework\Http;
use OCP\Files\File;
use OCP\Files\IRootFolder;
@@ -46,6 +49,7 @@ use OCP\ILogger;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* Class AvatarControllerTest
@@ -78,6 +82,8 @@ class AvatarControllerTest extends \Test\TestCase {
private $request;
/** @var TimeFactory|\PHPUnit_Framework_MockObject_MockObject */
private $timeFactory;
+ /** @var IAccountManager|MockObject */
+ private $accountManager;
protected function setUp(): void {
parent::setUp();
@@ -92,6 +98,7 @@ class AvatarControllerTest extends \Test\TestCase {
$this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock();
$this->logger = $this->getMockBuilder(ILogger::class)->getMock();
$this->timeFactory = $this->getMockBuilder('OC\AppFramework\Utility\TimeFactory')->getMock();
+ $this->accountManager = $this->createMock(IAccountManager::class);
$this->avatarMock = $this->getMockBuilder('OCP\IAvatar')->getMock();
$this->userMock = $this->getMockBuilder(IUser::class)->getMock();
@@ -106,7 +113,8 @@ class AvatarControllerTest extends \Test\TestCase {
$this->rootFolder,
$this->logger,
'userid',
- $this->timeFactory
+ $this->timeFactory,
+ $this->accountManager
);
// Configure userMock
@@ -137,6 +145,39 @@ class AvatarControllerTest extends \Test\TestCase {
$this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus());
}
+ public function testAvatarNotPublic() {
+ $account = $this->createMock(IAccount::class);
+ $this->accountManager->method('getAccount')
+ ->with($this->userMock)
+ ->willReturn($account);
+
+ $property = $this->createMock(IAccountProperty::class);
+ $account->method('getProperty')
+ ->with(IAccountManager::PROPERTY_AVATAR)
+ ->willReturn($property);
+
+ $property->method('getScope')
+ ->willReturn(IAccountManager::VISIBILITY_PRIVATE);
+
+ $controller = new AvatarController(
+ 'core',
+ $this->request,
+ $this->avatarManager,
+ $this->cache,
+ $this->l,
+ $this->userManager,
+ $this->rootFolder,
+ $this->logger,
+ null,
+ $this->timeFactory,
+ $this->accountManager
+ );
+
+ $result = $controller->getAvatar('userId', 128);
+
+ $this->assertEquals(Http::STATUS_NOT_FOUND, $result->getStatus());
+ }
+
/**
* Fetch the user's avatar
*/