diff options
author | Robin Appelman <icewind@owncloud.com> | 2015-04-15 15:31:30 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2015-04-27 14:07:16 +0200 |
commit | d5434c9c4e005ff0407d6adddbc2a81dbedd7783 (patch) | |
tree | adce9dba3a0fa9d671be13ec9880edfb4b1c6935 /apps/files_sharing/tests | |
parent | b5c62cdad640ca9d0c2c184a61f9f0d683f22509 (diff) | |
download | nextcloud-server-d5434c9c4e005ff0407d6adddbc2a81dbedd7783.tar.gz nextcloud-server-d5434c9c4e005ff0407d6adddbc2a81dbedd7783.zip |
more propagation tests
Diffstat (limited to 'apps/files_sharing/tests')
-rw-r--r-- | apps/files_sharing/tests/etagpropagation.php | 338 | ||||
-rw-r--r-- | apps/files_sharing/tests/propagation.php | 245 | ||||
-rw-r--r-- | apps/files_sharing/tests/sizepropagation.php | 89 | ||||
-rw-r--r-- | apps/files_sharing/tests/testcase.php | 2 |
4 files changed, 429 insertions, 245 deletions
diff --git a/apps/files_sharing/tests/etagpropagation.php b/apps/files_sharing/tests/etagpropagation.php new file mode 100644 index 00000000000..b515362c02d --- /dev/null +++ b/apps/files_sharing/tests/etagpropagation.php @@ -0,0 +1,338 @@ +<?php +/** + * @author Vincent Petry <pvince81@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @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, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCA\Files_sharing\Tests; + +use OC\Files\Filesystem; +use OC\Files\View; + +class EtagPropagation extends TestCase { + /** + * @var \OC\Files\View + */ + private $rootView; + protected $fileIds = []; // [$user=>[$path=>$id]] + protected $fileEtags = []; // [$id=>$etag] + + protected function setUp() { + parent::setUp(); + $this->setUpShares(); + } + + /** + * "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) + */ + private function setUpShares() { + $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] = []; + + $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'); + $view1->mkdir('/sub1/sub2/folder/other'); + $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'); + \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31); + \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31); + $folderInfo = $view1->getFileInfo('/directReshare'); + \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31); + $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(); + + $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'); + $insideInfo = $view2->getFileInfo('/sub1/sub2/folder/inside'); + \OCP\Share::shareItem('folder', $insideInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER4, 31); + $folderInfo = $view2->getFileInfo('/directReshare'); + \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER4, 31); + $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(); + + $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(); + + $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); + $this->fileEtags[$id] = $this->rootView->getFileInfo($path)->getEtag(); + } + } + } + + /** + * @param string[] $users + * @param string $subPath + */ + private function assertEtagsChanged($users, $subPath = '') { + $oldUser = \OC::$server->getUserSession()->getUser(); + foreach ($users as $user) { + $this->loginAsUser($user); + $id = $this->fileIds[$user][$subPath]; + $path = $this->rootView->getPath($id); + $etag = $this->rootView->getFileInfo($path)->getEtag(); + $this->assertNotEquals($this->fileEtags[$id], $etag, 'Failed asserting that the etag for "' . $subPath . '" of user ' . $user . ' has changed'); + $this->fileEtags[$id] = $etag; + } + $this->loginAsUser($oldUser->getUID()); + } + + /** + * @param string[] $users + * @param string $subPath + */ + private function assertEtagsNotChanged($users, $subPath = '') { + $oldUser = \OC::$server->getUserSession()->getUser(); + foreach ($users as $user) { + $this->loginAsUser($user); + $id = $this->fileIds[$user][$subPath]; + $path = $this->rootView->getPath($id); + $etag = $this->rootView->getFileInfo($path)->getEtag(); + $this->assertEquals($this->fileEtags[$id], $etag, 'Failed asserting that the etag for "' . $subPath . '" of user ' . $user . ' has not changed'); + $this->fileEtags[$id] = $etag; + } + $this->loginAsUser($oldUser->getUID()); + } + + /** + * Assert that the etags for the root, /sub1 and /sub1/sub2 have changed + * + * @param string[] $users + */ + private function assertEtagsForFoldersChanged($users) { + $this->assertEtagsChanged($users); + + $this->assertEtagsChanged($users, 'sub1'); + $this->assertEtagsChanged($users, 'sub1/sub2'); + } + + private function assertAllUnchaged() { + $users = [self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, + self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]; + $this->assertEtagsNotChanged($users); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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]); + $this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, + self::TEST_FILES_SHARING_API_USER3]); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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'); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } + + 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]); + + $this->assertAllUnchaged(); + } +} diff --git a/apps/files_sharing/tests/propagation.php b/apps/files_sharing/tests/propagation.php deleted file mode 100644 index 1949f7808a4..00000000000 --- a/apps/files_sharing/tests/propagation.php +++ /dev/null @@ -1,245 +0,0 @@ -<?php -/** - * @author Vincent Petry <pvince81@owncloud.com> - * - * @copyright Copyright (c) 2015, ownCloud, Inc. - * @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, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * - */ - -namespace OCA\Files_sharing\Tests; - -use OC\Files\Filesystem; -use OC\Files\View; - -class Propagation extends TestCase { - public function testSizePropagationWhenOwnerChangesFile() { - $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); - $recipientView = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); - - $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); - $ownerView = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); - $ownerView->mkdir('/sharedfolder/subfolder'); - $ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar'); - - $sharedFolderInfo = $ownerView->getFileInfo('/sharedfolder', false); - \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31); - $ownerRootInfo = $ownerView->getFileInfo('', false); - - $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); - $this->assertTrue($recipientView->file_exists('/sharedfolder/subfolder/foo.txt')); - $recipientRootInfo = $recipientView->getFileInfo('', false); - - // when file changed as owner - $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); - $ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar'); - - // size of recipient's root stays the same - $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); - $newRecipientRootInfo = $recipientView->getFileInfo('', false); - $this->assertEquals($recipientRootInfo->getSize(), $newRecipientRootInfo->getSize()); - - // size of owner's root increases - $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); - $newOwnerRootInfo = $ownerView->getFileInfo('', false); - $this->assertEquals($ownerRootInfo->getSize() + 3, $newOwnerRootInfo->getSize()); - } - - public function testSizePropagationWhenRecipientChangesFile() { - $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); - $recipientView = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); - - $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); - $ownerView = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); - $ownerView->mkdir('/sharedfolder/subfolder'); - $ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar'); - - $sharedFolderInfo = $ownerView->getFileInfo('/sharedfolder', false); - \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31); - $ownerRootInfo = $ownerView->getFileInfo('', false); - - $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); - $this->assertTrue($recipientView->file_exists('/sharedfolder/subfolder/foo.txt')); - $recipientRootInfo = $recipientView->getFileInfo('', false); - - // when file changed as recipient - $recipientView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar'); - - // size of recipient's root stays the same - $newRecipientRootInfo = $recipientView->getFileInfo('', false); - $this->assertEquals($recipientRootInfo->getSize(), $newRecipientRootInfo->getSize()); - - // size of owner's root increases - $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); - $newOwnerRootInfo = $ownerView->getFileInfo('', false); - $this->assertEquals($ownerRootInfo->getSize() + 3, $newOwnerRootInfo->getSize()); - } - - /** - * @return \OC\Files\View[] - */ - private function setupViews() { - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); - $view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2); - $view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); - $view2->mkdir('/sharedfolder/subfolder'); - $view2->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar'); - return [$view1, $view2]; - } - - public function testEtagPropagationSingleUserShareRecipient() { - /** - * @var \OC\Files\View $view1 - * @var \OC\Files\View $view2 - */ - list($view1, $view2) = $this->setupViews(); - - $sharedFolderInfo = $view2->getFileInfo('/sharedfolder'); - \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31); - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); - $this->assertTrue($view1->file_exists('/sharedfolder/subfolder/foo.txt')); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2); - $rootInfo = $view2->getFileInfo(''); - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); - - Filesystem::file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar'); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2); - $newRootInfo = $view2->getFileInfo(''); - $this->assertNotEquals($rootInfo->getEtag(), $newRootInfo->getEtag()); - } - - public function testEtagPropagationSingleUserShare() { - /** - * @var \OC\Files\View $view1 - * @var \OC\Files\View $view2 - */ - list($view1, $view2) = $this->setupViews(); - - $sharedFolderInfo = $view2->getFileInfo('/sharedfolder'); - \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31); - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); - $this->assertTrue($view1->file_exists('/sharedfolder/subfolder/foo.txt')); - - $rootInfo = $view1->getFileInfo(''); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2); - Filesystem::file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar'); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); - $newRootInfo = $view1->getFileInfo(''); - $this->assertNotEquals($rootInfo->getEtag(), $newRootInfo->getEtag()); - } - - public function testEtagPropagationGroupShare() { - /** - * @var \OC\Files\View $view1 - * @var \OC\Files\View $view2 - */ - list($view1, $view2) = $this->setupViews(); - - $sharedFolderInfo = $view2->getFileInfo('/sharedfolder'); - \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group', 31); - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); - $this->assertTrue($view1->file_exists('/sharedfolder/subfolder/foo.txt')); - - $rootInfo = $view1->getFileInfo(''); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2); - Filesystem::file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar'); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); - $newRootInfo = $view1->getFileInfo(''); - $this->assertNotEquals($rootInfo->getEtag(), $newRootInfo->getEtag()); - } - - public function testEtagPropagationGroupShareOtherRecipient() { - /** - * @var \OC\Files\View $view1 - * @var \OC\Files\View $view2 - */ - list($view1, $view2) = $this->setupViews(); - - $sharedFolderInfo = $view2->getFileInfo('/sharedfolder'); - \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group', 31); - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER3); - $view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files'); - $this->assertTrue($view3->file_exists('/sharedfolder/subfolder/foo.txt')); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); - $rootInfo = $view1->getFileInfo(''); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER3); - Filesystem::file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar'); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); - $newRootInfo = $view1->getFileInfo(''); - $this->assertNotEquals($rootInfo->getEtag(), $newRootInfo->getEtag()); - } - - public function testEtagPropagationOtherShare() { - /** - * @var \OC\Files\View $view1 - * @var \OC\Files\View $view2 - */ - list($view1, $view2) = $this->setupViews(); - - $sharedFolderInfo = $view2->getFileInfo('/sharedfolder'); - \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31); - \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31); - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER3); - $view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files'); - $this->assertTrue($view3->file_exists('/sharedfolder/subfolder/foo.txt')); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); - $rootInfo = $view1->getFileInfo(''); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER3); - Filesystem::file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar'); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); - $newRootInfo = $view1->getFileInfo(''); - $this->assertNotEquals($rootInfo->getEtag(), $newRootInfo->getEtag()); - } - - public function testEtagPropagationOtherShareSubFolder() { - /** - * @var \OC\Files\View $view1 - * @var \OC\Files\View $view2 - */ - list($view1, $view2) = $this->setupViews(); - - $sharedFolderInfo = $view2->getFileInfo('/sharedfolder'); - \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31); - $sharedFolderInfo = $view2->getFileInfo('/sharedfolder/subfolder'); - \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31); - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER3); - $view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files'); - $this->assertTrue($view3->file_exists('/subfolder/foo.txt')); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); - $rootInfo = $view1->getFileInfo(''); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER3); - Filesystem::file_put_contents('/subfolder/foo.txt', 'foobar'); - - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); - $newRootInfo = $view1->getFileInfo(''); - $this->assertNotEquals($rootInfo->getEtag(), $newRootInfo->getEtag()); - } -} diff --git a/apps/files_sharing/tests/sizepropagation.php b/apps/files_sharing/tests/sizepropagation.php new file mode 100644 index 00000000000..4ab3475ccfc --- /dev/null +++ b/apps/files_sharing/tests/sizepropagation.php @@ -0,0 +1,89 @@ +<?php +/** + * @author Vincent Petry <pvince81@owncloud.com> + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @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, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ + +namespace OCA\Files_sharing\Tests; + +use OC\Files\View; + +class SizePropagation extends TestCase { + + public function testSizePropagationWhenOwnerChangesFile() { + $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); + $recipientView = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); + $ownerView = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); + $ownerView->mkdir('/sharedfolder/subfolder'); + $ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar'); + + $sharedFolderInfo = $ownerView->getFileInfo('/sharedfolder', false); + \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31); + $ownerRootInfo = $ownerView->getFileInfo('', false); + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); + $this->assertTrue($recipientView->file_exists('/sharedfolder/subfolder/foo.txt')); + $recipientRootInfo = $recipientView->getFileInfo('', false); + + // when file changed as owner + $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); + $ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar'); + + // size of recipient's root stays the same + $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); + $newRecipientRootInfo = $recipientView->getFileInfo('', false); + $this->assertEquals($recipientRootInfo->getSize(), $newRecipientRootInfo->getSize()); + + // size of owner's root increases + $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); + $newOwnerRootInfo = $ownerView->getFileInfo('', false); + $this->assertEquals($ownerRootInfo->getSize() + 3, $newOwnerRootInfo->getSize()); + } + + public function testSizePropagationWhenRecipientChangesFile() { + $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); + $recipientView = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); + $ownerView = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); + $ownerView->mkdir('/sharedfolder/subfolder'); + $ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar'); + + $sharedFolderInfo = $ownerView->getFileInfo('/sharedfolder', false); + \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31); + $ownerRootInfo = $ownerView->getFileInfo('', false); + + $this->loginHelper(self::TEST_FILES_SHARING_API_USER1); + $this->assertTrue($recipientView->file_exists('/sharedfolder/subfolder/foo.txt')); + $recipientRootInfo = $recipientView->getFileInfo('', false); + + // when file changed as recipient + $recipientView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar'); + + // size of recipient's root stays the same + $newRecipientRootInfo = $recipientView->getFileInfo('', false); + $this->assertEquals($recipientRootInfo->getSize(), $newRecipientRootInfo->getSize()); + + // size of owner's root increases + $this->loginHelper(self::TEST_FILES_SHARING_API_USER2); + $newOwnerRootInfo = $ownerView->getFileInfo('', false); + $this->assertEquals($ownerRootInfo->getSize() + 3, $newOwnerRootInfo->getSize()); + } +} diff --git a/apps/files_sharing/tests/testcase.php b/apps/files_sharing/tests/testcase.php index 5cae54fef6c..b9e9f077201 100644 --- a/apps/files_sharing/tests/testcase.php +++ b/apps/files_sharing/tests/testcase.php @@ -43,6 +43,7 @@ abstract class TestCase extends \Test\TestCase { const TEST_FILES_SHARING_API_USER1 = "test-share-user1"; const TEST_FILES_SHARING_API_USER2 = "test-share-user2"; const TEST_FILES_SHARING_API_USER3 = "test-share-user3"; + const TEST_FILES_SHARING_API_USER4 = "test-share-user4"; const TEST_FILES_SHARING_API_GROUP1 = "test-share-group1"; @@ -76,6 +77,7 @@ abstract class TestCase extends \Test\TestCase { $backend->createUser(self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER1); $backend->createUser(self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER2); $backend->createUser(self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER3); + $backend->createUser(self::TEST_FILES_SHARING_API_USER4, self::TEST_FILES_SHARING_API_USER4); // create group $groupBackend = new \OC_Group_Dummy(); |