Skip to content

Commit b47f326

Browse files
authored
Merge pull request #63635 from nextcloud/fix/dav-photo-export-local-addressbooks
fix(dav): scope contact photo export to local address books
2 parents 007294d + b9ae9a1 commit b47f326

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
@@ -80,12 +80,16 @@ public function httpGet(RequestInterface $request, ResponseInterface $response)
8080
$addressbookpath = explode('/', $path);
8181
array_pop($addressbookpath);
8282
$addressbookpath = implode('/', $addressbookpath);
83-
/** @var AddressBook $addressbook */
8483
$addressbook = $this->server->tree->getNodeForPath($addressbookpath);
8584

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

88+
if (!$addressbook instanceof AddressBook) {
89+
$response->setStatus(Http::STATUS_NO_CONTENT);
90+
return false;
91+
}
92+
8993
try {
9094
$file = $this->cache->get($addressbook->getResourceId(), $node->getName(), $size, $node);
9195
$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
@@ -11,6 +11,7 @@
1111

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

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

0 commit comments

Comments
 (0)