Add test case for group share propagation
This commit is contained in:
parent
75c3d64635
commit
3d5a7b307f
|
@ -34,31 +34,7 @@ use OC\Files\View;
|
|||
*
|
||||
* @package OCA\Files_sharing\Tests
|
||||
*/
|
||||
class EtagPropagation extends TestCase {
|
||||
/**
|
||||
* @var \OC\Files\View
|
||||
*/
|
||||
private $rootView;
|
||||
protected $fileIds = []; // [$user=>[$path=>$id]]
|
||||
protected $fileEtags = []; // [$id=>$etag]
|
||||
|
||||
public static function setUpBeforeClass() {
|
||||
parent::setUpBeforeClass();
|
||||
\OCA\Files_Sharing\Helper::registerHooks();
|
||||
}
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->setUpShares();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
\OC_Hook::clear('OC_Filesystem', 'post_write');
|
||||
\OC_Hook::clear('OC_Filesystem', 'post_delete');
|
||||
\OC_Hook::clear('OC_Filesystem', 'post_rename');
|
||||
\OC_Hook::clear('OCP\Share', 'post_update_permissions');
|
||||
parent::tearDown();
|
||||
}
|
||||
class EtagPropagation extends PropagationTestCase {
|
||||
|
||||
/**
|
||||
* "user1" is the admin who shares a folder "sub1/sub2/folder" with "user2" and "user3"
|
||||
|
@ -67,7 +43,7 @@ class EtagPropagation extends TestCase {
|
|||
* "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() {
|
||||
protected 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] = [];
|
||||
|
@ -136,58 +112,6 @@ class EtagPropagation extends TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 assertAllUnchanged() {
|
||||
$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');
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Robin Appelman <icewind@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;
|
||||
|
||||
/**
|
||||
* @group DB
|
||||
*
|
||||
* @package OCA\Files_sharing\Tests
|
||||
*/
|
||||
class GroupEtagPropagation extends PropagationTestCase {
|
||||
/**
|
||||
* "user1" creates /test, /test/sub and shares with group1
|
||||
* "user2" (in group1) reshares /test with group2 and reshared /test/sub with group3
|
||||
* "user3" (in group 2)
|
||||
* "user4" (in group 3)
|
||||
*/
|
||||
protected 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('/test/sub');
|
||||
$folderInfo = $view1->getFileInfo('/test');
|
||||
\OCP\Share::shareItem('folder', $folderInfo->getId(), \OCP\Share::SHARE_TYPE_GROUP, 'group1', 31);
|
||||
$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->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();
|
||||
|
||||
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER3);
|
||||
$view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER3][''] = $view3->getFileInfo('')->getId();
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER3]['test'] = $view3->getFileInfo('test')->getId();
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER3]['test/sub'] = $view3->getFileInfo('test/sub')->getId();
|
||||
|
||||
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
|
||||
$view4 = new View('/' . self::TEST_FILES_SHARING_API_USER4 . '/files');
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER4][''] = $view4->getFileInfo('')->getId();
|
||||
$this->fileIds[self::TEST_FILES_SHARING_API_USER4]['sub'] = $view4->getFileInfo('sub')->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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testGroupReShareRecipientWrites() {
|
||||
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER3);
|
||||
|
||||
Filesystem::file_put_contents('/test/sub/file.txt', 'asd');
|
||||
|
||||
$this->assertEtagsChanged([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->assertAllUnchanged();
|
||||
}
|
||||
|
||||
public function testGroupReShareSubFolderRecipientWrites() {
|
||||
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
|
||||
|
||||
Filesystem::file_put_contents('/sub/file.txt', 'asd');
|
||||
|
||||
$this->assertEtagsChanged([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->assertAllUnchanged();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Robin Appelman <icewind@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;
|
||||
|
||||
abstract class PropagationTestCase extends TestCase {
|
||||
/**
|
||||
* @var \OC\Files\View
|
||||
*/
|
||||
protected $rootView;
|
||||
protected $fileIds = []; // [$user=>[$path=>$id]]
|
||||
protected $fileEtags = []; // [$id=>$etag]
|
||||
|
||||
public static function setUpBeforeClass() {
|
||||
parent::setUpBeforeClass();
|
||||
\OCA\Files_Sharing\Helper::registerHooks();
|
||||
}
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->setUpShares();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
\OC_Hook::clear('OC_Filesystem', 'post_write');
|
||||
\OC_Hook::clear('OC_Filesystem', 'post_delete');
|
||||
\OC_Hook::clear('OC_Filesystem', 'post_rename');
|
||||
\OC_Hook::clear('OCP\Share', 'post_update_permissions');
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
abstract protected function setUpShares();
|
||||
|
||||
/**
|
||||
* @param string[] $users
|
||||
* @param string $subPath
|
||||
*/
|
||||
protected 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
|
||||
*/
|
||||
protected 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
|
||||
*/
|
||||
protected function assertEtagsForFoldersChanged($users) {
|
||||
$this->assertEtagsChanged($users);
|
||||
|
||||
$this->assertEtagsChanged($users, 'sub1');
|
||||
$this->assertEtagsChanged($users, 'sub1/sub2');
|
||||
}
|
||||
|
||||
protected function assertAllUnchanged() {
|
||||
$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);
|
||||
}
|
||||
}
|
|
@ -84,9 +84,15 @@ abstract class TestCase extends \Test\TestCase {
|
|||
$groupBackend = new \OC_Group_Dummy();
|
||||
$groupBackend->createGroup(self::TEST_FILES_SHARING_API_GROUP1);
|
||||
$groupBackend->createGroup('group');
|
||||
$groupBackend->createGroup('group1');
|
||||
$groupBackend->createGroup('group2');
|
||||
$groupBackend->createGroup('group3');
|
||||
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER1, 'group');
|
||||
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER2, 'group');
|
||||
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER3, 'group');
|
||||
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER2, 'group1');
|
||||
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER3, 'group2');
|
||||
$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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue