1
0

CacheTest.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  9. * @author Morris Jobke <hey@morrisjobke.de>
  10. * @author Robin Appelman <robin@icewind.nl>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. * @author Vincent Petry <vincent@nextcloud.com>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. namespace OCA\Files_Sharing\Tests;
  31. use OC\Files\Storage\Temporary;
  32. use OC\Files\Storage\Wrapper\Jail;
  33. use OCA\Files_Sharing\SharedStorage;
  34. use OCP\Share\IShare;
  35. /**
  36. * Class CacheTest
  37. *
  38. * @group DB
  39. */
  40. class CacheTest extends TestCase {
  41. /**
  42. * @var \OC\Files\View
  43. */
  44. public $user2View;
  45. /** @var \OC\Files\Cache\Cache */
  46. protected $ownerCache;
  47. /** @var \OC\Files\Cache\Cache */
  48. protected $sharedCache;
  49. /** @var \OC\Files\Storage\Storage */
  50. protected $ownerStorage;
  51. /** @var \OC\Files\Storage\Storage */
  52. protected $sharedStorage;
  53. /** @var \OCP\Share\IManager */
  54. protected $shareManager;
  55. protected function setUp(): void {
  56. parent::setUp();
  57. $this->shareManager = \OC::$server->getShareManager();
  58. $userManager = \OC::$server->getUserManager();
  59. $userManager->get(self::TEST_FILES_SHARING_API_USER1)->setDisplayName('User One');
  60. $userManager->get(self::TEST_FILES_SHARING_API_USER2)->setDisplayName('User Two');
  61. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  62. $this->user2View = new \OC\Files\View('/'. self::TEST_FILES_SHARING_API_USER2 . '/files');
  63. // prepare user1's dir structure
  64. $this->view->mkdir('container');
  65. $this->view->mkdir('container/shareddir');
  66. $this->view->mkdir('container/shareddir/subdir');
  67. $this->view->mkdir('container/shareddir/emptydir');
  68. $textData = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  69. $this->view->file_put_contents('container/not shared.txt', $textData);
  70. $this->view->file_put_contents('container/shared single file.txt', $textData);
  71. $this->view->file_put_contents('container/shareddir/bar.txt', $textData);
  72. $this->view->file_put_contents('container/shareddir/subdir/another.txt', $textData);
  73. $this->view->file_put_contents('container/shareddir/subdir/another too.txt', $textData);
  74. $this->view->file_put_contents('container/shareddir/subdir/not a text file.xml', '<xml></xml>');
  75. $this->view->file_put_contents('simplefile.txt', $textData);
  76. [$this->ownerStorage,] = $this->view->resolvePath('');
  77. $this->ownerCache = $this->ownerStorage->getCache();
  78. $this->ownerStorage->getScanner()->scan('');
  79. // share "shareddir" with user2
  80. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  81. $node = $rootFolder->get('container/shareddir');
  82. $share = $this->shareManager->newShare();
  83. $share->setNode($node)
  84. ->setShareType(IShare::TYPE_USER)
  85. ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
  86. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  87. ->setPermissions(\OCP\Constants::PERMISSION_ALL);
  88. $share = $this->shareManager->createShare($share);
  89. $share->setStatus(IShare::STATUS_ACCEPTED);
  90. $this->shareManager->updateShare($share);
  91. $node = $rootFolder->get('container/shared single file.txt');
  92. $share = $this->shareManager->newShare();
  93. $share->setNode($node)
  94. ->setShareType(IShare::TYPE_USER)
  95. ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
  96. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  97. ->setPermissions(\OCP\Constants::PERMISSION_ALL & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE));
  98. $share = $this->shareManager->createShare($share);
  99. $share->setStatus(IShare::STATUS_ACCEPTED);
  100. $this->shareManager->updateShare($share);
  101. // login as user2
  102. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  103. // retrieve the shared storage
  104. $secondView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
  105. [$this->sharedStorage,] = $secondView->resolvePath('files/shareddir');
  106. $this->sharedCache = $this->sharedStorage->getCache();
  107. }
  108. protected function tearDown(): void {
  109. if ($this->sharedCache) {
  110. $this->sharedCache->clear();
  111. }
  112. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  113. $shares = $this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER);
  114. foreach ($shares as $share) {
  115. $this->shareManager->deleteShare($share);
  116. }
  117. $this->view->deleteAll('container');
  118. $this->ownerCache->clear();
  119. parent::tearDown();
  120. }
  121. public function searchDataProvider() {
  122. return [
  123. ['%another%',
  124. [
  125. ['name' => 'another too.txt', 'path' => 'subdir/another too.txt'],
  126. ['name' => 'another.txt', 'path' => 'subdir/another.txt'],
  127. ]
  128. ],
  129. ['%Another%',
  130. [
  131. ['name' => 'another too.txt', 'path' => 'subdir/another too.txt'],
  132. ['name' => 'another.txt', 'path' => 'subdir/another.txt'],
  133. ]
  134. ],
  135. ['%dir%',
  136. [
  137. ['name' => 'emptydir', 'path' => 'emptydir'],
  138. ['name' => 'subdir', 'path' => 'subdir'],
  139. ['name' => 'shareddir', 'path' => ''],
  140. ]
  141. ],
  142. ['%Dir%',
  143. [
  144. ['name' => 'emptydir', 'path' => 'emptydir'],
  145. ['name' => 'subdir', 'path' => 'subdir'],
  146. ['name' => 'shareddir', 'path' => ''],
  147. ]
  148. ],
  149. ['%txt%',
  150. [
  151. ['name' => 'bar.txt', 'path' => 'bar.txt'],
  152. ['name' => 'another too.txt', 'path' => 'subdir/another too.txt'],
  153. ['name' => 'another.txt', 'path' => 'subdir/another.txt'],
  154. ]
  155. ],
  156. ['%Txt%',
  157. [
  158. ['name' => 'bar.txt', 'path' => 'bar.txt'],
  159. ['name' => 'another too.txt', 'path' => 'subdir/another too.txt'],
  160. ['name' => 'another.txt', 'path' => 'subdir/another.txt'],
  161. ]
  162. ],
  163. ['%',
  164. [
  165. ['name' => 'bar.txt', 'path' => 'bar.txt'],
  166. ['name' => 'emptydir', 'path' => 'emptydir'],
  167. ['name' => 'subdir', 'path' => 'subdir'],
  168. ['name' => 'another too.txt', 'path' => 'subdir/another too.txt'],
  169. ['name' => 'another.txt', 'path' => 'subdir/another.txt'],
  170. ['name' => 'not a text file.xml', 'path' => 'subdir/not a text file.xml'],
  171. ['name' => 'shareddir', 'path' => ''],
  172. ]
  173. ],
  174. ['%nonexistent%',
  175. [
  176. ]
  177. ],
  178. ];
  179. }
  180. /**
  181. * we cannot use a dataProvider because that would cause the stray hook detection to remove the hooks
  182. * that were added in setUpBeforeClass.
  183. */
  184. public function testSearch() {
  185. foreach ($this->searchDataProvider() as $data) {
  186. [$pattern, $expectedFiles] = $data;
  187. $results = $this->sharedStorage->getCache()->search($pattern);
  188. $this->verifyFiles($expectedFiles, $results);
  189. }
  190. }
  191. /**
  192. * Test searching by mime type
  193. */
  194. public function testSearchByMime() {
  195. $results = $this->sharedStorage->getCache()->searchByMime('text');
  196. $check = [
  197. [
  198. 'name' => 'bar.txt',
  199. 'path' => 'bar.txt'
  200. ],
  201. [
  202. 'name' => 'another too.txt',
  203. 'path' => 'subdir/another too.txt'
  204. ],
  205. [
  206. 'name' => 'another.txt',
  207. 'path' => 'subdir/another.txt'
  208. ],
  209. ];
  210. $this->verifyFiles($check, $results);
  211. }
  212. public function testGetFolderContentsInRoot() {
  213. $results = $this->user2View->getDirectoryContent('/');
  214. $results = (array_filter($results, function ($file) {
  215. return $file->getName() !== 'welcome.txt';
  216. }));
  217. // we should get the shared items "shareddir" and "shared single file.txt"
  218. // additional root will always contain the example file "welcome.txt",
  219. // so this will be part of the result
  220. $this->verifyFiles(
  221. [
  222. [
  223. 'name' => 'shareddir',
  224. 'path' => 'files/shareddir',
  225. 'mimetype' => 'httpd/unix-directory',
  226. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  227. 'displayname_owner' => 'User One',
  228. ],
  229. [
  230. 'name' => 'shared single file.txt',
  231. 'path' => 'files/shared single file.txt',
  232. 'mimetype' => 'text/plain',
  233. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  234. 'displayname_owner' => 'User One',
  235. ],
  236. ],
  237. $results
  238. );
  239. }
  240. public function testGetFolderContentsInSubdir() {
  241. $results = $this->user2View->getDirectoryContent('/shareddir');
  242. $this->verifyFiles(
  243. [
  244. [
  245. 'name' => 'bar.txt',
  246. 'path' => 'bar.txt',
  247. 'mimetype' => 'text/plain',
  248. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  249. 'displayname_owner' => 'User One',
  250. ],
  251. [
  252. 'name' => 'emptydir',
  253. 'path' => 'emptydir',
  254. 'mimetype' => 'httpd/unix-directory',
  255. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  256. 'displayname_owner' => 'User One',
  257. ],
  258. [
  259. 'name' => 'subdir',
  260. 'path' => 'subdir',
  261. 'mimetype' => 'httpd/unix-directory',
  262. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  263. 'displayname_owner' => 'User One',
  264. ],
  265. ],
  266. $results
  267. );
  268. }
  269. /**
  270. * This covers a bug where the share owners name was propagated
  271. * to the recipient in the recent files API response where the
  272. * share recipient has a different target set
  273. *
  274. * https://github.com/nextcloud/server/issues/39879
  275. */
  276. public function testShareRenameOriginalFileInRecentResults() {
  277. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  278. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  279. $node = $rootFolder->get('simplefile.txt');
  280. $share = $this->shareManager->newShare();
  281. $share->setNode($node)
  282. ->setShareType(IShare::TYPE_USER)
  283. ->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
  284. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  285. ->setPermissions(\OCP\Constants::PERMISSION_READ);
  286. $share = $this->shareManager->createShare($share);
  287. $share->setStatus(IShare::STATUS_ACCEPTED);
  288. $this->shareManager->updateShare($share);
  289. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  290. $node->move(self::TEST_FILES_SHARING_API_USER1 . '/files/simplefile2.txt');
  291. self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
  292. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER3);
  293. $recents = $rootFolder->getRecent(10);
  294. self::assertEquals([
  295. 'welcome.txt',
  296. 'simplefile.txt'
  297. ], array_map(function ($node) {
  298. return $node->getFileInfo()['name'];
  299. }, $recents));
  300. }
  301. public function testGetFolderContentsWhenSubSubdirShared() {
  302. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  303. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  304. $node = $rootFolder->get('container/shareddir/subdir');
  305. $share = $this->shareManager->newShare();
  306. $share->setNode($node)
  307. ->setShareType(IShare::TYPE_USER)
  308. ->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
  309. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  310. ->setPermissions(\OCP\Constants::PERMISSION_ALL);
  311. $share = $this->shareManager->createShare($share);
  312. $share->setStatus(IShare::STATUS_ACCEPTED);
  313. $this->shareManager->updateShare($share);
  314. self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
  315. $thirdView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
  316. $results = $thirdView->getDirectoryContent('/subdir');
  317. $this->verifyFiles(
  318. [
  319. [
  320. 'name' => 'another too.txt',
  321. 'path' => 'another too.txt',
  322. 'mimetype' => 'text/plain',
  323. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  324. 'displayname_owner' => 'User One',
  325. ],
  326. [
  327. 'name' => 'another.txt',
  328. 'path' => 'another.txt',
  329. 'mimetype' => 'text/plain',
  330. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  331. 'displayname_owner' => 'User One',
  332. ],
  333. [
  334. 'name' => 'not a text file.xml',
  335. 'path' => 'not a text file.xml',
  336. 'mimetype' => 'application/xml',
  337. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  338. 'displayname_owner' => 'User One',
  339. ],
  340. ],
  341. $results
  342. );
  343. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  344. $this->shareManager->deleteShare($share);
  345. }
  346. /**
  347. * Check if 'results' contains the expected 'examples' only.
  348. *
  349. * @param array $examples array of example files
  350. * @param array $results array of files
  351. */
  352. private function verifyFiles($examples, $results) {
  353. $this->assertEquals(count($examples), count($results));
  354. foreach ($examples as $example) {
  355. foreach ($results as $key => $result) {
  356. if ($result['name'] === $example['name']) {
  357. $this->verifyKeys($example, $result);
  358. unset($results[$key]);
  359. break;
  360. }
  361. }
  362. }
  363. $this->assertEquals([], $results);
  364. }
  365. /**
  366. * verify if each value from the result matches the expected result
  367. * @param array $example array with the expected results
  368. * @param array $result array with the results
  369. */
  370. private function verifyKeys($example, $result) {
  371. foreach ($example as $key => $value) {
  372. $this->assertEquals($value, $result[$key]);
  373. }
  374. }
  375. public function testGetPathByIdDirectShare() {
  376. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  377. \OC\Files\Filesystem::file_put_contents('test.txt', 'foo');
  378. $info = \OC\Files\Filesystem::getFileInfo('test.txt');
  379. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  380. $node = $rootFolder->get('test.txt');
  381. $share = $this->shareManager->newShare();
  382. $share->setNode($node)
  383. ->setShareType(IShare::TYPE_USER)
  384. ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
  385. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  386. ->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
  387. $share = $this->shareManager->createShare($share);
  388. $share->setStatus(IShare::STATUS_ACCEPTED);
  389. $this->shareManager->updateShare($share);
  390. \OC_Util::tearDownFS();
  391. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  392. $this->assertTrue(\OC\Files\Filesystem::file_exists('/test.txt'));
  393. [$sharedStorage] = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/test.txt');
  394. /**
  395. * @var \OCA\Files_Sharing\SharedStorage $sharedStorage
  396. */
  397. $sharedCache = $sharedStorage->getCache();
  398. $this->assertEquals('', $sharedCache->getPathById($info->getId()));
  399. }
  400. public function testGetPathByIdShareSubFolder() {
  401. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  402. \OC\Files\Filesystem::mkdir('foo');
  403. \OC\Files\Filesystem::mkdir('foo/bar');
  404. \OC\Files\Filesystem::touch('foo/bar/test.txt');
  405. $folderInfo = \OC\Files\Filesystem::getFileInfo('foo');
  406. $fileInfo = \OC\Files\Filesystem::getFileInfo('foo/bar/test.txt');
  407. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  408. $node = $rootFolder->get('foo');
  409. $share = $this->shareManager->newShare();
  410. $share->setNode($node)
  411. ->setShareType(IShare::TYPE_USER)
  412. ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
  413. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  414. ->setPermissions(\OCP\Constants::PERMISSION_ALL);
  415. $share = $this->shareManager->createShare($share);
  416. $share->setStatus(IShare::STATUS_ACCEPTED);
  417. $this->shareManager->updateShare($share);
  418. \OC_Util::tearDownFS();
  419. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  420. $this->assertTrue(\OC\Files\Filesystem::file_exists('/foo'));
  421. [$sharedStorage] = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/foo');
  422. /**
  423. * @var \OCA\Files_Sharing\SharedStorage $sharedStorage
  424. */
  425. $sharedCache = $sharedStorage->getCache();
  426. $this->assertEquals('', $sharedCache->getPathById($folderInfo->getId()));
  427. $this->assertEquals('bar/test.txt', $sharedCache->getPathById($fileInfo->getId()));
  428. }
  429. public function testNumericStorageId() {
  430. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  431. \OC\Files\Filesystem::mkdir('foo');
  432. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  433. $node = $rootFolder->get('foo');
  434. $share = $this->shareManager->newShare();
  435. $share->setNode($node)
  436. ->setShareType(IShare::TYPE_USER)
  437. ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
  438. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  439. ->setPermissions(\OCP\Constants::PERMISSION_ALL);
  440. $share = $this->shareManager->createShare($share);
  441. $share->setStatus(IShare::STATUS_ACCEPTED);
  442. $this->shareManager->updateShare($share);
  443. \OC_Util::tearDownFS();
  444. [$sourceStorage] = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/foo');
  445. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  446. $this->assertTrue(\OC\Files\Filesystem::file_exists('/foo'));
  447. /** @var SharedStorage $sharedStorage */
  448. [$sharedStorage] = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/foo');
  449. $this->assertEquals($sourceStorage->getCache()->getNumericStorageId(), $sharedStorage->getCache()->getNumericStorageId());
  450. }
  451. public function testShareJailedStorage() {
  452. $sourceStorage = new Temporary();
  453. $sourceStorage->mkdir('jail');
  454. $sourceStorage->mkdir('jail/sub');
  455. $sourceStorage->file_put_contents('jail/sub/foo.txt', 'foo');
  456. $jailedSource = new Jail([
  457. 'storage' => $sourceStorage,
  458. 'root' => 'jail'
  459. ]);
  460. $sourceStorage->getScanner()->scan('');
  461. $this->registerMount(self::TEST_FILES_SHARING_API_USER1, $jailedSource, '/' . self::TEST_FILES_SHARING_API_USER1 . '/files/foo');
  462. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  463. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  464. $node = $rootFolder->get('foo/sub');
  465. $share = $this->shareManager->newShare();
  466. $share->setNode($node)
  467. ->setShareType(IShare::TYPE_USER)
  468. ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
  469. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  470. ->setPermissions(\OCP\Constants::PERMISSION_ALL);
  471. $share = $this->shareManager->createShare($share);
  472. $share->setStatus(IShare::STATUS_ACCEPTED);
  473. $this->shareManager->updateShare($share);
  474. \OC_Util::tearDownFS();
  475. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  476. $this->assertEquals('foo', \OC\Files\Filesystem::file_get_contents('/sub/foo.txt'));
  477. \OC\Files\Filesystem::file_put_contents('/sub/bar.txt', 'bar');
  478. /** @var SharedStorage $sharedStorage */
  479. [$sharedStorage] = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub');
  480. $this->assertTrue($sharedStorage->getCache()->inCache('bar.txt'));
  481. $this->assertTrue($sourceStorage->getCache()->inCache('jail/sub/bar.txt'));
  482. }
  483. public function testSearchShareJailedStorage() {
  484. $sourceStorage = new Temporary();
  485. $sourceStorage->mkdir('jail');
  486. $sourceStorage->mkdir('jail/sub');
  487. $sourceStorage->file_put_contents('jail/sub/foo.txt', 'foo');
  488. $jailedSource = new Jail([
  489. 'storage' => $sourceStorage,
  490. 'root' => 'jail'
  491. ]);
  492. $sourceStorage->getScanner()->scan('');
  493. $this->registerMount(self::TEST_FILES_SHARING_API_USER1, $jailedSource, '/' . self::TEST_FILES_SHARING_API_USER1 . '/files/foo');
  494. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  495. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  496. $node = $rootFolder->get('foo/sub');
  497. $share = $this->shareManager->newShare();
  498. $share->setNode($node)
  499. ->setShareType(IShare::TYPE_USER)
  500. ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
  501. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  502. ->setPermissions(\OCP\Constants::PERMISSION_ALL);
  503. $share = $this->shareManager->createShare($share);
  504. $share->setStatus(IShare::STATUS_ACCEPTED);
  505. $this->shareManager->updateShare($share);
  506. \OC_Util::tearDownFS();
  507. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  508. /** @var SharedStorage $sharedStorage */
  509. [$sharedStorage] = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub');
  510. $results = $sharedStorage->getCache()->search("foo.txt");
  511. $this->assertCount(1, $results);
  512. }
  513. }