ShareControllerTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Björn Schießle <bjoern@schiessle.org>
  7. * @author Georg Ehrke <oc.list@georgehrke.com>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Robin Appelman <robin@icewind.nl>
  12. * @author Roeland Jago Douma <roeland@famdouma.nl>
  13. * @author Thomas Müller <thomas.mueller@tmit.eu>
  14. * @author Vincent Cloutier <vincent1cloutier@gmail.com>
  15. *
  16. * @license AGPL-3.0
  17. *
  18. * This code is free software: you can redistribute it and/or modify
  19. * it under the terms of the GNU Affero General Public License, version 3,
  20. * as published by the Free Software Foundation.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU Affero General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU Affero General Public License, version 3,
  28. * along with this program. If not, see <http://www.gnu.org/licenses/>
  29. *
  30. */
  31. namespace OCA\Files_Sharing\Tests\Controllers;
  32. use OC\Files\Filesystem;
  33. use OC\Files\Node\Folder;
  34. use OCA\FederatedFileSharing\FederatedShareProvider;
  35. use OCA\Files_Sharing\Controller\ShareController;
  36. use OCP\AppFramework\Http\DataResponse;
  37. use OCP\AppFramework\Http\Template\ExternalShareMenuAction;
  38. use OCP\AppFramework\Http\Template\LinkMenuAction;
  39. use OCP\AppFramework\Http\Template\PublicTemplateResponse;
  40. use OCP\AppFramework\Http\Template\SimpleMenuAction;
  41. use OCP\Constants;
  42. use OCP\Files\NotFoundException;
  43. use OCP\Files\Storage;
  44. use OCP\IConfig;
  45. use OCP\IL10N;
  46. use OCP\ILogger;
  47. use OCP\IPreview;
  48. use OCP\IRequest;
  49. use OCP\IUser;
  50. use OCP\Share\Exceptions\ShareNotFound;
  51. use OCP\ISession;
  52. use OCP\IUserManager;
  53. use OCP\Security\ISecureRandom;
  54. use OCP\IURLGenerator;
  55. use OCP\Share\IShare;
  56. use PHPUnit\Framework\MockObject\MockObject;
  57. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  58. /**
  59. * @group DB
  60. *
  61. * @package OCA\Files_Sharing\Controllers
  62. */
  63. class ShareControllerTest extends \Test\TestCase {
  64. /** @var string */
  65. private $user;
  66. /** @var string */
  67. private $oldUser;
  68. /** @var string */
  69. private $appName = 'files_sharing';
  70. /** @var ShareController */
  71. private $shareController;
  72. /** @var IURLGenerator | \PHPUnit_Framework_MockObject_MockObject */
  73. private $urlGenerator;
  74. /** @var ISession | \PHPUnit_Framework_MockObject_MockObject */
  75. private $session;
  76. /** @var \OCP\IPreview | \PHPUnit_Framework_MockObject_MockObject */
  77. private $previewManager;
  78. /** @var \OCP\IConfig | \PHPUnit_Framework_MockObject_MockObject */
  79. private $config;
  80. /** @var \OC\Share20\Manager | \PHPUnit_Framework_MockObject_MockObject */
  81. private $shareManager;
  82. /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */
  83. private $userManager;
  84. /** @var FederatedShareProvider | \PHPUnit_Framework_MockObject_MockObject */
  85. private $federatedShareProvider;
  86. /** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */
  87. private $eventDispatcher;
  88. /** @var IL10N */
  89. private $l10n;
  90. protected function setUp() {
  91. parent::setUp();
  92. $this->appName = 'files_sharing';
  93. $this->shareManager = $this->getMockBuilder('\OC\Share20\Manager')->disableOriginalConstructor()->getMock();
  94. $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
  95. $this->session = $this->getMockBuilder(ISession::class)->getMock();
  96. $this->previewManager = $this->getMockBuilder(IPreview::class)->getMock();
  97. $this->config = $this->getMockBuilder(IConfig::class)->getMock();
  98. $this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
  99. $this->federatedShareProvider = $this->getMockBuilder('OCA\FederatedFileSharing\FederatedShareProvider')
  100. ->disableOriginalConstructor()->getMock();
  101. $this->federatedShareProvider->expects($this->any())
  102. ->method('isOutgoingServer2serverShareEnabled')->willReturn(true);
  103. $this->federatedShareProvider->expects($this->any())
  104. ->method('isIncomingServer2serverShareEnabled')->willReturn(true);
  105. $this->eventDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
  106. $this->l10n = $this->createMock(IL10N::class);
  107. $this->shareController = new \OCA\Files_Sharing\Controller\ShareController(
  108. $this->appName,
  109. $this->getMockBuilder(IRequest::class)->getMock(),
  110. $this->config,
  111. $this->urlGenerator,
  112. $this->userManager,
  113. $this->getMockBuilder(ILogger::class)->getMock(),
  114. $this->getMockBuilder('\OCP\Activity\IManager')->getMock(),
  115. $this->shareManager,
  116. $this->session,
  117. $this->previewManager,
  118. $this->getMockBuilder('\OCP\Files\IRootFolder')->getMock(),
  119. $this->federatedShareProvider,
  120. $this->eventDispatcher,
  121. $this->l10n,
  122. $this->getMockBuilder('\OCP\Defaults')->getMock()
  123. );
  124. // Store current user
  125. $this->oldUser = \OC_User::getUser();
  126. // Create a dummy user
  127. $this->user = \OC::$server->getSecureRandom()->generate(12, ISecureRandom::CHAR_LOWER);
  128. \OC::$server->getUserManager()->createUser($this->user, $this->user);
  129. \OC_Util::tearDownFS();
  130. $this->loginAsUser($this->user);
  131. }
  132. protected function tearDown() {
  133. \OC_Util::tearDownFS();
  134. \OC_User::setUserId('');
  135. Filesystem::tearDown();
  136. $user = \OC::$server->getUserManager()->get($this->user);
  137. if ($user !== null) { $user->delete(); }
  138. \OC_User::setIncognitoMode(false);
  139. \OC::$server->getSession()->set('public_link_authenticated', '');
  140. // Set old user
  141. \OC_User::setUserId($this->oldUser);
  142. \OC_Util::setupFS($this->oldUser);
  143. parent::tearDown();
  144. }
  145. public function testShowShareInvalidToken() {
  146. $this->shareController->setToken('invalidtoken');
  147. $this->shareManager
  148. ->expects($this->once())
  149. ->method('getShareByToken')
  150. ->with('invalidtoken')
  151. ->will($this->throwException(new ShareNotFound()));
  152. $this->expectException(NotFoundException::class);
  153. // Test without a not existing token
  154. $this->shareController->showShare();
  155. }
  156. public function testShowShareNotAuthenticated() {
  157. $this->shareController->setToken('validtoken');
  158. $share = \OC::$server->getShareManager()->newShare();
  159. $share->setPassword('password');
  160. $this->shareManager
  161. ->expects($this->once())
  162. ->method('getShareByToken')
  163. ->with('validtoken')
  164. ->willReturn($share);
  165. $this->expectException(NotFoundException::class);
  166. // Test without a not existing token
  167. $this->shareController->showShare();
  168. }
  169. public function testShowShare() {
  170. $note = 'personal note';
  171. $this->shareController->setToken('token');
  172. $owner = $this->getMockBuilder(IUser::class)->getMock();
  173. $owner->method('getDisplayName')->willReturn('ownerDisplay');
  174. $owner->method('getUID')->willReturn('ownerUID');
  175. $file = $this->getMockBuilder('OCP\Files\File')->getMock();
  176. $file->method('getName')->willReturn('file1.txt');
  177. $file->method('getMimetype')->willReturn('text/plain');
  178. $file->method('getSize')->willReturn(33);
  179. $file->method('isReadable')->willReturn(true);
  180. $file->method('isShareable')->willReturn(true);
  181. $share = \OC::$server->getShareManager()->newShare();
  182. $share->setId(42);
  183. $share->setPassword('password')
  184. ->setShareOwner('ownerUID')
  185. ->setNode($file)
  186. ->setNote($note)
  187. ->setTarget('/file1.txt');
  188. $this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
  189. $this->session->method('get')->with('public_link_authenticated')->willReturn('42');
  190. $this->urlGenerator->expects($this->at(0))
  191. ->method('linkToRouteAbsolute')
  192. ->with('files_sharing.sharecontroller.downloadShare', ['token' => 'token'])
  193. ->willReturn('downloadURL');
  194. $this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
  195. $this->config->method('getSystemValue')
  196. ->willReturnMap(
  197. [
  198. ['max_filesize_animated_gifs_public_sharing', 10, 10],
  199. ['enable_previews', true, true],
  200. ['preview_max_x', 1024, 1024],
  201. ['preview_max_y', 1024, 1024],
  202. ]
  203. );
  204. $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
  205. $shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
  206. $this->shareManager
  207. ->expects($this->once())
  208. ->method('getShareByToken')
  209. ->with('token')
  210. ->willReturn($share);
  211. $this->config
  212. ->expects($this->once())
  213. ->method('getAppValue')
  214. ->with('core', 'shareapi_public_link_disclaimertext', null)
  215. ->willReturn('My disclaimer text');
  216. $this->userManager->method('get')->with('ownerUID')->willReturn($owner);
  217. $this->eventDispatcher->expects($this->once())
  218. ->method('dispatch')
  219. ->with('OCA\Files_Sharing::loadAdditionalScripts');
  220. $this->l10n->expects($this->any())
  221. ->method('t')
  222. ->will($this->returnCallback(function($text, $parameters) {
  223. return vsprintf($text, $parameters);
  224. }));
  225. $response = $this->shareController->showShare();
  226. $sharedTmplParams = array(
  227. 'displayName' => 'ownerDisplay',
  228. 'owner' => 'ownerUID',
  229. 'filename' => 'file1.txt',
  230. 'directory_path' => '/file1.txt',
  231. 'mimetype' => 'text/plain',
  232. 'dirToken' => 'token',
  233. 'sharingToken' => 'token',
  234. 'server2serversharing' => true,
  235. 'protected' => 'true',
  236. 'dir' => '',
  237. 'downloadURL' => 'downloadURL',
  238. 'fileSize' => '33 B',
  239. 'nonHumanFileSize' => 33,
  240. 'maxSizeAnimateGif' => 10,
  241. 'previewSupported' => true,
  242. 'previewEnabled' => true,
  243. 'previewMaxX' => 1024,
  244. 'previewMaxY' => 1024,
  245. 'hideFileList' => false,
  246. 'shareOwner' => 'ownerDisplay',
  247. 'disclaimer' => 'My disclaimer text',
  248. 'shareUrl' => null,
  249. 'previewImage' => null,
  250. 'previewURL' => 'downloadURL',
  251. 'note' => $note,
  252. 'hideDownload' => false,
  253. 'showgridview' => false
  254. );
  255. $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
  256. $csp->addAllowedFrameDomain('\'self\'');
  257. $expectedResponse = new PublicTemplateResponse($this->appName, 'public', $sharedTmplParams);
  258. $expectedResponse->setContentSecurityPolicy($csp);
  259. $expectedResponse->setHeaderTitle($sharedTmplParams['filename']);
  260. $expectedResponse->setHeaderDetails('shared by ' . $sharedTmplParams['displayName']);
  261. $expectedResponse->setHeaderActions([
  262. new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download-white', $sharedTmplParams['downloadURL'], 0),
  263. new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', $sharedTmplParams['downloadURL'], 10, $sharedTmplParams['fileSize']),
  264. new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', $sharedTmplParams['previewURL']),
  265. new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', $sharedTmplParams['owner'], $sharedTmplParams['displayName'], $sharedTmplParams['filename']),
  266. ]);
  267. $this->assertEquals($expectedResponse, $response);
  268. }
  269. public function testShowShareHideDownload() {
  270. $note = 'personal note';
  271. $this->shareController->setToken('token');
  272. $owner = $this->getMockBuilder(IUser::class)->getMock();
  273. $owner->method('getDisplayName')->willReturn('ownerDisplay');
  274. $owner->method('getUID')->willReturn('ownerUID');
  275. $file = $this->getMockBuilder('OCP\Files\File')->getMock();
  276. $file->method('getName')->willReturn('file1.txt');
  277. $file->method('getMimetype')->willReturn('text/plain');
  278. $file->method('getSize')->willReturn(33);
  279. $file->method('isReadable')->willReturn(true);
  280. $file->method('isShareable')->willReturn(true);
  281. $share = \OC::$server->getShareManager()->newShare();
  282. $share->setId(42);
  283. $share->setPassword('password')
  284. ->setShareOwner('ownerUID')
  285. ->setNode($file)
  286. ->setNote($note)
  287. ->setTarget('/file1.txt')
  288. ->setHideDownload(true);
  289. $this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
  290. $this->session->method('get')->with('public_link_authenticated')->willReturn('42');
  291. // Even if downloads are disabled the "downloadURL" parameter is
  292. // provided to the template, as it is needed to preview audio and GIF
  293. // files.
  294. $this->urlGenerator->expects($this->at(0))
  295. ->method('linkToRouteAbsolute')
  296. ->with('files_sharing.sharecontroller.downloadShare', ['token' => 'token'])
  297. ->willReturn('downloadURL');
  298. $this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
  299. $this->config->method('getSystemValue')
  300. ->willReturnMap(
  301. [
  302. ['max_filesize_animated_gifs_public_sharing', 10, 10],
  303. ['enable_previews', true, true],
  304. ['preview_max_x', 1024, 1024],
  305. ['preview_max_y', 1024, 1024],
  306. ]
  307. );
  308. $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
  309. $shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
  310. $this->shareManager
  311. ->expects($this->once())
  312. ->method('getShareByToken')
  313. ->with('token')
  314. ->willReturn($share);
  315. $this->config
  316. ->expects($this->once())
  317. ->method('getAppValue')
  318. ->with('core', 'shareapi_public_link_disclaimertext', null)
  319. ->willReturn('My disclaimer text');
  320. $this->userManager->method('get')->with('ownerUID')->willReturn($owner);
  321. $this->eventDispatcher->expects($this->once())
  322. ->method('dispatch')
  323. ->with('OCA\Files_Sharing::loadAdditionalScripts');
  324. $this->l10n->expects($this->any())
  325. ->method('t')
  326. ->will($this->returnCallback(function($text, $parameters) {
  327. return vsprintf($text, $parameters);
  328. }));
  329. $response = $this->shareController->showShare();
  330. $sharedTmplParams = array(
  331. 'displayName' => 'ownerDisplay',
  332. 'owner' => 'ownerUID',
  333. 'filename' => 'file1.txt',
  334. 'directory_path' => '/file1.txt',
  335. 'mimetype' => 'text/plain',
  336. 'dirToken' => 'token',
  337. 'sharingToken' => 'token',
  338. 'server2serversharing' => true,
  339. 'protected' => 'true',
  340. 'dir' => '',
  341. 'downloadURL' => 'downloadURL',
  342. 'fileSize' => '33 B',
  343. 'nonHumanFileSize' => 33,
  344. 'maxSizeAnimateGif' => 10,
  345. 'previewSupported' => true,
  346. 'previewEnabled' => true,
  347. 'previewMaxX' => 1024,
  348. 'previewMaxY' => 1024,
  349. 'hideFileList' => false,
  350. 'shareOwner' => 'ownerDisplay',
  351. 'disclaimer' => 'My disclaimer text',
  352. 'shareUrl' => null,
  353. 'previewImage' => null,
  354. 'previewURL' => 'downloadURL',
  355. 'note' => $note,
  356. 'hideDownload' => true,
  357. 'showgridview' => false
  358. );
  359. $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
  360. $csp->addAllowedFrameDomain('\'self\'');
  361. $expectedResponse = new PublicTemplateResponse($this->appName, 'public', $sharedTmplParams);
  362. $expectedResponse->setContentSecurityPolicy($csp);
  363. $expectedResponse->setHeaderTitle($sharedTmplParams['filename']);
  364. $expectedResponse->setHeaderDetails('shared by ' . $sharedTmplParams['displayName']);
  365. $expectedResponse->setHeaderActions([]);
  366. $this->assertEquals($expectedResponse, $response);
  367. }
  368. /**
  369. * Checks file drop shares:
  370. * - there must not be any header action
  371. * - the template param "hideFileList" should be true
  372. *
  373. * @test
  374. * @return void
  375. */
  376. public function testShareFileDrop() {
  377. $this->shareController->setToken('token');
  378. $owner = $this->getMockBuilder(IUser::class)->getMock();
  379. $owner->method('getDisplayName')->willReturn('ownerDisplay');
  380. $owner->method('getUID')->willReturn('ownerUID');
  381. /* @var MockObject|Storage $storage */
  382. $storage = $this->getMockBuilder(Storage::class)
  383. ->disableOriginalConstructor()
  384. ->getMock();
  385. /* @var MockObject|Folder $folder */
  386. $folder = $this->getMockBuilder(Folder::class)
  387. ->disableOriginalConstructor()
  388. ->getMock();
  389. $folder->method('getName')->willReturn('/fileDrop');
  390. $folder->method('isReadable')->willReturn(true);
  391. $folder->method('isShareable')->willReturn(true);
  392. $folder->method('getStorage')->willReturn($storage);
  393. $folder->method('get')->with('')->willReturn($folder);
  394. $folder->method('getSize')->willReturn(1337);
  395. $share = \OC::$server->getShareManager()->newShare();
  396. $share->setId(42);
  397. $share->setPermissions(Constants::PERMISSION_CREATE)
  398. ->setShareOwner('ownerUID')
  399. ->setNode($folder)
  400. ->setTarget('/fileDrop');
  401. $this->shareManager
  402. ->expects($this->once())
  403. ->method('getShareByToken')
  404. ->with('token')
  405. ->willReturn($share);
  406. $this->userManager->method('get')->with('ownerUID')->willReturn($owner);
  407. $this->l10n->expects($this->any())
  408. ->method('t')
  409. ->will($this->returnCallback(function($text, $parameters) {
  410. return vsprintf($text, $parameters);
  411. }));
  412. $response = $this->shareController->showShare();
  413. // skip the "folder" param for tests
  414. $responseParams = $response->getParams();
  415. unset($responseParams['folder']);
  416. $response->setParams($responseParams);
  417. $sharedTmplParams = array(
  418. 'displayName' => 'ownerDisplay',
  419. 'owner' => 'ownerUID',
  420. 'filename' => '/fileDrop',
  421. 'directory_path' => '/fileDrop',
  422. 'mimetype' => null,
  423. 'dirToken' => 'token',
  424. 'sharingToken' => 'token',
  425. 'server2serversharing' => true,
  426. 'protected' => 'false',
  427. 'dir' => null,
  428. 'downloadURL' => '',
  429. 'fileSize' => '1 KB',
  430. 'nonHumanFileSize' => 1337,
  431. 'maxSizeAnimateGif' => null,
  432. 'previewSupported' => null,
  433. 'previewEnabled' => null,
  434. 'previewMaxX' => null,
  435. 'previewMaxY' => null,
  436. 'hideFileList' => true,
  437. 'shareOwner' => 'ownerDisplay',
  438. 'disclaimer' => null,
  439. 'shareUrl' => '',
  440. 'previewImage' => '',
  441. 'previewURL' => '',
  442. 'note' => '',
  443. 'hideDownload' => false,
  444. 'showgridview' => false
  445. );
  446. $csp = new \OCP\AppFramework\Http\ContentSecurityPolicy();
  447. $csp->addAllowedFrameDomain('\'self\'');
  448. $expectedResponse = new PublicTemplateResponse($this->appName, 'public', $sharedTmplParams);
  449. $expectedResponse->setContentSecurityPolicy($csp);
  450. $expectedResponse->setHeaderTitle($sharedTmplParams['filename']);
  451. $expectedResponse->setHeaderDetails('shared by ' . $sharedTmplParams['displayName']);
  452. self::assertEquals($expectedResponse, $response);
  453. }
  454. /**
  455. * @expectedException \OCP\Files\NotFoundException
  456. */
  457. public function testShowShareInvalid() {
  458. $this->shareController->setToken('token');
  459. $owner = $this->getMockBuilder(IUser::class)->getMock();
  460. $owner->method('getDisplayName')->willReturn('ownerDisplay');
  461. $owner->method('getUID')->willReturn('ownerUID');
  462. $file = $this->getMockBuilder('OCP\Files\File')->getMock();
  463. $file->method('getName')->willReturn('file1.txt');
  464. $file->method('getMimetype')->willReturn('text/plain');
  465. $file->method('getSize')->willReturn(33);
  466. $file->method('isShareable')->willReturn(false);
  467. $file->method('isReadable')->willReturn(true);
  468. $share = \OC::$server->getShareManager()->newShare();
  469. $share->setId(42);
  470. $share->setPassword('password')
  471. ->setShareOwner('ownerUID')
  472. ->setNode($file)
  473. ->setTarget('/file1.txt');
  474. $this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
  475. $this->session->method('get')->with('public_link_authenticated')->willReturn('42');
  476. $this->previewManager->method('isMimeSupported')->with('text/plain')->willReturn(true);
  477. $this->config->method('getSystemValue')
  478. ->willReturnMap(
  479. [
  480. ['max_filesize_animated_gifs_public_sharing', 10, 10],
  481. ['enable_previews', true, true],
  482. ]
  483. );
  484. $shareTmpl['maxSizeAnimateGif'] = $this->config->getSystemValue('max_filesize_animated_gifs_public_sharing', 10);
  485. $shareTmpl['previewEnabled'] = $this->config->getSystemValue('enable_previews', true);
  486. $this->shareManager
  487. ->expects($this->once())
  488. ->method('getShareByToken')
  489. ->with('token')
  490. ->willReturn($share);
  491. $this->userManager->method('get')->with('ownerUID')->willReturn($owner);
  492. $this->shareController->showShare();
  493. }
  494. public function testDownloadShareWithCreateOnlyShare() {
  495. $share = $this->getMockBuilder(IShare::class)->getMock();
  496. $share->method('getPassword')->willReturn('password');
  497. $share
  498. ->expects($this->once())
  499. ->method('getPermissions')
  500. ->willReturn(\OCP\Constants::PERMISSION_CREATE);
  501. $this->shareManager
  502. ->expects($this->once())
  503. ->method('getShareByToken')
  504. ->with('validtoken')
  505. ->willReturn($share);
  506. // Test with a password protected share and no authentication
  507. $response = $this->shareController->downloadShare('validtoken');
  508. $expectedResponse = new DataResponse('Share is read-only');
  509. $this->assertEquals($expectedResponse, $response);
  510. }
  511. }