Skip to content

Commit

Permalink
Prevent double output of avatar image data
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Jan 12, 2018
1 parent fc9d06f commit 74b2998
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/dav/appinfo/v1/caldav.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

// Add plugins
$server->addPlugin(new MaintenancePlugin());
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend));
$server->addPlugin(new \Sabre\CalDAV\Plugin());

$server->addPlugin(new LegacyDAVACL());
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/appinfo/v1/carddav.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
$server->setBaseUri($baseuri);
// Add plugins
$server->addPlugin(new MaintenancePlugin());
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, 'ownCloud'));
$server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend));
$server->addPlugin(new Plugin());

$server->addPlugin(new LegacyDAVACL());
Expand Down
3 changes: 2 additions & 1 deletion apps/dav/lib/Avatars/AvatarNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ function get() {
ob_start();
if ($this->ext === 'png') {
imagepng($res);
} else {
imagejpeg($res);
}
imagejpeg($res);

return ob_get_clean();
}
Expand Down
9 changes: 5 additions & 4 deletions apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function __construct(IRequest $request, $baseUri) {
// with performance and locking issues because it will query
// every parent node which might trigger an implicit rescan in the
// case of external storages with update detection
if (!$this->requestIsForSubtree('files')) {
if (!$this->isRequestForSubtree('files')) {
// acl
$acl = new DavAclPlugin();
$acl->principalCollectionSet = [
Expand All @@ -136,7 +136,7 @@ public function __construct(IRequest $request, $baseUri) {
}

// calendar plugins
if ($this->requestIsForSubtree('calendars')) {
if ($this->isRequestForSubtree('calendars')) {
$mailer = \OC::$server->getMailer();
$this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin());
$this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin());
Expand All @@ -152,7 +152,8 @@ public function __construct(IRequest $request, $baseUri) {
}

// addressbook plugins
if ($this->requestIsForSubtree('addressbooks')) {
if ($this->isRequestForSubtree('addressbooks')) {
$this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest()));
$this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin());
$this->server->addPlugin(new VCFExportPlugin());
$this->server->addPlugin(new ImageExportPlugin(\OC::$server->getLogger()));
Expand Down Expand Up @@ -280,7 +281,7 @@ public function exec() {
* @param string $subTree
* @return bool
*/
private function requestIsForSubtree($subTree) {
private function isRequestForSubtree($subTree) {
$subTree = trim($subTree, " /");
return strpos($this->server->getRequestUri(), "$subTree/") === 0;
}
Expand Down
26 changes: 26 additions & 0 deletions apps/dav/tests/unit/Avatars/AvatarNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

use OCA\DAV\Avatars\AvatarNode;
use OCP\IAvatar;
use OCP\IImage;
use Test\TestCase;

class AvatarNodeTest extends TestCase {
Expand All @@ -45,4 +46,29 @@ public function testGetContentType() {
$n = new AvatarNode(1024, 'jpeg', $a);
$this->assertEquals('image/jpeg', $n->getContentType());
}

/**
* @dataProvider providesFormats
*/
public function testGetOperation($realImage, $mime, $imageFunction) {
$image = $this->createMock(IImage::class);
$image->expects($this->once())->method('resource')->willReturn($realImage);
/** @var IAvatar | \PHPUnit_Framework_MockObject_MockObject $a */
$a = $this->createMock(IAvatar::class);
$a->expects($this->once())->method('get')->with(1024)->willReturn($image);
$n = new AvatarNode(1024, $mime, $a);

ob_start();
$imageFunction($realImage);

$expected = ob_get_clean();
$this->assertEquals($expected, $n->get());
}

public function providesFormats() {
return [
'jpeg' => [imagecreatefromjpeg(\OC::$SERVERROOT . '/tests/data/testimage.jpg'), 'jpeg', 'imagejpeg'],
'png' => [imagecreatefrompng(\OC::$SERVERROOT . '/tests/data/testimage.png'), 'png', 'imagepng']
];
}
}

0 comments on commit 74b2998

Please sign in to comment.