From 2dc11cf20e85e9f47c0a2e7027e1229b41c46e6d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 6 Mar 2015 13:15:50 +0100 Subject: [PATCH] unit test for etag propagation across shared storage boundary --- apps/files_sharing/tests/propagation.php | 160 ++++++++++++++++++++++- 1 file changed, 158 insertions(+), 2 deletions(-) diff --git a/apps/files_sharing/tests/propagation.php b/apps/files_sharing/tests/propagation.php index 546f67556f..1949f7808a 100644 --- a/apps/files_sharing/tests/propagation.php +++ b/apps/files_sharing/tests/propagation.php @@ -19,12 +19,12 @@ * */ -namespace OCA\Files_Sharing\Tests; +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'); @@ -86,4 +86,160 @@ class Propagation extends TestCase { $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()); + } }