diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-10-18 23:25:18 +0300 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-10-19 10:10:54 +0300 |
commit | 1144cf0de00df3c1b2bc703105c49f24f85e1a50 (patch) | |
tree | c2fda40b51d894d03d29ceff588e26b02e3d5fb5 /apps | |
parent | fcda88ccb14d2bc75905138406bb15100e3c9585 (diff) |
Partial backport of etag propagation tests
Took the etag propagation test cases from
92abb5f23d3beb7e60c9f3a656a7ca41b5812da7 to make sure it uses the new
API when creating shares.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/tests/api.php | 5 | ||||
-rw-r--r-- | apps/files_sharing/tests/etagpropagation.php | 148 | ||||
-rw-r--r-- | apps/files_sharing/tests/groupetagpropagation.php | 30 | ||||
-rw-r--r-- | apps/files_sharing/tests/testcase.php | 31 |
4 files changed, 176 insertions, 38 deletions
diff --git a/apps/files_sharing/tests/api.php b/apps/files_sharing/tests/api.php index 3a2ae1eef37..cb440f997c4 100644 --- a/apps/files_sharing/tests/api.php +++ b/apps/files_sharing/tests/api.php @@ -40,9 +40,6 @@ class Test_Files_Sharing_Api extends TestCase { private static $tempStorage; - /** @var \OCP\Share\IManager */ - private $shareManager; - protected function setUp() { parent::setUp(); @@ -62,8 +59,6 @@ class Test_Files_Sharing_Api extends TestCase { $this->view->mkdir($this->folder . $this->subfolder . $this->subsubfolder); $this->view->file_put_contents($this->folder.$this->filename, $this->data); $this->view->file_put_contents($this->folder . $this->subfolder . $this->filename, $this->data); - - $this->shareManager = \OC::$server->getShareManager(); } protected function tearDown() { diff --git a/apps/files_sharing/tests/etagpropagation.php b/apps/files_sharing/tests/etagpropagation.php index 67c5410dc80..e7d5bb46258 100644 --- a/apps/files_sharing/tests/etagpropagation.php +++ b/apps/files_sharing/tests/etagpropagation.php @@ -50,13 +50,15 @@ class EtagPropagation extends PropagationTestCase { $this->fileIds[self::TEST_FILES_SHARING_API_USER3] = []; $this->fileIds[self::TEST_FILES_SHARING_API_USER4] = []; + $rootFolder = \OC::$server->getRootFolder(); + $shareManager = \OC::$server->getShareManager(); + $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('/foo.txt', 'foobar'); $view1->file_put_contents('/sub1/sub2/folder/file.txt', 'foobar'); $view1->file_put_contents('/sub1/sub2/folder/inside/file.txt', 'foobar'); @@ -64,30 +66,90 @@ class EtagPropagation extends PropagationTestCase { $this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo); $fileInfo = $view1->getFileInfo('/foo.txt'); $this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo); - \OCP\Share::shareItem('file', $fileInfo->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_USER2, 31); - \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER3, 31); + + $node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1) + ->get('/foo.txt'); + $share = $shareManager->newShare(); + $share->setNode($node) + ->setShareType(\OCP\Share::SHARE_TYPE_USER) + ->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); + $shareManager->createShare($share); + $node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1) + ->get('/sub1/sub2/folder'); + $share = $shareManager->newShare(); + $share->setNode($node) + ->setShareType(\OCP\Share::SHARE_TYPE_USER) + ->setSharedWith(self::TEST_FILES_SHARING_API_USER2) + ->setSharedBy(self::TEST_FILES_SHARING_API_USER1) + ->setPermissions(\OCP\Constants::PERMISSION_ALL); + $shareManager->createShare($share); + $share = $shareManager->newShare(); + $share->setNode($node) + ->setShareType(\OCP\Share::SHARE_TYPE_USER) + ->setSharedWith(self::TEST_FILES_SHARING_API_USER3) + ->setSharedBy(self::TEST_FILES_SHARING_API_USER1) + ->setPermissions(\OCP\Constants::PERMISSION_ALL); + $shareManager->createShare($share); + $folderInfo = $view1->getFileInfo('/directReshare'); $this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo); - \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31); + + $node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1) + ->get('/directReshare'); + $share = $shareManager->newShare(); + $share->setNode($node) + ->setShareType(\OCP\Share::SHARE_TYPE_USER) + ->setSharedWith(self::TEST_FILES_SHARING_API_USER2) + ->setSharedBy(self::TEST_FILES_SHARING_API_USER1) + ->setPermissions(\OCP\Constants::PERMISSION_ALL); + $shareManager->createShare($share); + $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(); + /* + * User 2 + */ $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'); $this->assertInstanceOf('\OC\Files\FileInfo', $insideInfo); - \OCP\Share::shareItem('folder', $insideInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER4, 31); + + $node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER2) + ->get('/sub1/sub2/folder/inside'); + $share = $shareManager->newShare(); + $share->setNode($node) + ->setShareType(\OCP\Share::SHARE_TYPE_USER) + ->setSharedWith(self::TEST_FILES_SHARING_API_USER4) + ->setSharedBy(self::TEST_FILES_SHARING_API_USER2) + ->setPermissions(\OCP\Constants::PERMISSION_ALL); + $shareManager->createShare($share); + $folderInfo = $view2->getFileInfo('/directReshare'); $this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo); - \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER4, 31); + + $node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER2) + ->get('/directReshare'); + $share = $shareManager->newShare(); + $share->setNode($node) + ->setShareType(\OCP\Share::SHARE_TYPE_USER) + ->setSharedWith(self::TEST_FILES_SHARING_API_USER4) + ->setSharedBy(self::TEST_FILES_SHARING_API_USER2) + ->setPermissions(\OCP\Constants::PERMISSION_ALL); + $shareManager->createShare($share); + $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(); + /* + * User 3 + */ $this->loginAsUser(self::TEST_FILES_SHARING_API_USER3); $view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files'); $view3->mkdir('/sub1/sub2'); @@ -96,6 +158,9 @@ class EtagPropagation extends PropagationTestCase { $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(); + /* + * User 4 + */ $this->loginAsUser(self::TEST_FILES_SHARING_API_USER4); $view4 = new View('/' . self::TEST_FILES_SHARING_API_USER4 . '/files'); $view4->mkdir('/sub1/sub2'); @@ -108,6 +173,7 @@ class EtagPropagation extends PropagationTestCase { $this->loginAsUser($user); foreach ($ids as $id) { $path = $this->rootView->getPath($id); + $ls = $this->rootView->getDirectoryContent($path); $this->fileEtags[$id] = $this->rootView->getFileInfo($path)->getEtag(); } } @@ -203,19 +269,40 @@ class EtagPropagation extends PropagationTestCase { $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); $folderInfo = $this->rootView->getFileInfo('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder'); $this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo); - $folderId = $folderInfo->getId(); - $this->assertTrue( - \OCP\Share::unshare( - 'folder', - $folderId, - \OCP\Share::SHARE_TYPE_USER, - self::TEST_FILES_SHARING_API_USER2 - ) - ); + + $node = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder'); + $shareManager = \OC::$server->getShareManager(); + $shares = $shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, \OCP\Share::SHARE_TYPE_USER, $node, true); + + foreach ($shares as $share) { + if ($share->getSharedWith() === self::TEST_FILES_SHARING_API_USER2) { + $shareManager->deleteShare($share); + } + } + $this->assertEtagsForFoldersChanged([ // direct recipient affected self::TEST_FILES_SHARING_API_USER2, - // reshare recipient affected + ]); + + $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(); + $shares = $shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, \OCP\Share::SHARE_TYPE_USER, $node, true); + + foreach ($shares as $share) { + $shareManager->deleteShare($share); + } + + $this->assertEtagsForFoldersChanged([ + // direct recipient affected self::TEST_FILES_SHARING_API_USER4, ]); @@ -224,14 +311,13 @@ class EtagPropagation extends PropagationTestCase { public function testRecipientUnsharesFromSelf() { $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2); + $ls = $this->rootView->getDirectoryContent('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub1/sub2/'); $this->assertTrue( $this->rootView->unlink('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub1/sub2/folder') ); $this->assertEtagsForFoldersChanged([ // direct recipient affected self::TEST_FILES_SHARING_API_USER2, - // reshare recipient affected - self::TEST_FILES_SHARING_API_USER4, ]); $this->assertAllUnchanged(); @@ -241,8 +327,11 @@ class EtagPropagation extends PropagationTestCase { $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->assertEtagsForFoldersChanged([ + self::TEST_FILES_SHARING_API_USER1, + self::TEST_FILES_SHARING_API_USER2, + self::TEST_FILES_SHARING_API_USER3 + ]); $this->assertAllUnchanged(); } @@ -351,14 +440,21 @@ class EtagPropagation extends PropagationTestCase { } public function testEtagChangeOnPermissionsChange() { - $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); + $userFolder = $this->rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1); + $node = $userFolder->get('/sub1/sub2/folder'); - $view = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); - $folderInfo = $view->getFileInfo('/sub1/sub2/folder'); + $shares = $this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, \OCP\Share::SHARE_TYPE_USER, $node); + /** @var \OCP\Share\IShare[] $shares */ + $shares = array_filter($shares, function(\OCP\Share\IShare $share) { + return $share->getSharedWith() === self::TEST_FILES_SHARING_API_USER2; + }); + $this->assertCount(1, $shares); - \OCP\Share::setPermissions('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 17); + $share = $shares[0]; + $share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE); + $this->shareManager->updateShare($share); - $this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER4]); + $this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER2]); $this->assertAllUnchanged(); } diff --git a/apps/files_sharing/tests/groupetagpropagation.php b/apps/files_sharing/tests/groupetagpropagation.php index 0c365e118cb..f119ef0864b 100644 --- a/apps/files_sharing/tests/groupetagpropagation.php +++ b/apps/files_sharing/tests/groupetagpropagation.php @@ -46,18 +46,36 @@ class GroupEtagPropagation extends PropagationTestCase { $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); $view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); $view1->mkdir('/test/sub'); - $folderInfo = $view1->getFileInfo('/test'); - \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group1', 31); + + $this->share( + \OCP\Share::SHARE_TYPE_GROUP, + '/test', + self::TEST_FILES_SHARING_API_USER1, + 'group1', + \OCP\Constants::PERMISSION_ALL + ); $this->fileIds[self::TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId(); $this->fileIds[self::TEST_FILES_SHARING_API_USER1]['test'] = $view1->getFileInfo('test')->getId(); $this->fileIds[self::TEST_FILES_SHARING_API_USER1]['test/sub'] = $view1->getFileInfo('test/sub')->getId(); $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2); $view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); - $folderInfo = $view2->getFileInfo('/test'); - $subFolderInfo = $view2->getFileInfo('/test/sub'); - \OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group2', 31); - \OCP\Share::shareItem('folder', $subFolderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group3', 31); + + $this->share( + \OCP\Share::SHARE_TYPE_GROUP, + '/test', + self::TEST_FILES_SHARING_API_USER2, + 'group2', + \OCP\Constants::PERMISSION_ALL + ); + $this->share( + \OCP\Share::SHARE_TYPE_GROUP, + '/test/sub', + self::TEST_FILES_SHARING_API_USER2, + 'group3', + \OCP\Constants::PERMISSION_ALL + ); + $this->fileIds[self::TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId(); $this->fileIds[self::TEST_FILES_SHARING_API_USER2]['test'] = $view2->getFileInfo('test')->getId(); $this->fileIds[self::TEST_FILES_SHARING_API_USER2]['test/sub'] = $view2->getFileInfo('test/sub')->getId(); diff --git a/apps/files_sharing/tests/testcase.php b/apps/files_sharing/tests/testcase.php index ce0a8beeec8..d30782e5074 100644 --- a/apps/files_sharing/tests/testcase.php +++ b/apps/files_sharing/tests/testcase.php @@ -59,6 +59,11 @@ abstract class TestCase extends \Test\TestCase { public $folder; public $subfolder; + /** @var \OCP\Share\IManager */ + protected $shareManager; + /** @var \OCP\Files\IRootFolder */ + protected $rootFolder; + public static function setUpBeforeClass() { parent::setUpBeforeClass(); @@ -96,7 +101,6 @@ abstract class TestCase extends \Test\TestCase { $groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER4, 'group3'); $groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_GROUP1); \OC_Group::useBackend($groupBackend); - } protected function setUp() { @@ -107,6 +111,9 @@ abstract class TestCase extends \Test\TestCase { $this->data = 'foobar'; $this->view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); + + $this->shareManager = \OC::$server->getShareManager(); + $this->rootFolder = \OC::$server->getRootFolder(); } protected function tearDown() { @@ -201,4 +208,26 @@ abstract class TestCase extends \Test\TestCase { } + /** + * @param int $type The share type + * @param string $path The path to share relative to $initiators root + * @param string $initiator + * @param string $recipient + * @param int $permissions + * @return \OCP\Share\IShare + */ + protected function share($type, $path, $initiator, $recipient, $permissions) { + $userFolder = $this->rootFolder->getUserFolder($initiator); + $node = $userFolder->get($path); + + $share = $this->shareManager->newShare(); + $share->setShareType($type) + ->setSharedWith($recipient) + ->setSharedBy($initiator) + ->setNode($node) + ->setPermissions($permissions); + $share = $this->shareManager->createShare($share); + + return $share; + } } |