Skip to content

Commit d2f3985

Browse files
authored
Merge pull request #63645 from nextcloud/backport/63635/stable34
[stable34] fix(dav): scope contact photo export to local address books
2 parents 40cd9a7 + a08f99e commit d2f3985

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

apps/dav/lib/CardDAV/ImageExportPlugin.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,16 @@ public function httpGet(RequestInterface $request, ResponseInterface $response)
7979
$addressbookpath = explode('/', $path);
8080
array_pop($addressbookpath);
8181
$addressbookpath = implode('/', $addressbookpath);
82-
/** @var AddressBook $addressbook */
8382
$addressbook = $this->server->tree->getNodeForPath($addressbookpath);
8483

8584
$response->setHeader('Cache-Control', 'private, max-age=3600, must-revalidate');
8685
$response->setHeader('Etag', $node->getETag());
8786

87+
if (!$addressbook instanceof AddressBook) {
88+
$response->setStatus(Http::STATUS_NO_CONTENT);
89+
return false;
90+
}
91+
8892
try {
8993
$file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node);
9094
$response->setHeader('Content-Type', $file->getMimeType());

apps/dav/tests/unit/CardDAV/ImageExportPluginTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use OCA\DAV\CardDAV\AddressBook;
1212
use OCA\DAV\CardDAV\ImageExportPlugin;
13+
use OCA\DAV\CardDAV\Integration\ExternalAddressBook;
1314
use OCA\DAV\CardDAV\PhotoCache;
1415
use OCP\AppFramework\Http;
1516
use OCP\Files\NotFoundException;
@@ -172,6 +173,39 @@ public function testCard(?int $size, bool $photo): void {
172173
$this->assertFalse($result);
173174
}
174175

176+
public function testAppGeneratedAddressBook(): void {
177+
$this->request->method('getQueryParameters')
178+
->willReturn(['photo' => null]);
179+
$this->request->method('getPath')
180+
->willReturn('user/book/card');
181+
182+
$card = $this->createMock(Card::class);
183+
$card->method('getETag')
184+
->willReturn('"myEtag"');
185+
$book = $this->createMock(ExternalAddressBook::class);
186+
187+
$this->tree->method('getNodeForPath')
188+
->willReturnCallback(function ($path) use ($card, $book) {
189+
if ($path === 'user/book/card') {
190+
return $card;
191+
} elseif ($path === 'user/book') {
192+
return $book;
193+
}
194+
$this->fail();
195+
});
196+
197+
$this->cache->expects($this->never())
198+
->method('get');
199+
$this->response->expects($this->once())
200+
->method('setStatus')
201+
->with(Http::STATUS_NO_CONTENT);
202+
$this->response->expects($this->never())
203+
->method('setBody');
204+
205+
$result = $this->plugin->httpGet($this->request, $this->response);
206+
$this->assertFalse($result);
207+
}
208+
175209
public function testCardWithSpecialCharactersInName(): void {
176210
$this->request->method('getQueryParameters')
177211
->willReturn(['photo' => null]);

0 commit comments

Comments
 (0)