unit test for etag propagation across shared storage boundary

This commit is contained in:
Robin Appelman 2015-03-06 13:15:50 +01:00
parent cc331609bf
commit 2dc11cf20e
1 changed files with 158 additions and 2 deletions

View File

@ -19,12 +19,12 @@
* *
*/ */
namespace OCA\Files_Sharing\Tests; namespace OCA\Files_sharing\Tests;
use OC\Files\Filesystem;
use OC\Files\View; use OC\Files\View;
class Propagation extends TestCase { class Propagation extends TestCase {
public function testSizePropagationWhenOwnerChangesFile() { public function testSizePropagationWhenOwnerChangesFile() {
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1); $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
$recipientView = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); $recipientView = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
@ -86,4 +86,160 @@ class Propagation extends TestCase {
$newOwnerRootInfo = $ownerView->getFileInfo('', false); $newOwnerRootInfo = $ownerView->getFileInfo('', false);
$this->assertEquals($ownerRootInfo->getSize() + 3, $newOwnerRootInfo->getSize()); $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());
}
} }