diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2016-10-21 21:32:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-21 21:32:10 +0200 |
commit | 4db595181d4a6e26dd5511317a87183815892e2f (patch) | |
tree | 375acbb2528c07532b1d9b6c2eae0a96aeb23f62 /tests | |
parent | 08804b851e1b50ae11fb4083976ff92ddfb0a8ee (diff) | |
parent | 116d17be86fd59a2178040d2fa328b20a6f24501 (diff) | |
download | nextcloud-server-4db595181d4a6e26dd5511317a87183815892e2f.tar.gz nextcloud-server-4db595181d4a6e26dd5511317a87183815892e2f.zip |
Merge pull request #1847 from nextcloud/backport-1164-avatar-files-accesscontrol-fixes
[stable10] Avatar fixes for access-control app
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Controller/AvatarControllerTest.php | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php index d45d0618230..272666deaf9 100644 --- a/tests/Core/Controller/AvatarControllerTest.php +++ b/tests/Core/Controller/AvatarControllerTest.php @@ -36,9 +36,9 @@ use OCP\AppFramework\IAppContainer; use OCP\AppFramework\Http; use OCP\Files\File; use OCP\Files\NotFoundException; -use OCP\IUser; +use OCP\Files\NotPermittedException; use OCP\IAvatar; -use Punic\Exception; +use OCP\IUser; use Test\Traits\UserTrait; /** @@ -314,7 +314,13 @@ class AvatarControllerTest extends \Test\TestCase { //Mock node API call $file = $this->getMockBuilder('OCP\Files\File') ->disableOriginalConstructor()->getMock(); - $file->method('getContent')->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg')); + + $file->expects($this->once()) + ->method('getContent') + ->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg')); + $file->expects($this->once()) + ->method('getMimeType') + ->willReturn('image/jpeg'); $this->container['UserFolder']->method('get')->willReturn($file); //Create request return @@ -341,6 +347,36 @@ class AvatarControllerTest extends \Test\TestCase { $this->assertEquals(['data' => ['message' => 'Please select a file.']], $response->getData()); } + public function testPostAvatarInvalidType() { + $file = $this->getMockBuilder('OCP\Files\File') + ->disableOriginalConstructor()->getMock(); + $file->expects($this->never()) + ->method('getContent'); + $file->expects($this->exactly(2)) + ->method('getMimeType') + ->willReturn('text/plain'); + $this->container['UserFolder']->method('get')->willReturn($file); + + $expectedResponse = new Http\JSONResponse(['data' => ['message' => 'The selected file is not an image.']], Http::STATUS_BAD_REQUEST); + $this->assertEquals($expectedResponse, $this->avatarController->postAvatar('avatar.jpg')); + } + + public function testPostAvatarNotPermittedException() { + $file = $this->getMockBuilder('OCP\Files\File') + ->disableOriginalConstructor()->getMock(); + $file->expects($this->once()) + ->method('getContent') + ->willThrowException(new NotPermittedException()); + $file->expects($this->once()) + ->method('getMimeType') + ->willReturn('image/jpeg'); + $userFolder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); + $this->container['UserFolder']->method('get')->willReturn($file); + + $expectedResponse = new Http\JSONResponse(['data' => ['message' => 'The selected file cannot be read.']], Http::STATUS_BAD_REQUEST); + $this->assertEquals($expectedResponse, $this->avatarController->postAvatar('avatar.jpg')); + } + /** * Test what happens if the upload of the avatar fails */ @@ -350,7 +386,13 @@ class AvatarControllerTest extends \Test\TestCase { ->will($this->throwException(new \Exception("foo"))); $file = $this->getMockBuilder('OCP\Files\File') ->disableOriginalConstructor()->getMock(); - $file->method('getContent')->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg')); + + $file->expects($this->once()) + ->method('getContent') + ->willReturn(file_get_contents(\OC::$SERVERROOT.'/tests/data/testimage.jpg')); + $file->expects($this->once()) + ->method('getMimeType') + ->willReturn('image/jpeg'); $this->container['UserFolder']->method('get')->willReturn($file); $this->container['Logger']->expects($this->once()) |