2015-04-15 16:31:30 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-10-26 15:54:55 +03:00
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2016-07-21 19:13:36 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-04-15 16:31:30 +03:00
|
|
|
* @author Vincent Petry <pvince81@owncloud.com>
|
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-04-15 16:31:30 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-05-17 12:42:03 +03:00
|
|
|
namespace OCA\Files_Sharing\Tests;
|
2015-04-15 16:31:30 +03:00
|
|
|
|
|
|
|
use OC\Files\Filesystem;
|
|
|
|
use OC\Files\View;
|
2020-06-24 17:49:16 +03:00
|
|
|
use OCP\Share\IShare;
|
2015-04-15 16:31:30 +03:00
|
|
|
|
2015-11-03 03:52:41 +03:00
|
|
|
/**
|
2016-05-17 12:42:03 +03:00
|
|
|
* Class EtagPropagationTest
|
2015-11-03 03:52:41 +03:00
|
|
|
*
|
2016-09-29 01:53:53 +03:00
|
|
|
* @group SLOWDB
|
2015-11-03 03:52:41 +03:00
|
|
|
*
|
2016-05-17 12:42:03 +03:00
|
|
|
* @package OCA\Files_Sharing\Tests
|
2015-11-03 03:52:41 +03:00
|
|
|
*/
|
2016-05-17 12:42:03 +03:00
|
|
|
class EtagPropagationTest extends PropagationTestCase {
|
2015-04-23 19:24:46 +03:00
|
|
|
|
2015-04-15 16:31:30 +03:00
|
|
|
/**
|
|
|
|
* "user1" is the admin who shares a folder "sub1/sub2/folder" with "user2" and "user3"
|
|
|
|
* "user2" receives the folder and puts it in "sub1/sub2/folder"
|
|
|
|
* "user3" receives the folder and puts it in "sub1/sub2/folder"
|
|
|
|
* "user2" reshares the subdir "sub1/sub2/folder/inside" with "user4"
|
|
|
|
* "user4" puts the received "inside" folder into "sub1/sub2/inside" (this is to check if it propagates across multiple subfolders)
|
|
|
|
*/
|
2015-12-10 15:36:43 +03:00
|
|
|
protected function setUpShares() {
|
2015-04-15 16:31:30 +03:00
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER1] = [];
|
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER2] = [];
|
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER3] = [];
|
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER4] = [];
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$rootFolder = \OC::$server->getRootFolder();
|
|
|
|
$shareManager = \OC::$server->getShareManager();
|
|
|
|
|
2015-04-15 16:31:30 +03:00
|
|
|
$this->rootView = new View('');
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
$view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
|
|
|
|
$view1->mkdir('/sub1/sub2/folder/inside');
|
|
|
|
$view1->mkdir('/directReshare');
|
|
|
|
$view1->mkdir('/sub1/sub2/folder/other');
|
2015-06-23 15:31:41 +03:00
|
|
|
$view1->file_put_contents('/foo.txt', 'foobar');
|
2015-04-15 16:31:30 +03:00
|
|
|
$view1->file_put_contents('/sub1/sub2/folder/file.txt', 'foobar');
|
|
|
|
$view1->file_put_contents('/sub1/sub2/folder/inside/file.txt', 'foobar');
|
|
|
|
$folderInfo = $view1->getFileInfo('/sub1/sub2/folder');
|
2015-09-28 17:38:01 +03:00
|
|
|
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
|
2015-06-23 15:31:41 +03:00
|
|
|
$fileInfo = $view1->getFileInfo('/foo.txt');
|
2015-09-28 17:38:01 +03:00
|
|
|
$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);
|
2016-04-15 10:02:17 +03:00
|
|
|
|
|
|
|
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1)
|
|
|
|
->get('/foo.txt');
|
|
|
|
$share = $shareManager->newShare();
|
|
|
|
$share->setNode($node)
|
2020-06-24 17:49:16 +03:00
|
|
|
->setShareType(IShare::TYPE_USER)
|
2016-04-15 10:02:17 +03:00
|
|
|
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
|
|
|
|
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
|
|
|
->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
|
2019-11-19 18:09:26 +03:00
|
|
|
$share = $shareManager->createShare($share);
|
|
|
|
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2);
|
2016-04-15 10:02:17 +03:00
|
|
|
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1)
|
|
|
|
->get('/sub1/sub2/folder');
|
2019-11-19 18:09:26 +03:00
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$share = $shareManager->newShare();
|
|
|
|
$share->setNode($node)
|
2020-06-24 17:49:16 +03:00
|
|
|
->setShareType(IShare::TYPE_USER)
|
2016-04-15 10:02:17 +03:00
|
|
|
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
|
|
|
|
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
|
|
|
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
2019-11-19 18:09:26 +03:00
|
|
|
$share = $shareManager->createShare($share);
|
|
|
|
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$share = $shareManager->newShare();
|
|
|
|
$share->setNode($node)
|
2020-06-24 17:49:16 +03:00
|
|
|
->setShareType(IShare::TYPE_USER)
|
2016-04-15 10:02:17 +03:00
|
|
|
->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
|
|
|
|
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
|
|
|
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
2019-11-19 18:09:26 +03:00
|
|
|
$share = $shareManager->createShare($share);
|
|
|
|
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER3);
|
2016-04-15 10:02:17 +03:00
|
|
|
|
2015-04-15 16:31:30 +03:00
|
|
|
$folderInfo = $view1->getFileInfo('/directReshare');
|
2015-09-28 17:38:01 +03:00
|
|
|
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
|
2016-04-15 10:02:17 +03:00
|
|
|
|
|
|
|
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1)
|
|
|
|
->get('/directReshare');
|
|
|
|
$share = $shareManager->newShare();
|
|
|
|
$share->setNode($node)
|
2020-06-24 17:49:16 +03:00
|
|
|
->setShareType(IShare::TYPE_USER)
|
2016-04-15 10:02:17 +03:00
|
|
|
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
|
|
|
|
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
|
|
|
|
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
2019-11-19 18:09:26 +03:00
|
|
|
$share = $shareManager->createShare($share);
|
|
|
|
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2);
|
2016-04-15 10:02:17 +03:00
|
|
|
|
2015-04-15 16:31:30 +03:00
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId();
|
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER1]['sub1'] = $view1->getFileInfo('sub1')->getId();
|
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER1]['sub1/sub2'] = $view1->getFileInfo('sub1/sub2')->getId();
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
/*
|
|
|
|
* User 2
|
|
|
|
*/
|
2015-04-15 16:31:30 +03:00
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
$view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
|
|
|
|
$view2->mkdir('/sub1/sub2');
|
|
|
|
$view2->rename('/folder', '/sub1/sub2/folder');
|
2020-07-08 16:32:11 +03:00
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
|
2015-04-15 16:31:30 +03:00
|
|
|
$insideInfo = $view2->getFileInfo('/sub1/sub2/folder/inside');
|
2015-09-28 17:38:01 +03:00
|
|
|
$this->assertInstanceOf('\OC\Files\FileInfo', $insideInfo);
|
2016-04-15 10:02:17 +03:00
|
|
|
|
|
|
|
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER2)
|
|
|
|
->get('/sub1/sub2/folder/inside');
|
|
|
|
$share = $shareManager->newShare();
|
|
|
|
$share->setNode($node)
|
2020-06-24 17:49:16 +03:00
|
|
|
->setShareType(IShare::TYPE_USER)
|
2016-04-15 10:02:17 +03:00
|
|
|
->setSharedWith(self::TEST_FILES_SHARING_API_USER4)
|
|
|
|
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
|
|
|
|
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
2019-11-19 18:09:26 +03:00
|
|
|
$share = $shareManager->createShare($share);
|
|
|
|
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER4);
|
2016-04-15 10:02:17 +03:00
|
|
|
|
2015-04-15 16:31:30 +03:00
|
|
|
$folderInfo = $view2->getFileInfo('/directReshare');
|
2015-09-28 17:38:01 +03:00
|
|
|
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
|
2016-04-15 10:02:17 +03:00
|
|
|
|
|
|
|
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER2)
|
|
|
|
->get('/directReshare');
|
|
|
|
$share = $shareManager->newShare();
|
|
|
|
$share->setNode($node)
|
2020-06-24 17:49:16 +03:00
|
|
|
->setShareType(IShare::TYPE_USER)
|
2016-04-15 10:02:17 +03:00
|
|
|
->setSharedWith(self::TEST_FILES_SHARING_API_USER4)
|
|
|
|
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
|
|
|
|
->setPermissions(\OCP\Constants::PERMISSION_ALL);
|
2019-11-19 18:09:26 +03:00
|
|
|
$share = $shareManager->createShare($share);
|
|
|
|
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER4);
|
2016-04-15 10:02:17 +03:00
|
|
|
|
2015-04-15 16:31:30 +03:00
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId();
|
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER2]['sub1'] = $view2->getFileInfo('sub1')->getId();
|
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER2]['sub1/sub2'] = $view2->getFileInfo('sub1/sub2')->getId();
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
/*
|
|
|
|
* User 3
|
|
|
|
*/
|
2015-04-15 16:31:30 +03:00
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER3);
|
|
|
|
$view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
|
|
|
|
$view3->mkdir('/sub1/sub2');
|
|
|
|
$view3->rename('/folder', '/sub1/sub2/folder');
|
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER3][''] = $view3->getFileInfo('')->getId();
|
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER3]['sub1'] = $view3->getFileInfo('sub1')->getId();
|
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER3]['sub1/sub2'] = $view3->getFileInfo('sub1/sub2')->getId();
|
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
/*
|
|
|
|
* User 4
|
|
|
|
*/
|
2015-04-15 16:31:30 +03:00
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
|
|
|
|
$view4 = new View('/' . self::TEST_FILES_SHARING_API_USER4 . '/files');
|
|
|
|
$view4->mkdir('/sub1/sub2');
|
|
|
|
$view4->rename('/inside', '/sub1/sub2/inside');
|
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER4][''] = $view4->getFileInfo('')->getId();
|
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER4]['sub1'] = $view4->getFileInfo('sub1')->getId();
|
|
|
|
$this->fileIds[self::TEST_FILES_SHARING_API_USER4]['sub1/sub2'] = $view4->getFileInfo('sub1/sub2')->getId();
|
|
|
|
|
|
|
|
foreach ($this->fileIds as $user => $ids) {
|
|
|
|
$this->loginAsUser($user);
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
$path = $this->rootView->getPath($id);
|
2016-04-15 10:02:17 +03:00
|
|
|
$ls = $this->rootView->getDirectoryContent($path);
|
2015-04-15 16:31:30 +03:00
|
|
|
$this->fileEtags[$id] = $this->rootView->getFileInfo($path)->getEtag();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOwnerWritesToShare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
Filesystem::file_put_contents('/sub1/sub2/folder/asd.txt', 'bar');
|
|
|
|
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
2015-06-23 15:31:41 +03:00
|
|
|
public function testOwnerWritesToSingleFileShare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
2015-11-10 18:31:30 +03:00
|
|
|
Filesystem::file_put_contents('/foo.txt', 'longer_bar');
|
2016-05-11 15:01:05 +03:00
|
|
|
$t = (int)Filesystem::filemtime('/foo.txt') - 1;
|
|
|
|
Filesystem::touch('/foo.txt', $t);
|
2015-06-23 15:31:41 +03:00
|
|
|
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER4, self::TEST_FILES_SHARING_API_USER3]);
|
|
|
|
$this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-06-23 15:31:41 +03:00
|
|
|
}
|
|
|
|
|
2015-04-15 16:31:30 +03:00
|
|
|
public function testOwnerWritesToShareWithReshare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
Filesystem::file_put_contents('/sub1/sub2/folder/inside/bar.txt', 'bar');
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testOwnerRenameInShare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
Filesystem::rename('/sub1/sub2/folder/file.txt', '/sub1/sub2/folder/renamed.txt');
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testOwnerRenameInReShare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
Filesystem::rename('/sub1/sub2/folder/inside/file.txt', '/sub1/sub2/folder/inside/renamed.txt');
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testOwnerRenameIntoReShare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
Filesystem::rename('/sub1/sub2/folder/file.txt', '/sub1/sub2/folder/inside/renamed.txt');
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testOwnerRenameOutOfReShare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
Filesystem::rename('/sub1/sub2/folder/inside/file.txt', '/sub1/sub2/folder/renamed.txt');
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testOwnerDeleteInShare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
Filesystem::unlink('/sub1/sub2/folder/file.txt');
|
|
|
|
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testOwnerDeleteInReShare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
Filesystem::unlink('/sub1/sub2/folder/inside/file.txt');
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
2015-04-22 18:24:40 +03:00
|
|
|
public function testOwnerUnshares() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
$folderInfo = $this->rootView->getFileInfo('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder');
|
2015-09-28 17:38:01 +03:00
|
|
|
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
|
2016-04-15 10:02:17 +03:00
|
|
|
|
|
|
|
$node = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder');
|
|
|
|
$shareManager = \OC::$server->getShareManager();
|
2020-06-24 17:49:16 +03:00
|
|
|
$shares = $shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER, $node, true);
|
2016-04-15 10:02:17 +03:00
|
|
|
|
|
|
|
foreach ($shares as $share) {
|
|
|
|
if ($share->getSharedWith() === self::TEST_FILES_SHARING_API_USER2) {
|
|
|
|
$shareManager->deleteShare($share);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-22 18:24:40 +03:00
|
|
|
$this->assertEtagsForFoldersChanged([
|
|
|
|
// direct recipient affected
|
2015-08-03 18:33:12 +03:00
|
|
|
self::TEST_FILES_SHARING_API_USER2,
|
2016-04-15 10:02:17 +03:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertAllUnchanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOwnerUnsharesFlatReshares() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
$folderInfo = $this->rootView->getFileInfo('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder/inside');
|
|
|
|
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
|
|
|
|
|
|
|
|
$node = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder/inside');
|
|
|
|
$shareManager = \OC::$server->getShareManager();
|
2020-06-24 17:49:16 +03:00
|
|
|
$shares = $shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER, $node, true);
|
2016-04-15 10:02:17 +03:00
|
|
|
|
|
|
|
foreach ($shares as $share) {
|
|
|
|
$shareManager->deleteShare($share);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEtagsForFoldersChanged([
|
|
|
|
// direct recipient affected
|
2015-08-03 18:33:12 +03:00
|
|
|
self::TEST_FILES_SHARING_API_USER4,
|
2015-04-22 18:24:40 +03:00
|
|
|
]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-22 18:24:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRecipientUnsharesFromSelf() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
|
2016-04-15 10:02:17 +03:00
|
|
|
$ls = $this->rootView->getDirectoryContent('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub1/sub2/');
|
2015-04-22 18:24:40 +03:00
|
|
|
$this->assertTrue(
|
|
|
|
$this->rootView->unlink('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub1/sub2/folder')
|
|
|
|
);
|
|
|
|
$this->assertEtagsForFoldersChanged([
|
|
|
|
// direct recipient affected
|
2015-08-03 18:33:12 +03:00
|
|
|
self::TEST_FILES_SHARING_API_USER2,
|
2015-04-22 18:24:40 +03:00
|
|
|
]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-22 18:24:40 +03:00
|
|
|
}
|
|
|
|
|
2015-04-15 16:31:30 +03:00
|
|
|
public function testRecipientWritesToShare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
Filesystem::file_put_contents('/sub1/sub2/folder/asd.txt', 'bar');
|
|
|
|
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER4]);
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->assertEtagsForFoldersChanged([
|
|
|
|
self::TEST_FILES_SHARING_API_USER1,
|
|
|
|
self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3
|
|
|
|
]);
|
2015-04-15 16:31:30 +03:00
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRecipientWritesToReshare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
Filesystem::file_put_contents('/sub1/sub2/folder/inside/asd.txt', 'bar');
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRecipientWritesToOtherRecipientsReshare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER3);
|
|
|
|
Filesystem::file_put_contents('/sub1/sub2/folder/inside/asd.txt', 'bar');
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRecipientRenameInShare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
Filesystem::rename('/sub1/sub2/folder/file.txt', '/sub1/sub2/folder/renamed.txt');
|
|
|
|
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRecipientRenameInReShare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
Filesystem::rename('/sub1/sub2/folder/inside/file.txt', '/sub1/sub2/folder/inside/renamed.txt');
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRecipientRenameResharedFolder() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
Filesystem::rename('/directReshare', '/sub1/directReshare');
|
|
|
|
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
$this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER2]);
|
|
|
|
|
|
|
|
$this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER2], 'sub1');
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRecipientDeleteInShare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
Filesystem::unlink('/sub1/sub2/folder/file.txt');
|
|
|
|
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testRecipientDeleteInReShare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
Filesystem::unlink('/sub1/sub2/folder/inside/file.txt');
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testReshareRecipientWritesToReshare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
|
|
|
|
Filesystem::file_put_contents('/sub1/sub2/inside/asd.txt', 'bar');
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testReshareRecipientRenameInReShare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
|
|
|
|
Filesystem::rename('/sub1/sub2/inside/file.txt', '/sub1/sub2/inside/renamed.txt');
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testReshareRecipientDeleteInReShare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
|
|
|
|
Filesystem::unlink('/sub1/sub2/inside/file.txt');
|
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2,
|
|
|
|
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|
2015-08-03 18:33:12 +03:00
|
|
|
|
|
|
|
public function testRecipientUploadInDirectReshare() {
|
|
|
|
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
|
|
|
|
Filesystem::file_put_contents('/directReshare/test.txt', 'sad');
|
|
|
|
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER3]);
|
|
|
|
$this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER4]);
|
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-08-03 18:33:12 +03:00
|
|
|
}
|
2015-10-01 16:37:26 +03:00
|
|
|
|
|
|
|
public function testEtagChangeOnPermissionsChange() {
|
2016-04-15 10:02:17 +03:00
|
|
|
$userFolder = $this->rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
|
|
|
|
$node = $userFolder->get('/sub1/sub2/folder');
|
2015-10-01 16:37:26 +03:00
|
|
|
|
2020-06-24 17:49:16 +03:00
|
|
|
$shares = $this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER, $node);
|
2016-04-15 10:02:17 +03:00
|
|
|
/** @var \OCP\Share\IShare[] $shares */
|
2020-04-09 14:53:40 +03:00
|
|
|
$shares = array_filter($shares, function (\OCP\Share\IShare $share) {
|
2016-04-15 10:02:17 +03:00
|
|
|
return $share->getSharedWith() === self::TEST_FILES_SHARING_API_USER2;
|
|
|
|
});
|
|
|
|
$this->assertCount(1, $shares);
|
2015-10-01 16:37:26 +03:00
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$share = $shares[0];
|
|
|
|
$share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE);
|
|
|
|
$this->shareManager->updateShare($share);
|
2015-10-01 16:37:26 +03:00
|
|
|
|
2016-04-15 10:02:17 +03:00
|
|
|
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER2]);
|
2015-10-01 16:37:26 +03:00
|
|
|
|
2015-06-15 15:10:10 +03:00
|
|
|
$this->assertAllUnchanged();
|
2015-10-01 16:37:26 +03:00
|
|
|
}
|
2015-04-15 16:31:30 +03:00
|
|
|
}
|