Compare commits

...

11 Commits

Author SHA1 Message Date
Lukas Reschke a4f6e198a1 Disable testing app only conditionally
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
2021-06-02 18:01:04 +02:00
Lukas Reschke 4cc3180429 Move null user test first
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
2021-06-02 17:13:01 +02:00
Lukas Reschke 4b48154b80 Import namespaced MockObject
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
2021-06-02 15:32:41 +02:00
Lukas Reschke e09c99cefa Nest migration code
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
2021-06-02 15:29:06 +02:00
Lukas Reschke 37543c0530 Use MockObject instead of PHPUnit_Framework_MockObject_MockObject
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
2021-06-02 15:22:54 +02:00
Lukas Reschke 9ed3522685 else if -> elseif
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
2021-06-02 15:22:03 +02:00
Lukas Reschke aef3f7cb00 Use single quotes instead double quotes
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
2021-06-02 15:21:18 +02:00
Lukas Reschke dfd9d5f504 Use self::getUniqueID instead of uniqid
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
2021-06-02 15:19:53 +02:00
Lukas Reschke 1d5cbd3e04 Flush duplicate usernames for integration tests
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
2021-06-02 15:01:25 +02:00
Lukas Reschke 4abf1226ba Adjust tests to use different user IDs
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
2021-06-02 15:01:25 +02:00
Lukas Reschke 39974acc5e Dont allow reusing usernames
We have cases in which app developers forget to delete user data when a user is being deleted. This could be problematic as future users with the same username could then access this data.

This mitigates this risk a bit by not allowing reusing of usernames. That said, we still need to fix occurrences of these issues by deleting missed data.

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
2021-06-02 15:01:24 +02:00
38 changed files with 1167 additions and 770 deletions

View File

@ -79,7 +79,7 @@ class FileTest extends TestCase {
\OC_Hook::clear();
$this->user = 'test_user';
$this->user = self::getUniqueID('test_user');
$this->createUser($this->user, 'pass');
$this->loginAsUser($this->user);

View File

@ -892,8 +892,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
$userManager = \OC::$server->getUserManager();
$rootFolder = \OC::$server->getRootFolder();
$u1 = $userManager->createUser('testFed', md5(time()));
$u2 = $userManager->createUser('testFed2', md5(time()));
$u1 = $userManager->createUser(self::getUniqueID('testFed'), md5(time()));
$u2 = $userManager->createUser(self::getUniqueID('testFed2'), md5(time()));
$folder1 = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo');
$file1 = $folder1->newFile('bar1');
@ -946,7 +946,7 @@ class FederatedShareProviderTest extends \Test\TestCase {
$userManager = \OC::$server->getUserManager();
$rootFolder = \OC::$server->getRootFolder();
$u1 = $userManager->createUser('testFed', md5(time()));
$u1 = $userManager->createUser(self::getUniqueID('testFed'), md5(time()));
$folder1 = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo');
$file1 = $folder1->newFile('bar1');

View File

@ -50,24 +50,24 @@ abstract class TestCase extends \Test\TestCase {
// create users
$backend = new \Test\Util\User\Dummy();
\OC_User::useBackend($backend);
$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($this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1);
$backend->createUser($this->TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2);
}
protected function setUp(): void {
parent::setUp();
//login as user1
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
}
public static function tearDownAfterClass(): void {
// cleanup users
$user = \OC::$server->getUserManager()->get(self::TEST_FILES_SHARING_API_USER1);
$user = \OC::$server->getUserManager()->get($this->TEST_FILES_SHARING_API_USER1);
if ($user !== null) {
$user->delete();
}
$user = \OC::$server->getUserManager()->get(self::TEST_FILES_SHARING_API_USER2);
$user = \OC::$server->getUserManager()->get($this->TEST_FILES_SHARING_API_USER2);
if ($user !== null) {
$user->delete();
}

View File

@ -91,7 +91,7 @@ class ApiTest extends TestCase {
$mount = $this->view->getMount($this->filename);
$mount->getStorage()->getScanner()->scan('', Scanner::SCAN_RECURSIVE);
$this->userFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$this->userFolder = \OC::$server->getUserFolder($this->TEST_FILES_SHARING_API_USER1);
}
protected function tearDown(): void {
@ -141,8 +141,8 @@ class ApiTest extends TestCase {
public function testCreateShareUserFile() {
$this->setUp(); // for some reasons phpunit refuses to do this for us only for this test
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_USER, $this->TEST_FILES_SHARING_API_USER2);
$ocs->cleanup();
$data = $result->getData();
@ -151,15 +151,15 @@ class ApiTest extends TestCase {
$this->shareManager->getShareById('ocinternal:'.$data['id']);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
}
public function testCreateShareUserFolder() {
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_USER, $this->TEST_FILES_SHARING_API_USER2);
$ocs->cleanup();
$data = $result->getData();
@ -168,14 +168,14 @@ class ApiTest extends TestCase {
$this->shareManager->getShareById('ocinternal:'.$data['id']);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
}
public function testCreateShareGroupFile() {
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1);
$ocs->cleanup();
@ -185,13 +185,13 @@ class ApiTest extends TestCase {
$this->shareManager->getShareById('ocinternal:'.$data['id']);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
}
public function testCreateShareGroupFolder() {
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1);
$ocs->cleanup();
@ -201,13 +201,13 @@ class ApiTest extends TestCase {
$this->shareManager->getShareById('ocinternal:'.$data['id']);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
}
public function testCreateShareLink() {
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK);
$ocs->cleanup();
@ -224,13 +224,13 @@ class ApiTest extends TestCase {
$this->shareManager->getShareById('ocinternal:'.$data['id']);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
}
public function testCreateShareLinkPublicUpload() {
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'true');
$ocs->cleanup();
@ -252,7 +252,7 @@ class ApiTest extends TestCase {
$this->shareManager->getShareById('ocinternal:'.$data['id']);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
}
@ -262,7 +262,7 @@ class ApiTest extends TestCase {
$config = \OC::$server->getConfig();
$config->setAppValue('core', 'shareapi_enforce_links_password', 'yes');
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
try {
$ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK);
$this->fail();
@ -270,7 +270,7 @@ class ApiTest extends TestCase {
}
$ocs->cleanup();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
try {
$ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', '');
$this->fail();
@ -279,19 +279,19 @@ class ApiTest extends TestCase {
$ocs->cleanup();
// share with password should succeed
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', $password);
$ocs->cleanup();
$data = $result->getData();
// setting new password should succeed
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->updateShare($data['id'], null, $password);
$ocs->cleanup();
// removing password should fail
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
try {
$ocs->updateShare($data['id']);
$this->fail();
@ -300,7 +300,7 @@ class ApiTest extends TestCase {
$ocs->cleanup();
// cleanup
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
@ -316,15 +316,15 @@ class ApiTest extends TestCase {
// to no
\OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups', 'no');
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_USER, $this->TEST_FILES_SHARING_API_USER2);
$ocs->cleanup();
$data = $result->getData();
$this->shareManager->getShareById('ocinternal:'.$data['id']);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
@ -332,23 +332,23 @@ class ApiTest extends TestCase {
\OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups', 'yes');
\OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups_list', 'admin,group1,group2');
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_USER, $this->TEST_FILES_SHARING_API_USER2);
$ocs->cleanup();
$data = $result->getData();
$this->shareManager->getShareById('ocinternal:' . $data['id']);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($data['id']);
$ocs->cleanup();
// now we exclude the group the user belongs to ('group'), sharing should fail now
\OC::$server->getConfig()->setAppValue('core', 'shareapi_exclude_groups_list', 'admin,group');
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_USER, $this->TEST_FILES_SHARING_API_USER2);
$ocs->cleanup();
// cleanup
@ -367,14 +367,14 @@ class ApiTest extends TestCase {
$share = $this->shareManager->newShare();
$share->setNode($node)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(19);
$share = $this->shareManager->createShare($share);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();
@ -387,8 +387,8 @@ class ApiTest extends TestCase {
$node1 = $this->userFolder->get($this->filename);
$share1 = $this->shareManager->newShare();
$share1->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(19);
$share1 = $this->shareManager->createShare($share1);
@ -398,15 +398,15 @@ class ApiTest extends TestCase {
$node2 = $this->userFolder->get($this->folder);
$share2 = $this->shareManager->newShare();
$share2->setNode($node2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(31);
$share2 = $this->shareManager->createShare($share2);
$share2->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share2);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER2);
$result = $ocs->getShares('true');
$ocs->cleanup();
@ -420,7 +420,7 @@ class ApiTest extends TestCase {
* @medium
*/
public function testPublicLinkUrl() {
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK);
$ocs->cleanup();
@ -435,7 +435,7 @@ class ApiTest extends TestCase {
$this->assertEquals($url, $data['url']);
// check for link in getall shares
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();
@ -443,7 +443,7 @@ class ApiTest extends TestCase {
$this->assertEquals($url, current($data)['url']);
// check for path
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();
@ -451,14 +451,14 @@ class ApiTest extends TestCase {
$this->assertEquals($url, current($data)['url']);
// check in share id
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShare($id);
$ocs->cleanup();
$data = $result->getData();
$this->assertEquals($url, current($data)['url']);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($id);
$ocs->cleanup();
}
@ -472,20 +472,20 @@ class ApiTest extends TestCase {
$node = $this->userFolder->get($this->filename);
$share = $this->shareManager->newShare();
$share->setNode($node)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(19);
$share1 = $this->shareManager->createShare($share);
$share = $this->shareManager->newShare();
$share->setNode($node)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
$share2 = $this->shareManager->createShare($share);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();
@ -505,21 +505,21 @@ class ApiTest extends TestCase {
$node = $this->userFolder->get($this->filename);
$share1 = $this->shareManager->newShare();
$share1->setNode($node)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(19);
$share1 = $this->shareManager->createShare($share1);
$share2 = $this->shareManager->newShare();
$share2->setNode($node)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
->setSharedBy($this->TEST_FILES_SHARING_API_USER2)
->setSharedWith($this->TEST_FILES_SHARING_API_USER3)
->setShareType(IShare::TYPE_USER)
->setPermissions(19);
$share2 = $this->shareManager->createShare($share2);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();
@ -527,7 +527,7 @@ class ApiTest extends TestCase {
$this->assertTrue(count($result->getData()) === 1);
// now also ask for the reshares
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares('false', 'true', 'false', $this->filename);
$ocs->cleanup();
@ -546,14 +546,14 @@ class ApiTest extends TestCase {
$node = $this->userFolder->get($this->filename);
$share1 = $this->shareManager->newShare();
$share1->setNode($node)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(19);
$share1 = $this->shareManager->createShare($share1);
// call getShare() with share ID
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShare($share1->getId());
$ocs->cleanup();
@ -570,8 +570,8 @@ class ApiTest extends TestCase {
$node1 = $this->userFolder->get($this->filename);
$share1 = $this->shareManager->newShare();
$share1->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(19);
$share1 = $this->shareManager->createShare($share1);
@ -579,13 +579,13 @@ class ApiTest extends TestCase {
$node2 = $this->userFolder->get($this->folder.'/'.$this->filename);
$share2 = $this->shareManager->newShare();
$share2->setNode($node2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
$share2 = $this->shareManager->createShare($share2);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares('false', 'false', 'true', $this->folder);
$ocs->cleanup();
@ -600,13 +600,13 @@ class ApiTest extends TestCase {
$node1 = $this->userFolder->get($this->filename);
$share1 = $this->shareManager->newShare();
$share1->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(19);
$share1 = $this->shareManager->createShare($share1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
try {
$ocs->getShares('false', 'false', 'true', $this->filename);
$this->fail();
@ -626,8 +626,8 @@ class ApiTest extends TestCase {
$node1 = $this->userFolder->get($this->folder);
$share1 = $this->shareManager->newShare();
$share1->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(31);
$share1 = $this->shareManager->createShare($share1);
@ -637,7 +637,7 @@ class ApiTest extends TestCase {
$node2 = $this->userFolder->get($this->folder.'/'.$this->filename);
$share2 = $this->shareManager->newShare();
$share2->setNode($node2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
$share2 = $this->shareManager->createShare($share2);
@ -647,7 +647,7 @@ class ApiTest extends TestCase {
$node3 = $this->userFolder->get($this->folder.'/'.$this->subfolder.'/'.$this->filename);
$share3 = $this->shareManager->newShare();
$share3->setNode($node3)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
$share3 = $this->shareManager->createShare($share3);
@ -662,7 +662,7 @@ class ApiTest extends TestCase {
];
foreach ($testValues as $value) {
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER2);
$result = $ocs->getShares('false', 'false', 'true', $value['query']);
$ocs->cleanup();
@ -686,25 +686,25 @@ class ApiTest extends TestCase {
$node1 = $this->userFolder->get($this->folder . $this->subfolder);
$share1 = $this->shareManager->newShare();
$share1->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(31);
$share1 = $this->shareManager->createShare($share1);
$share1->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share1);
$node2 = \OC::$server->getRootFolder()->getUserFolder(self::TEST_FILES_SHARING_API_USER2)->get($this->subfolder);
$node2 = \OC::$server->getRootFolder()->getUserFolder($this->TEST_FILES_SHARING_API_USER2)->get($this->subfolder);
$share2 = $this->shareManager->newShare();
$share2->setNode($node2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
$share2 = $this->shareManager->createShare($share2);
$share2->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share2);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER2);
$result = $ocs->getShares();
$ocs->cleanup();
@ -728,8 +728,8 @@ class ApiTest extends TestCase {
$node1 = $this->userFolder->get($this->folder . $this->subfolder);
$share1 = $this->shareManager->newShare();
$share1->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(31);
$share1 = $this->shareManager->createShare($share1);
@ -737,15 +737,15 @@ class ApiTest extends TestCase {
$node2 = $this->userFolder->get($this->folder . $this->subfolder . $this->subsubfolder);
$share2 = $this->shareManager->newShare();
$share2->setNode($node2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
->setSharedBy($this->TEST_FILES_SHARING_API_USER2)
->setSharedWith($this->TEST_FILES_SHARING_API_USER3)
->setShareType(IShare::TYPE_USER)
->setPermissions(31);
$share2 = $this->shareManager->createShare($share2);
$share3 = $this->shareManager->newShare();
$share3->setNode($node2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER3)
->setSharedBy($this->TEST_FILES_SHARING_API_USER3)
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
$share3 = $this->shareManager->createShare($share3);
@ -753,7 +753,7 @@ class ApiTest extends TestCase {
/*
* Test as recipient
*/
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER3);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER3);
$result = $ocs->getShares();
$ocs->cleanup();
@ -767,7 +767,7 @@ class ApiTest extends TestCase {
/*
* Test for first owner/initiator
*/
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();
@ -781,7 +781,7 @@ class ApiTest extends TestCase {
/*
* Test for second initiator
*/
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER2);
$result = $ocs->getShares();
$ocs->cleanup();
@ -806,8 +806,8 @@ class ApiTest extends TestCase {
$node1 = $this->userFolder->get($this->folder . $this->subfolder);
$share1 = $this->shareManager->newShare();
$share1->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(31);
$share1 = $this->shareManager->createShare($share1);
@ -817,8 +817,8 @@ class ApiTest extends TestCase {
$node2 = $this->userFolder->get($this->folder);
$share2 = $this->shareManager->newShare();
$share2->setNode($node2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(31);
$share2 = $this->shareManager->createShare($share2);
@ -827,7 +827,7 @@ class ApiTest extends TestCase {
$share3 = $this->shareManager->newShare();
$share3->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
$share3 = $this->shareManager->createShare($share3);
@ -835,7 +835,7 @@ class ApiTest extends TestCase {
$this->shareManager->updateShare($share3);
// $request = $this->createRequest(['path' => $this->subfolder]);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER2);
$result1 = $ocs->getShares('false','false','false', $this->subfolder);
$ocs->cleanup();
@ -845,7 +845,7 @@ class ApiTest extends TestCase {
$s1 = reset($data1);
//$request = $this->createRequest(['path' => $this->folder.$this->subfolder]);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER2);
$result2 = $ocs->getShares('false', 'false', 'false', $this->folder . $this->subfolder);
$ocs->cleanup();
@ -870,38 +870,38 @@ class ApiTest extends TestCase {
$node1 = $this->userFolder->get($this->folder . $this->subfolder);
$share1 = $this->shareManager->newShare();
$share1->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(31);
$share1 = $this->shareManager->createShare($share1);
$share1->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share1);
$user2Folder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER2);
$user2Folder = \OC::$server->getUserFolder($this->TEST_FILES_SHARING_API_USER2);
$node2 = $user2Folder->get($this->subfolder . $this->filename);
$share2 = $this->shareManager->newShare();
$share2->setNode($node2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
->setSharedBy($this->TEST_FILES_SHARING_API_USER2)
->setSharedWith($this->TEST_FILES_SHARING_API_USER3)
->setShareType(IShare::TYPE_USER)
->setPermissions(19);
$share2 = $this->shareManager->createShare($share2);
$share2->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share2);
$user3Folder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER3);
$user3Folder = \OC::$server->getUserFolder($this->TEST_FILES_SHARING_API_USER3);
$node3 = $user3Folder->get($this->filename);
$share3 = $this->shareManager->newShare();
$share3->setNode($node3)
->setSharedBy(self::TEST_FILES_SHARING_API_USER3)
->setSharedBy($this->TEST_FILES_SHARING_API_USER3)
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
$share3 = $this->shareManager->createShare($share3);
$share3->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share3);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER3);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER3);
$result = $ocs->getShares();
$ocs->cleanup();
@ -922,7 +922,7 @@ class ApiTest extends TestCase {
* @medium
*/
public function testGetShareFromUnknownId() {
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER3);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER3);
try {
$ocs->getShare(0);
$this->fail();
@ -943,21 +943,21 @@ class ApiTest extends TestCase {
$node1 = $this->userFolder->get($this->filename);
$share1 = $this->shareManager->newShare();
$share1->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(19);
$share1 = $this->shareManager->createShare($share1);
$share2 = $this->shareManager->newShare();
$share2->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
$share2 = $this->shareManager->createShare($share2);
// update permissions
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->updateShare($share1->getId(), 1);
$ocs->cleanup();
@ -967,14 +967,14 @@ class ApiTest extends TestCase {
// update password for link share
$this->assertNull($share2->getPassword());
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->updateShare($share2->getId(), null, $password);
$ocs->cleanup();
$share2 = $this->shareManager->getShareById('ocinternal:' . $share2->getId());
$this->assertNotNull($share2->getPassword());
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->updateShare($share2->getId(), null, '');
$ocs->cleanup();
@ -992,13 +992,13 @@ class ApiTest extends TestCase {
$node1 = $this->userFolder->get($this->folder);
$share1 = $this->shareManager->newShare();
$share1->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
$share1 = $this->shareManager->createShare($share1);
// update public upload
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->updateShare($share1->getId(), null, null, null, 'true');
$ocs->cleanup();
@ -1023,7 +1023,7 @@ class ApiTest extends TestCase {
$node1 = $this->userFolder->get($this->folder);
$share1 = $this->shareManager->newShare();
$share1->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
$share1 = $this->shareManager->createShare($share1);
@ -1044,7 +1044,7 @@ class ApiTest extends TestCase {
$dateOutOfRange->add(new \DateInterval('P8D'));
// update expire date to a valid value
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->updateShare($share1->getId(), null, null, null, null, $dateWithinRange->format('Y-m-d'));
$ocs->cleanup();
@ -1054,7 +1054,7 @@ class ApiTest extends TestCase {
$this->assertEquals($dateWithinRange, $share1->getExpirationDate());
// update expire date to a value out of range
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
try {
$ocs->updateShare($share1->getId());
$this->fail();
@ -1068,7 +1068,7 @@ class ApiTest extends TestCase {
$this->assertEquals($dateWithinRange, $share1->getExpirationDate());
// Try to remove expire date
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
try {
$ocs->updateShare($share1->getId());
$this->fail();
@ -1095,29 +1095,29 @@ class ApiTest extends TestCase {
$node1 = $this->userFolder->get($this->filename);
$share1 = $this->shareManager->newShare();
$share1->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(19);
$share1 = $this->shareManager->createShare($share1);
$share2 = $this->shareManager->newShare();
$share2->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
$share2 = $this->shareManager->createShare($share1);
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($share1->getId());
$ocs->cleanup();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($share2->getId());
$ocs->cleanup();
$this->assertEmpty($this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER2, IShare::TYPE_USER));
$this->assertEmpty($this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER2, IShare::TYPE_LINK));
$this->assertEmpty($this->shareManager->getSharesBy($this->TEST_FILES_SHARING_API_USER2, IShare::TYPE_USER));
$this->assertEmpty($this->shareManager->getSharesBy($this->TEST_FILES_SHARING_API_USER2, IShare::TYPE_LINK));
}
/**
@ -1127,19 +1127,19 @@ class ApiTest extends TestCase {
$node1 = $this->userFolder->get($this->folder);
$share1 = $this->shareManager->newShare();
$share1->setNode($node1)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_USER)
->setPermissions(31);
$share1 = $this->shareManager->createShare($share1);
$share1->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share1);
$user2folder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER2);
$user2folder = \OC::$server->getUserFolder($this->TEST_FILES_SHARING_API_USER2);
$node2 = $user2folder->get($this->folder.'/'.$this->filename);
$share2 = $this->shareManager->newShare();
$share2->setNode($node2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER2)
->setShareType(IShare::TYPE_LINK)
->setPermissions(1);
$share2 = $this->shareManager->createShare($share2);
@ -1147,7 +1147,7 @@ class ApiTest extends TestCase {
$this->shareManager->updateShare($share2);
// test if we can unshare the link again
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER2);
$ocs->deleteShare($share2->getId());
$ocs->cleanup();
@ -1160,22 +1160,22 @@ class ApiTest extends TestCase {
*/
public function testShareFolderWithAMountPoint() {
// user 1 shares a folder with user2
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL
);
$share->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share);
// user2 shares a file from the folder as link
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
$view = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
$view->mkdir("localDir");
// move mount point to the folder "localDir"
@ -1192,8 +1192,8 @@ class ApiTest extends TestCase {
$this->share(
IShare::TYPE_USER,
'localDir',
self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3,
$this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3,
\OCP\Constants::PERMISSION_ALL
);
} catch (\Exception $e) {
@ -1208,7 +1208,7 @@ class ApiTest extends TestCase {
$this->assertTrue($result !== false);
$view->unlink('localDir');
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->shareManager->deleteShare($share);
}
@ -1217,8 +1217,8 @@ class ApiTest extends TestCase {
* Post init mount points hook for mounting simulated ext storage
*/
public static function initTestMountPointsHook($data) {
if ($data['user'] === self::TEST_FILES_SHARING_API_USER1) {
\OC\Files\Filesystem::mount(self::$tempStorage, [], '/' . self::TEST_FILES_SHARING_API_USER1 . '/files' . self::TEST_FOLDER_NAME);
if ($data['user'] === $this->TEST_FILES_SHARING_API_USER1) {
\OC\Files\Filesystem::mount(self::$tempStorage, [], '/' . $this->TEST_FILES_SHARING_API_USER1 . '/files' . self::TEST_FOLDER_NAME);
}
}
@ -1230,31 +1230,31 @@ class ApiTest extends TestCase {
$tempStorage->file_put_contents('test.txt', 'abcdef');
$tempStorage->getScanner()->scan('');
$this->registerMount(self::TEST_FILES_SHARING_API_USER1, $tempStorage, self::TEST_FILES_SHARING_API_USER1 . '/files' . self::TEST_FOLDER_NAME);
$this->registerMount($this->TEST_FILES_SHARING_API_USER1, $tempStorage, $this->TEST_FILES_SHARING_API_USER1 . '/files' . self::TEST_FOLDER_NAME);
// logging in will auto-mount the temp storage for user1 as well
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
// user 1 shares the mount point folder with user2
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL
);
$share->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share);
// user2: check that mount point name appears correctly
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
$view = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
$this->assertTrue($view->file_exists($this->folder));
$this->assertTrue($view->file_exists($this->folder . '/test.txt'));
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->shareManager->deleteShare($share);
@ -1279,7 +1279,7 @@ class ApiTest extends TestCase {
* @dataProvider datesProvider
*/
public function testPublicLinkExpireDate($date, $valid) {
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
try {
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', '', null, $date);
@ -1317,7 +1317,7 @@ class ApiTest extends TestCase {
$date = new \DateTime();
$date->add(new \DateInterval('P5D'));
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', '', null, $date->format('Y-m-d'));
$ocs->cleanup();
@ -1349,7 +1349,7 @@ class ApiTest extends TestCase {
$date = new \DateTime();
$date->add(new \DateInterval('P8D'));
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
try {
$ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', '', null, $date->format('Y-m-d'));
@ -1370,7 +1370,7 @@ class ApiTest extends TestCase {
$date = new \DateTime();
$date->sub(new \DateInterval('P8D'));
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
try {
$ocs->createShare($this->filename, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK, null, 'false', '', null, $date->format('Y-m-d'));
@ -1391,26 +1391,26 @@ class ApiTest extends TestCase {
*/
public function testInvisibleSharesUser() {
// simulate a post request
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_USER, $this->TEST_FILES_SHARING_API_USER2);
$ocs->cleanup();
$data = $result->getData();
$topId = $data['id'];
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER2);
$ocs->acceptShare($topId);
$ocs->cleanup();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER2);
$ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK);
$ocs->cleanup();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($topId);
$ocs->cleanup();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();
@ -1423,28 +1423,28 @@ class ApiTest extends TestCase {
*/
public function testInvisibleSharesGroup() {
// simulate a post request
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_GROUP, self::TEST_FILES_SHARING_API_GROUP1);
$ocs->cleanup();
$data = $result->getData();
$topId = $data['id'];
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER2);
$ocs->acceptShare($topId);
$ocs->cleanup();
\OC_Util::tearDownFS();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER2);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER2);
$ocs->createShare($this->folder, \OCP\Constants::PERMISSION_ALL, IShare::TYPE_LINK);
$ocs->cleanup();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$ocs->deleteShare($topId);
$ocs->cleanup();
$ocs = $this->createOCS(self::TEST_FILES_SHARING_API_USER1);
$ocs = $this->createOCS($this->TEST_FILES_SHARING_API_USER1);
$result = $ocs->getShares();
$ocs->cleanup();

View File

@ -69,12 +69,12 @@ class CacheTest extends TestCase {
$userManager = \OC::$server->getUserManager();
$userManager->get(self::TEST_FILES_SHARING_API_USER1)->setDisplayName('User One');
$userManager->get(self::TEST_FILES_SHARING_API_USER2)->setDisplayName('User Two');
$userManager->get($this->TEST_FILES_SHARING_API_USER1)->setDisplayName('User One');
$userManager->get($this->TEST_FILES_SHARING_API_USER2)->setDisplayName('User Two');
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->user2View = new \OC\Files\View('/'. self::TEST_FILES_SHARING_API_USER2 . '/files');
$this->user2View = new \OC\Files\View('/'. $this->TEST_FILES_SHARING_API_USER2 . '/files');
// prepare user1's dir structure
$this->view->mkdir('container');
@ -95,14 +95,14 @@ class CacheTest extends TestCase {
$this->ownerStorage->getScanner()->scan('');
// share "shareddir" with user2
$rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$rootFolder = \OC::$server->getUserFolder($this->TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('container/shareddir');
$share = $this->shareManager->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED);
@ -112,18 +112,18 @@ class CacheTest extends TestCase {
$share = $this->shareManager->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE));
$share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share);
// login as user2
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
// retrieve the shared storage
$secondView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
$secondView = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2);
[$this->sharedStorage,] = $secondView->resolvePath('files/shareddir');
$this->sharedCache = $this->sharedStorage->getCache();
}
@ -133,9 +133,9 @@ class CacheTest extends TestCase {
$this->sharedCache->clear();
}
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$shares = $this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER);
$shares = $this->shareManager->getSharesBy($this->TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER);
foreach ($shares as $share) {
$this->shareManager->deleteShare($share);
}
@ -259,14 +259,14 @@ class CacheTest extends TestCase {
'name' => 'shareddir',
'path' => 'files/shareddir',
'mimetype' => 'httpd/unix-directory',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One',
],
[
'name' => 'shared single file.txt',
'path' => 'files/shared single file.txt',
'mimetype' => 'text/plain',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One',
],
],
@ -283,21 +283,21 @@ class CacheTest extends TestCase {
'name' => 'bar.txt',
'path' => 'bar.txt',
'mimetype' => 'text/plain',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One',
],
[
'name' => 'emptydir',
'path' => 'emptydir',
'mimetype' => 'httpd/unix-directory',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One',
],
[
'name' => 'subdir',
'path' => 'subdir',
'mimetype' => 'httpd/unix-directory',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One',
],
],
@ -306,23 +306,23 @@ class CacheTest extends TestCase {
}
public function testGetFolderContentsWhenSubSubdirShared() {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$rootFolder = \OC::$server->getUserFolder($this->TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('container/shareddir/subdir');
$share = $this->shareManager->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER3)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share);
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
self::loginHelper($this->TEST_FILES_SHARING_API_USER3);
$thirdView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
$thirdView = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER3 . '/files');
$results = $thirdView->getDirectoryContent('/subdir');
$this->verifyFiles(
@ -331,28 +331,28 @@ class CacheTest extends TestCase {
'name' => 'another too.txt',
'path' => 'another too.txt',
'mimetype' => 'text/plain',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One',
],
[
'name' => 'another.txt',
'path' => 'another.txt',
'mimetype' => 'text/plain',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One',
],
[
'name' => 'not a text file.xml',
'path' => 'not a text file.xml',
'mimetype' => 'application/xml',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One',
],
],
$results
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->shareManager->deleteShare($share);
}
@ -390,17 +390,17 @@ class CacheTest extends TestCase {
}
public function testGetPathByIdDirectShare() {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
\OC\Files\Filesystem::file_put_contents('test.txt', 'foo');
$info = \OC\Files\Filesystem::getFileInfo('test.txt');
$rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$rootFolder = \OC::$server->getUserFolder($this->TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('test.txt');
$share = $this->shareManager->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
$share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED);
@ -408,9 +408,9 @@ class CacheTest extends TestCase {
\OC_Util::tearDownFS();
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$this->assertTrue(\OC\Files\Filesystem::file_exists('/test.txt'));
[$sharedStorage] = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/test.txt');
[$sharedStorage] = \OC\Files\Filesystem::resolvePath('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/test.txt');
/**
* @var \OCA\Files_Sharing\SharedStorage $sharedStorage
*/
@ -420,29 +420,29 @@ class CacheTest extends TestCase {
}
public function testGetPathByIdShareSubFolder() {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
\OC\Files\Filesystem::mkdir('foo');
\OC\Files\Filesystem::mkdir('foo/bar');
\OC\Files\Filesystem::touch('foo/bar/test.txt');
$folderInfo = \OC\Files\Filesystem::getFileInfo('foo');
$fileInfo = \OC\Files\Filesystem::getFileInfo('foo/bar/test.txt');
$rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$rootFolder = \OC::$server->getUserFolder($this->TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('foo');
$share = $this->shareManager->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share);
\OC_Util::tearDownFS();
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$this->assertTrue(\OC\Files\Filesystem::file_exists('/foo'));
[$sharedStorage] = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/foo');
[$sharedStorage] = \OC\Files\Filesystem::resolvePath('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/foo');
/**
* @var \OCA\Files_Sharing\SharedStorage $sharedStorage
*/
@ -453,28 +453,28 @@ class CacheTest extends TestCase {
}
public function testNumericStorageId() {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
\OC\Files\Filesystem::mkdir('foo');
$rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$rootFolder = \OC::$server->getUserFolder($this->TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('foo');
$share = $this->shareManager->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share);
\OC_Util::tearDownFS();
[$sourceStorage] = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/foo');
[$sourceStorage] = \OC\Files\Filesystem::resolvePath('/' . $this->TEST_FILES_SHARING_API_USER1 . '/files/foo');
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$this->assertTrue(\OC\Files\Filesystem::file_exists('/foo'));
/** @var SharedStorage $sharedStorage */
[$sharedStorage] = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/foo');
[$sharedStorage] = \OC\Files\Filesystem::resolvePath('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/foo');
$this->assertEquals($sourceStorage->getCache()->getNumericStorageId(), $sharedStorage->getCache()->getNumericStorageId());
}
@ -489,29 +489,29 @@ class CacheTest extends TestCase {
'root' => 'jail'
]);
$sourceStorage->getScanner()->scan('');
$this->registerMount(self::TEST_FILES_SHARING_API_USER1, $jailedSource, '/' . self::TEST_FILES_SHARING_API_USER1 . '/files/foo');
$this->registerMount($this->TEST_FILES_SHARING_API_USER1, $jailedSource, '/' . $this->TEST_FILES_SHARING_API_USER1 . '/files/foo');
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$rootFolder = \OC::$server->getUserFolder($this->TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('foo/sub');
$share = $this->shareManager->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share);
\OC_Util::tearDownFS();
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$this->assertEquals('foo', \OC\Files\Filesystem::file_get_contents('/sub/foo.txt'));
\OC\Files\Filesystem::file_put_contents('/sub/bar.txt', 'bar');
/** @var SharedStorage $sharedStorage */
[$sharedStorage] = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub');
[$sharedStorage] = \OC\Files\Filesystem::resolvePath('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/sub');
$this->assertTrue($sharedStorage->getCache()->inCache('bar.txt'));
@ -528,27 +528,27 @@ class CacheTest extends TestCase {
'root' => 'jail'
]);
$sourceStorage->getScanner()->scan('');
$this->registerMount(self::TEST_FILES_SHARING_API_USER1, $jailedSource, '/' . self::TEST_FILES_SHARING_API_USER1 . '/files/foo');
$this->registerMount($this->TEST_FILES_SHARING_API_USER1, $jailedSource, '/' . $this->TEST_FILES_SHARING_API_USER1 . '/files/foo');
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$rootFolder = \OC::$server->getUserFolder($this->TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('foo/sub');
$share = $this->shareManager->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share);
\OC_Util::tearDownFS();
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
/** @var SharedStorage $sharedStorage */
[$sharedStorage] = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub');
[$sharedStorage] = \OC\Files\Filesystem::resolvePath('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/sub');
$results = $sharedStorage->getCache()->search("foo.txt");
$this->assertCount(1, $results);

View File

@ -50,17 +50,17 @@ class EtagPropagationTest extends PropagationTestCase {
* "user4" puts the received "inside" folder into "sub1/sub2/inside" (this is to check if it propagates across multiple subfolders)
*/
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->fileIds[$this->TEST_FILES_SHARING_API_USER1] = [];
$this->fileIds[$this->TEST_FILES_SHARING_API_USER2] = [];
$this->fileIds[$this->TEST_FILES_SHARING_API_USER3] = [];
$this->fileIds[$this->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');
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER1);
$view1 = new View('/' . $this->TEST_FILES_SHARING_API_USER1 . '/files');
$view1->mkdir('/sub1/sub2/folder/inside');
$view1->mkdir('/directReshare');
$view1->mkdir('/sub1/sub2/folder/other');
@ -72,117 +72,117 @@ class EtagPropagationTest extends PropagationTestCase {
$fileInfo = $view1->getFileInfo('/foo.txt');
$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo);
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1)
$node = $rootFolder->getUserFolder($this->TEST_FILES_SHARING_API_USER1)
->get('/foo.txt');
$share = $shareManager->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
$share = $shareManager->createShare($share);
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2);
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1)
$this->shareManager->acceptShare($share, $this->TEST_FILES_SHARING_API_USER2);
$node = $rootFolder->getUserFolder($this->TEST_FILES_SHARING_API_USER1)
->get('/sub1/sub2/folder');
$share = $shareManager->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $shareManager->createShare($share);
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2);
$this->shareManager->acceptShare($share, $this->TEST_FILES_SHARING_API_USER2);
$share = $shareManager->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER3)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $shareManager->createShare($share);
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER3);
$this->shareManager->acceptShare($share, $this->TEST_FILES_SHARING_API_USER3);
$folderInfo = $view1->getFileInfo('/directReshare');
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1)
$node = $rootFolder->getUserFolder($this->TEST_FILES_SHARING_API_USER1)
->get('/directReshare');
$share = $shareManager->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $shareManager->createShare($share);
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2);
$this->shareManager->acceptShare($share, $this->TEST_FILES_SHARING_API_USER2);
$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->fileIds[$this->TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId();
$this->fileIds[$this->TEST_FILES_SHARING_API_USER1]['sub1'] = $view1->getFileInfo('sub1')->getId();
$this->fileIds[$this->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');
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER2);
$view2 = new View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
$view2->mkdir('/sub1/sub2');
$view2->rename('/folder', '/sub1/sub2/folder');
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER2);
$insideInfo = $view2->getFileInfo('/sub1/sub2/folder/inside');
$this->assertInstanceOf('\OC\Files\FileInfo', $insideInfo);
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER2)
$node = $rootFolder->getUserFolder($this->TEST_FILES_SHARING_API_USER2)
->get('/sub1/sub2/folder/inside');
$share = $shareManager->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER4)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
->setSharedWith($this->TEST_FILES_SHARING_API_USER4)
->setSharedBy($this->TEST_FILES_SHARING_API_USER2)
->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $shareManager->createShare($share);
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER4);
$this->shareManager->acceptShare($share, $this->TEST_FILES_SHARING_API_USER4);
$folderInfo = $view2->getFileInfo('/directReshare');
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER2)
$node = $rootFolder->getUserFolder($this->TEST_FILES_SHARING_API_USER2)
->get('/directReshare');
$share = $shareManager->newShare();
$share->setNode($node)
->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER4)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2)
->setSharedWith($this->TEST_FILES_SHARING_API_USER4)
->setSharedBy($this->TEST_FILES_SHARING_API_USER2)
->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $shareManager->createShare($share);
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER4);
$this->shareManager->acceptShare($share, $this->TEST_FILES_SHARING_API_USER4);
$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->fileIds[$this->TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId();
$this->fileIds[$this->TEST_FILES_SHARING_API_USER2]['sub1'] = $view2->getFileInfo('sub1')->getId();
$this->fileIds[$this->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');
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER3);
$view3 = new View('/' . $this->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->fileIds[$this->TEST_FILES_SHARING_API_USER3][''] = $view3->getFileInfo('')->getId();
$this->fileIds[$this->TEST_FILES_SHARING_API_USER3]['sub1'] = $view3->getFileInfo('sub1')->getId();
$this->fileIds[$this->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');
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER4);
$view4 = new View('/' . $this->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();
$this->fileIds[$this->TEST_FILES_SHARING_API_USER4][''] = $view4->getFileInfo('')->getId();
$this->fileIds[$this->TEST_FILES_SHARING_API_USER4]['sub1'] = $view4->getFileInfo('sub1')->getId();
$this->fileIds[$this->TEST_FILES_SHARING_API_USER4]['sub1/sub2'] = $view4->getFileInfo('sub1/sub2')->getId();
foreach ($this->fileIds as $user => $ids) {
$this->loginAsUser($user);
@ -195,122 +195,122 @@ class EtagPropagationTest extends PropagationTestCase {
}
public function testOwnerWritesToShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$this->loginAsUser($this->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->assertEtagsNotChanged([$this->TEST_FILES_SHARING_API_USER4]);
$this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3]);
$this->assertAllUnchanged();
}
public function testOwnerWritesToSingleFileShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER1);
Filesystem::file_put_contents('/foo.txt', 'longer_bar');
$t = (int)Filesystem::filemtime('/foo.txt') - 1;
Filesystem::touch('/foo.txt', $t);
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER4, self::TEST_FILES_SHARING_API_USER3]);
$this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2]);
$this->assertEtagsNotChanged([$this->TEST_FILES_SHARING_API_USER4, $this->TEST_FILES_SHARING_API_USER3]);
$this->assertEtagsChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2]);
$this->assertAllUnchanged();
}
public function testOwnerWritesToShareWithReshare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$this->loginAsUser($this->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->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged();
}
public function testOwnerRenameInShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER4]);
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER1);
$this->assertEtagsNotChanged([$this->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->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3]);
$this->assertAllUnchanged();
}
public function testOwnerRenameInReShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$this->loginAsUser($this->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->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged();
}
public function testOwnerRenameIntoReShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$this->loginAsUser($this->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->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged();
}
public function testOwnerRenameOutOfReShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$this->loginAsUser($this->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->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged();
}
public function testOwnerDeleteInShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$this->loginAsUser($this->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->assertEtagsNotChanged([$this->TEST_FILES_SHARING_API_USER4]);
$this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3]);
$this->assertAllUnchanged();
}
public function testOwnerDeleteInReShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$this->loginAsUser($this->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->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged();
}
public function testOwnerUnshares() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$folderInfo = $this->rootView->getFileInfo('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder');
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER1);
$folderInfo = $this->rootView->getFileInfo('/' . $this->TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder');
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo);
$node = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder');
$node = \OC::$server->getUserFolder($this->TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder');
$shareManager = \OC::$server->getShareManager();
$shares = $shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER, $node, true);
$shares = $shareManager->getSharesBy($this->TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER, $node, true);
foreach ($shares as $share) {
if ($share->getSharedWith() === self::TEST_FILES_SHARING_API_USER2) {
if ($share->getSharedWith() === $this->TEST_FILES_SHARING_API_USER2) {
$shareManager->deleteShare($share);
}
}
$this->assertEtagsForFoldersChanged([
// direct recipient affected
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER2,
]);
$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->loginAsUser($this->TEST_FILES_SHARING_API_USER1);
$folderInfo = $this->rootView->getFileInfo('/' . $this->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');
$node = \OC::$server->getUserFolder($this->TEST_FILES_SHARING_API_USER1)->get('/sub1/sub2/folder/inside');
$shareManager = \OC::$server->getShareManager();
$shares = $shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER, $node, true);
$shares = $shareManager->getSharesBy($this->TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER, $node, true);
foreach ($shares as $share) {
$shareManager->deleteShare($share);
@ -318,150 +318,150 @@ class EtagPropagationTest extends PropagationTestCase {
$this->assertEtagsForFoldersChanged([
// direct recipient affected
self::TEST_FILES_SHARING_API_USER4,
$this->TEST_FILES_SHARING_API_USER4,
]);
$this->assertAllUnchanged();
}
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->loginAsUser($this->TEST_FILES_SHARING_API_USER2);
$ls = $this->rootView->getDirectoryContent('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/sub1/sub2/');
$this->assertTrue(
$this->rootView->unlink('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub1/sub2/folder')
$this->rootView->unlink('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/sub1/sub2/folder')
);
$this->assertEtagsForFoldersChanged([
// direct recipient affected
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER2,
]);
$this->assertAllUnchanged();
}
public function testRecipientWritesToShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER2);
Filesystem::file_put_contents('/sub1/sub2/folder/asd.txt', 'bar');
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER4]);
$this->assertEtagsNotChanged([$this->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->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3
]);
$this->assertAllUnchanged();
}
public function testRecipientWritesToReshare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$this->loginAsUser($this->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->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged();
}
public function testRecipientWritesToOtherRecipientsReshare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER3);
$this->loginAsUser($this->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->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged();
}
public function testRecipientRenameInShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$this->loginAsUser($this->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->assertEtagsNotChanged([$this->TEST_FILES_SHARING_API_USER4]);
$this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3]);
$this->assertAllUnchanged();
}
public function testRecipientRenameInReShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$this->loginAsUser($this->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->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged();
}
public function testRecipientRenameResharedFolder() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$this->loginAsUser($this->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->assertEtagsNotChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertEtagsChanged([$this->TEST_FILES_SHARING_API_USER2]);
$this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER2], 'sub1');
$this->assertEtagsChanged([$this->TEST_FILES_SHARING_API_USER2], 'sub1');
$this->assertAllUnchanged();
}
public function testRecipientDeleteInShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$this->loginAsUser($this->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->assertEtagsNotChanged([$this->TEST_FILES_SHARING_API_USER4]);
$this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3]);
$this->assertAllUnchanged();
}
public function testRecipientDeleteInReShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$this->loginAsUser($this->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->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged();
}
public function testReshareRecipientWritesToReshare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
$this->loginAsUser($this->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->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged();
}
public function testReshareRecipientRenameInReShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
$this->loginAsUser($this->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->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged();
}
public function testReshareRecipientDeleteInReShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
$this->loginAsUser($this->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->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged();
}
public function testRecipientUploadInDirectReshare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER2);
Filesystem::file_put_contents('/directReshare/test.txt', 'sad');
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER3]);
$this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_USER4]);
$this->assertEtagsNotChanged([$this->TEST_FILES_SHARING_API_USER3]);
$this->assertEtagsChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged();
}
public function testEtagChangeOnPermissionsChange() {
$userFolder = $this->rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
$userFolder = $this->rootFolder->getUserFolder($this->TEST_FILES_SHARING_API_USER1);
$node = $userFolder->get('/sub1/sub2/folder');
$shares = $this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER, $node);
$shares = $this->shareManager->getSharesBy($this->TEST_FILES_SHARING_API_USER1, IShare::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;
return $share->getSharedWith() === $this->TEST_FILES_SHARING_API_USER2;
});
$this->assertCount(1, $shares);
@ -469,7 +469,7 @@ class EtagPropagationTest extends PropagationTestCase {
$share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE);
$this->shareManager->updateShare($share);
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER2]);
$this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER2]);
$this->assertAllUnchanged();
}

View File

@ -43,62 +43,62 @@ class GroupEtagPropagationTest extends PropagationTestCase {
* "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->fileIds[$this->TEST_FILES_SHARING_API_USER1] = [];
$this->fileIds[$this->TEST_FILES_SHARING_API_USER2] = [];
$this->fileIds[$this->TEST_FILES_SHARING_API_USER3] = [];
$this->fileIds[$this->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');
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER1);
$view1 = new View('/' . $this->TEST_FILES_SHARING_API_USER1 . '/files');
$view1->mkdir('/test/sub');
$share = $this->share(
IShare::TYPE_GROUP,
'/test',
self::TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER1,
'group1',
\OCP\Constants::PERMISSION_ALL
);
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2);
$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->shareManager->acceptShare($share, $this->TEST_FILES_SHARING_API_USER2);
$this->fileIds[$this->TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId();
$this->fileIds[$this->TEST_FILES_SHARING_API_USER1]['test'] = $view1->getFileInfo('test')->getId();
$this->fileIds[$this->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');
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER2);
$view2 = new View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
$share = $this->share(
IShare::TYPE_GROUP,
'/test',
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER2,
'group2',
\OCP\Constants::PERMISSION_ALL
);
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER3);
$this->shareManager->acceptShare($share, $this->TEST_FILES_SHARING_API_USER3);
$share = $this->share(
IShare::TYPE_GROUP,
'/test/sub',
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER2,
'group3',
\OCP\Constants::PERMISSION_ALL
);
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER4);
$this->shareManager->acceptShare($share, $this->TEST_FILES_SHARING_API_USER4);
$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->fileIds[$this->TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId();
$this->fileIds[$this->TEST_FILES_SHARING_API_USER2]['test'] = $view2->getFileInfo('test')->getId();
$this->fileIds[$this->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($this->TEST_FILES_SHARING_API_USER3);
$view3 = new View('/' . $this->TEST_FILES_SHARING_API_USER3 . '/files');
$this->fileIds[$this->TEST_FILES_SHARING_API_USER3][''] = $view3->getFileInfo('')->getId();
$this->fileIds[$this->TEST_FILES_SHARING_API_USER3]['test'] = $view3->getFileInfo('test')->getId();
$this->fileIds[$this->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();
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER4);
$view4 = new View('/' . $this->TEST_FILES_SHARING_API_USER4 . '/files');
$this->fileIds[$this->TEST_FILES_SHARING_API_USER4][''] = $view4->getFileInfo('')->getId();
$this->fileIds[$this->TEST_FILES_SHARING_API_USER4]['sub'] = $view4->getFileInfo('sub')->getId();
foreach ($this->fileIds as $user => $ids) {
$this->loginAsUser($user);
@ -110,43 +110,43 @@ class GroupEtagPropagationTest extends PropagationTestCase {
}
public function testGroupReShareRecipientWrites() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER3);
$this->loginAsUser($this->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->assertEtagsChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged();
}
public function testGroupReShareSubFolderRecipientWrites() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER4);
$this->loginAsUser($this->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->assertEtagsChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged();
}
public function testRecipientUnsharesFromSelf() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER2);
$this->assertTrue(
$this->rootView->unlink('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/test')
$this->rootView->unlink('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/test')
);
$this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER2]);
$this->assertEtagsChanged([$this->TEST_FILES_SHARING_API_USER2]);
$this->assertAllUnchanged();
}
public function testRecipientUnsharesFromSelfUniqueGroupShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER2);
// rename to create an extra entry in the share table
$this->rootView->rename('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/test', '/' . self::TEST_FILES_SHARING_API_USER2 . '/files/test_renamed');
$this->rootView->rename('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/test', '/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/test_renamed');
$this->assertTrue(
$this->rootView->unlink('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/test_renamed')
$this->rootView->unlink('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/test_renamed')
);
$this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER2]);
$this->assertEtagsChanged([$this->TEST_FILES_SHARING_API_USER2]);
$this->assertAllUnchanged();
}

View File

@ -99,8 +99,8 @@ abstract class PropagationTestCase extends TestCase {
}
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];
$users = [$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4];
$this->assertEtagsNotChanged($users);
}
}

View File

@ -59,7 +59,7 @@ class ShareTest extends TestCase {
}
protected function tearDown(): void {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->view->unlink($this->filename);
$this->view->deleteAll($this->folder);
@ -73,43 +73,43 @@ class ShareTest extends TestCase {
$userManager = \OC::$server->getUserManager();
$testGroup = $groupManager->createGroup('testGroup');
$user1 = $userManager->get(self::TEST_FILES_SHARING_API_USER2);
$user2 = $userManager->get(self::TEST_FILES_SHARING_API_USER3);
$user1 = $userManager->get($this->TEST_FILES_SHARING_API_USER2);
$user2 = $userManager->get($this->TEST_FILES_SHARING_API_USER3);
$testGroup->addUser($user1);
$testGroup->addUser($user2);
$share1 = $this->share(
IShare::TYPE_USER,
$this->filename,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
);
$share2 = $this->share(
IShare::TYPE_GROUP,
$this->filename,
self::TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER1,
'testGroup',
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
);
$this->shareManager->acceptShare($share2, self::TEST_FILES_SHARING_API_USER2);
$this->shareManager->acceptShare($share2, self::TEST_FILES_SHARING_API_USER3);
$this->shareManager->acceptShare($share2, $this->TEST_FILES_SHARING_API_USER2);
$this->shareManager->acceptShare($share2, $this->TEST_FILES_SHARING_API_USER3);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
self::loginHelper($this->TEST_FILES_SHARING_API_USER3);
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
\OC\Files\Filesystem::unlink($this->filename);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
// both group share and user share should be gone
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename));
// for user3 nothing should change
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
self::loginHelper($this->TEST_FILES_SHARING_API_USER3);
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
$this->shareManager->deleteShare($share1);
@ -135,8 +135,8 @@ class ShareTest extends TestCase {
$share = $this->share(
IShare::TYPE_USER,
$this->filename,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
);
@ -145,12 +145,12 @@ class ShareTest extends TestCase {
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
$this->assertTrue(\OC\Files\Filesystem::file_exists('/Shared/subfolder/' . $this->folder));
@ -162,27 +162,27 @@ class ShareTest extends TestCase {
public function testShareWithGroupUniqueName() {
$this->markTestSkipped('TODO: Disable because fails on drone');
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
$this->loginHelper($this->TEST_FILES_SHARING_API_USER1);
\OC\Files\Filesystem::file_put_contents('test.txt', 'test');
$share = $this->share(
IShare::TYPE_GROUP,
'test.txt',
self::TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_GROUP1,
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
);
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->loginHelper($this->TEST_FILES_SHARING_API_USER2);
$shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, IShare::TYPE_GROUP);
$shares = $this->shareManager->getSharedWith($this->TEST_FILES_SHARING_API_USER2, IShare::TYPE_GROUP);
$share = $shares[0];
$this->assertSame('/test.txt' ,$share->getTarget());
$this->assertSame(19, $share->getPermissions());
\OC\Files\Filesystem::rename('test.txt', 'new test.txt');
$shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, IShare::TYPE_GROUP);
$shares = $this->shareManager->getSharedWith($this->TEST_FILES_SHARING_API_USER2, IShare::TYPE_GROUP);
$share = $shares[0];
$this->assertSame('/new test.txt' ,$share->getTarget());
$this->assertSame(19, $share->getPermissions());
@ -190,8 +190,8 @@ class ShareTest extends TestCase {
$share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE);
$this->shareManager->updateShare($share);
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, IShare::TYPE_GROUP);
$this->loginHelper($this->TEST_FILES_SHARING_API_USER2);
$shares = $this->shareManager->getSharedWith($this->TEST_FILES_SHARING_API_USER2, IShare::TYPE_GROUP);
$share = $shares[0];
$this->assertSame('/new test.txt' ,$share->getTarget());
@ -208,8 +208,8 @@ class ShareTest extends TestCase {
$this->share(
IShare::TYPE_USER,
$this->filename,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
$permission
);
} catch (\Exception $e) {
@ -239,15 +239,15 @@ class ShareTest extends TestCase {
$this->share(
IShare::TYPE_USER,
$this->filename,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_READ
);
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->loginHelper($this->TEST_FILES_SHARING_API_USER2);
$info = \OC\Files\Filesystem::getFileInfo($this->filename);
$this->assertSame(self::TEST_FILES_SHARING_API_USER1, $info->getOwner()->getUID());
$this->assertSame($this->TEST_FILES_SHARING_API_USER1, $info->getOwner()->getUID());
}
}

View File

@ -87,25 +87,25 @@ class SharedMountTest extends TestCase {
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL);
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2);
$this->shareManager->acceptShare($share, $this->TEST_FILES_SHARING_API_USER2);
$share->setTarget('/foo/bar' . $this->folder);
$this->shareManager->moveShare($share, self::TEST_FILES_SHARING_API_USER2);
$this->shareManager->moveShare($share, $this->TEST_FILES_SHARING_API_USER2);
$share = $this->shareManager->getShareById($share->getFullId());
$this->assertSame('/foo/bar' . $this->folder, $share->getTarget());
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
// share should have moved up
$share = $this->shareManager->getShareById($share->getFullId());
$this->assertSame($this->folder, $share->getTarget());
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->shareManager->deleteShare($share);
$this->view->unlink($this->folder);
}
@ -118,13 +118,13 @@ class SharedMountTest extends TestCase {
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
$this->assertTrue($user2View->file_exists($this->folder));
// create a local folder
@ -143,13 +143,13 @@ class SharedMountTest extends TestCase {
$this->assertTrue($result);
//enforce reload of the mount points
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
//mount point should be back at the root
$this->assertTrue($user2View->is_dir($this->folder));
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->view->unlink($this->folder);
}
@ -157,24 +157,24 @@ class SharedMountTest extends TestCase {
$share = $this->share(
IShare::TYPE_USER,
$this->filename,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
\OC\Files\Filesystem::rename($this->filename, $this->filename . '_renamed');
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename . '_renamed'));
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename));
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename . '_renamed'));
// rename back to original name
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
\OC\Files\Filesystem::rename($this->filename . '_renamed', $this->filename);
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename . '_renamed'));
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
@ -189,9 +189,9 @@ class SharedMountTest extends TestCase {
*/
public function testMoveGroupShare() {
$testGroup = $this->groupManager->createGroup('testGroup');
$user1 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER1);
$user2 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER2);
$user3 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER3);
$user1 = $this->userManager->get($this->TEST_FILES_SHARING_API_USER1);
$user2 = $this->userManager->get($this->TEST_FILES_SHARING_API_USER2);
$user3 = $this->userManager->get($this->TEST_FILES_SHARING_API_USER3);
$testGroup->addUser($user1);
$testGroup->addUser($user2);
$testGroup->addUser($user3);
@ -200,7 +200,7 @@ class SharedMountTest extends TestCase {
$share = $this->share(
IShare::TYPE_GROUP,
$this->filename,
self::TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER1,
'testGroup',
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
);
@ -208,7 +208,7 @@ class SharedMountTest extends TestCase {
$this->shareManager->acceptShare($share, $user2->getUID());
$this->shareManager->acceptShare($share, $user3->getUID());
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
@ -217,16 +217,16 @@ class SharedMountTest extends TestCase {
$this->assertTrue(\OC\Files\Filesystem::file_exists('newFileName'));
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename));
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
self::loginHelper($this->TEST_FILES_SHARING_API_USER3);
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
$this->assertFalse(\OC\Files\Filesystem::file_exists('newFileName'));
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
self::loginHelper($this->TEST_FILES_SHARING_API_USER3);
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
$this->assertFalse(\OC\Files\Filesystem::file_exists('newFileName'));
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->shareManager->deleteShare($share);
$testGroup->removeUser($user1);
$testGroup->removeUser($user2);
@ -270,9 +270,9 @@ class SharedMountTest extends TestCase {
*/
public function testPermissionUpgradeOnUserDeletedGroupShare() {
$testGroup = $this->groupManager->createGroup('testGroup');
$user1 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER1);
$user2 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER2);
$user3 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER3);
$user1 = $this->userManager->get($this->TEST_FILES_SHARING_API_USER1);
$user2 = $this->userManager->get($this->TEST_FILES_SHARING_API_USER2);
$user3 = $this->userManager->get($this->TEST_FILES_SHARING_API_USER3);
$testGroup->addUser($user1);
$testGroup->addUser($user2);
$testGroup->addUser($user3);
@ -284,7 +284,7 @@ class SharedMountTest extends TestCase {
$share = $this->share(
IShare::TYPE_GROUP,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER1,
'testGroup',
\OCP\Constants::PERMISSION_READ
);
@ -293,9 +293,9 @@ class SharedMountTest extends TestCase {
$this->shareManager->acceptShare($share, $user3->getUID());
// Login as user 2 and verify the item exists
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
$result = $this->shareManager->getShareById($share->getFullId(), $this->TEST_FILES_SHARING_API_USER2);
$this->assertNotEmpty($result);
$this->assertEquals(\OCP\Constants::PERMISSION_READ, $result->getPermissions());
@ -304,24 +304,24 @@ class SharedMountTest extends TestCase {
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder));
// Verify we do not get a share
$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
$result = $this->shareManager->getShareById($share->getFullId(), $this->TEST_FILES_SHARING_API_USER2);
$this->assertEquals(0, $result->getPermissions());
// Login as user 1 again and change permissions
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$share->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $this->shareManager->updateShare($share);
// Login as user 2 and verify
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder));
$result = $this->shareManager->getShareById($share->getFullId(), self::TEST_FILES_SHARING_API_USER2);
$result = $this->shareManager->getShareById($share->getFullId(), $this->TEST_FILES_SHARING_API_USER2);
$this->assertEquals(0, $result->getPermissions());
$this->shareManager->deleteShare($share);
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$testGroup->removeUser($user1);
$testGroup->removeUser($user2);
$testGroup->removeUser($user3);

View File

@ -85,13 +85,13 @@ class SharedStorageTest extends TestCase {
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
$this->assertTrue($user2View->file_exists($this->folder));
// create a local folder
@ -107,17 +107,17 @@ class SharedStorageTest extends TestCase {
// delete the local folder
/** @var \OC\Files\Storage\Storage $storage */
[$storage, $internalPath] = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/localfolder');
[$storage, $internalPath] = \OC\Files\Filesystem::resolvePath('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/localfolder');
$storage->rmdir($internalPath);
//enforce reload of the mount points
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
//mount point should be back at the root
$this->assertTrue($user2View->is_dir($this->folder));
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->view->unlink($this->folder);
}
@ -130,14 +130,14 @@ class SharedStorageTest extends TestCase {
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
$this->assertTrue($user2View->file_exists($this->folder));
@ -154,7 +154,7 @@ class SharedStorageTest extends TestCase {
$this->assertTrue($user2View->file_exists($this->folder . '/foo.txt'));
// check if the rename also affected the owner
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->assertTrue($this->view->file_exists($this->folder . '/foo.txt'));
@ -170,21 +170,21 @@ class SharedStorageTest extends TestCase {
$share1 = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL
);
$share2 = $this->share(
IShare::TYPE_USER,
$this->filename,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
// compare file size between user1 and user2, should always be the same
$this->assertSame($folderSize, \OC\Files\Filesystem::filesize($this->folder));
@ -200,13 +200,13 @@ class SharedStorageTest extends TestCase {
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_READ
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$this->assertTrue(\OC\Files\Filesystem::is_dir($this->folder));
@ -232,13 +232,13 @@ class SharedStorageTest extends TestCase {
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_READ
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
// part file should be forbidden
$handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
@ -265,13 +265,13 @@ class SharedStorageTest extends TestCase {
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
// create part file allowed
$handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
@ -301,7 +301,7 @@ class SharedStorageTest extends TestCase {
$this->assertFalse($user2View->unlink($this->folder . '/existing.txt'));
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->shareManager->deleteShare($share);
}
@ -311,13 +311,13 @@ class SharedStorageTest extends TestCase {
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
// create part file allowed
$handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
@ -357,13 +357,13 @@ class SharedStorageTest extends TestCase {
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
// part file should be forbidden
$handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
@ -385,39 +385,39 @@ class SharedStorageTest extends TestCase {
public function testMountSharesOtherUser() {
$rootView = new \OC\Files\View('');
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
// share 2 different files with 2 different users
$share1 = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL
);
$share2 = $this->share(
IShare::TYPE_USER,
$this->filename,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER3,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER3,
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder));
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$this->assertTrue($rootView->file_exists('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder));
$mountConfigManager = \OC::$server->getMountProviderCollection();
$mounts = $mountConfigManager->getMountsForUser(\OC::$server->getUserManager()->get(self::TEST_FILES_SHARING_API_USER3));
$mounts = $mountConfigManager->getMountsForUser(\OC::$server->getUserManager()->get($this->TEST_FILES_SHARING_API_USER3));
array_walk($mounts, [\OC\Files\Filesystem::getMountManager(), 'addMount']);
$this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER3 . '/files/' . $this->filename));
$this->assertTrue($rootView->file_exists('/' . $this->TEST_FILES_SHARING_API_USER3 . '/files/' . $this->filename));
// make sure we didn't double setup shares for user 2 or mounted the shares for user 3 in user's 2 home
$this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder . ' (2)'));
$this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->filename));
$this->assertFalse($rootView->file_exists('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder . ' (2)'));
$this->assertFalse($rootView->file_exists('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/' . $this->filename));
//cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->view->unlink($this->folder);
$this->shareManager->deleteShare($share1);
@ -425,18 +425,18 @@ class SharedStorageTest extends TestCase {
}
public function testCopyFromStorage() {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$view = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
$this->assertTrue($view->file_exists($this->folder));
/**
@ -452,24 +452,24 @@ class SharedStorageTest extends TestCase {
$this->assertTrue($sharedStorage->file_exists('bar.txt'));
$this->assertEquals('asd', $sharedStorage->file_get_contents('bar.txt'));
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->view->unlink($this->folder);
$this->shareManager->deleteShare($share);
}
public function testMoveFromStorage() {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$view = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
$this->assertTrue($view->file_exists($this->folder));
/**
@ -485,47 +485,47 @@ class SharedStorageTest extends TestCase {
$this->assertTrue($sharedStorage->file_exists('bar.txt'));
$this->assertEquals('asd', $sharedStorage->file_get_contents('bar.txt'));
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->view->unlink($this->folder);
$this->shareManager->deleteShare($share);
}
public function testNameConflict() {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
$view1 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$view1 = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER1 . '/files');
$view1->mkdir('foo');
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
$view3 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
self::loginHelper($this->TEST_FILES_SHARING_API_USER3);
$view3 = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER3 . '/files');
$view3->mkdir('foo');
// share a folder with the same name from two different users to the same user
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$share1 = $this->share(
IShare::TYPE_GROUP,
'foo',
self::TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_GROUP1,
\OCP\Constants::PERMISSION_ALL
);
$this->shareManager->acceptShare($share1, self::TEST_FILES_SHARING_API_USER2);
$this->shareManager->acceptShare($share1, $this->TEST_FILES_SHARING_API_USER2);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
self::loginHelper($this->TEST_FILES_SHARING_API_USER3);
$share2 = $this->share(
IShare::TYPE_GROUP,
'foo',
self::TEST_FILES_SHARING_API_USER3,
$this->TEST_FILES_SHARING_API_USER3,
self::TEST_FILES_SHARING_API_GROUP1,
\OCP\Constants::PERMISSION_ALL
);
$this->shareManager->acceptShare($share2, self::TEST_FILES_SHARING_API_USER2);
$this->shareManager->acceptShare($share2, $this->TEST_FILES_SHARING_API_USER2);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$view2 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$view2 = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
$this->assertTrue($view2->file_exists('/foo'));
$this->assertTrue($view2->file_exists('/foo (2)'));
@ -535,30 +535,30 @@ class SharedStorageTest extends TestCase {
/** @var \OCA\Files_Sharing\SharedStorage $storage */
$storage = $mount->getStorage();
$this->assertEquals(self::TEST_FILES_SHARING_API_USER1, $storage->getOwner(''));
$this->assertEquals($this->TEST_FILES_SHARING_API_USER1, $storage->getOwner(''));
$this->shareManager->deleteShare($share1);
$this->shareManager->deleteShare($share2);
}
public function testOwnerPermissions() {
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_DELETE
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$view = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
$this->assertTrue($view->file_exists($this->folder));
$view->file_put_contents($this->folder . '/newfile.txt', 'asd');
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->assertTrue($this->view->file_exists($this->folder . '/newfile.txt'));
$this->assertEquals(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE,
@ -586,7 +586,7 @@ class SharedStorageTest extends TestCase {
public function testInitWithNotFoundSource() {
$share = $this->createMock(IShare::class);
$share->method('getShareOwner')->willReturn(self::TEST_FILES_SHARING_API_USER1);
$share->method('getShareOwner')->willReturn($this->TEST_FILES_SHARING_API_USER1);
$ownerView = $this->createMock(View::class);
$ownerView->method('getPath')->will($this->throwException(new NotFoundException()));
$storage = new SharedStorage([

View File

@ -49,57 +49,57 @@ class SizePropagationTest extends TestCase {
}
public function testSizePropagationWhenOwnerChangesFile() {
$recipientView = $this->setupUser(self::TEST_FILES_SHARING_API_USER1);
$recipientView = $this->setupUser($this->TEST_FILES_SHARING_API_USER1);
$ownerView = $this->setupUser(self::TEST_FILES_SHARING_API_USER2);
$ownerView = $this->setupUser($this->TEST_FILES_SHARING_API_USER2);
$ownerView->mkdir('/sharedfolder/subfolder');
$ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar');
$this->share(
IShare::TYPE_USER,
'/sharedfolder',
self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
\OCP\Constants::PERMISSION_ALL
);
$ownerRootInfo = $ownerView->getFileInfo('', false);
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER1);
$this->assertTrue($recipientView->file_exists('/sharedfolder/subfolder/foo.txt'));
$recipientRootInfo = $recipientView->getFileInfo('', false);
// when file changed as owner
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER2);
$ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar');
// size of recipient's root stays the same
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER1);
$newRecipientRootInfo = $recipientView->getFileInfo('', false);
$this->assertEquals($recipientRootInfo->getSize(), $newRecipientRootInfo->getSize());
// size of owner's root increases
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER2);
$newOwnerRootInfo = $ownerView->getFileInfo('', false);
$this->assertEquals($ownerRootInfo->getSize() + 3, $newOwnerRootInfo->getSize());
}
public function testSizePropagationWhenRecipientChangesFile() {
$recipientView = $this->setupUser(self::TEST_FILES_SHARING_API_USER1);
$recipientView = $this->setupUser($this->TEST_FILES_SHARING_API_USER1);
$ownerView = $this->setupUser(self::TEST_FILES_SHARING_API_USER2);
$ownerView = $this->setupUser($this->TEST_FILES_SHARING_API_USER2);
$ownerView->mkdir('/sharedfolder/subfolder');
$ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar');
$this->share(
IShare::TYPE_USER,
'/sharedfolder',
self::TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
\OCP\Constants::PERMISSION_ALL
);
$ownerRootInfo = $ownerView->getFileInfo('', false);
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER1);
$this->assertTrue($recipientView->file_exists('/sharedfolder/subfolder/foo.txt'));
$recipientRootInfo = $recipientView->getFileInfo('', false);
$recipientRootInfoWithMounts = $recipientView->getFileInfo('', true);
@ -117,7 +117,7 @@ class SizePropagationTest extends TestCase {
$this->assertEquals($oldRecipientSize + 3, $newRecipientRootInfo->getSize());
// size of owner's root increases
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
$this->loginAsUser($this->TEST_FILES_SHARING_API_USER2);
$newOwnerRootInfo = $ownerView->getFileInfo('', false);
$this->assertEquals($ownerRootInfo->getSize() + 3, $newOwnerRootInfo->getSize());
}

View File

@ -48,10 +48,10 @@ use Test\Traits\MountProviderTrait;
abstract class TestCase extends \Test\TestCase {
use MountProviderTrait;
public const TEST_FILES_SHARING_API_USER1 = "test-share-user1";
public const TEST_FILES_SHARING_API_USER2 = "test-share-user2";
public const TEST_FILES_SHARING_API_USER3 = "test-share-user3";
public const TEST_FILES_SHARING_API_USER4 = "test-share-user4";
public $TEST_FILES_SHARING_API_USER1 = "test-share-user1-";
public $TEST_FILES_SHARING_API_USER2 = "test-share-user2-";
public $TEST_FILES_SHARING_API_USER3 = "test-share-user3-";
public $TEST_FILES_SHARING_API_USER4 = "test-share-user4-";
public const TEST_FILES_SHARING_API_GROUP1 = "test-share-group1";
@ -69,8 +69,8 @@ abstract class TestCase extends \Test\TestCase {
/** @var \OCP\Files\IRootFolder */
protected $rootFolder;
public static function setUpBeforeClass(): void {
parent::setUpBeforeClass();
protected function setUp(): void {
parent::setUp();
new Application();
@ -82,13 +82,19 @@ abstract class TestCase extends \Test\TestCase {
\OC_Hook::clear('OCP\\Share');
\OC::registerShareHooks(\OC::$server->getSystemConfig());
// User Prefix
$this->TEST_FILES_SHARING_API_USER1 = self::getUniqueID($this->TEST_FILES_SHARING_API_USER1);
$this->TEST_FILES_SHARING_API_USER2 = self::getUniqueID($this->TEST_FILES_SHARING_API_USER2);
$this->TEST_FILES_SHARING_API_USER3 = self::getUniqueID($this->TEST_FILES_SHARING_API_USER3);
$this->TEST_FILES_SHARING_API_USER4 = self::getUniqueID($this->TEST_FILES_SHARING_API_USER4);
// create users
$backend = new \Test\Util\User\Dummy();
\OC_User::useBackend($backend);
$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);
$backend->createUser($this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1);
$backend->createUser($this->TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2);
$backend->createUser($this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER3);
$backend->createUser($this->TEST_FILES_SHARING_API_USER4, $this->TEST_FILES_SHARING_API_USER4);
// create group
$groupBackend = new \Test\Util\Group\Dummy();
@ -97,56 +103,36 @@ abstract class TestCase extends \Test\TestCase {
$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);
$groupBackend->addToGroup($this->TEST_FILES_SHARING_API_USER1, 'group');
$groupBackend->addToGroup($this->TEST_FILES_SHARING_API_USER2, 'group');
$groupBackend->addToGroup($this->TEST_FILES_SHARING_API_USER3, 'group');
$groupBackend->addToGroup($this->TEST_FILES_SHARING_API_USER2, 'group1');
$groupBackend->addToGroup($this->TEST_FILES_SHARING_API_USER3, 'group2');
$groupBackend->addToGroup($this->TEST_FILES_SHARING_API_USER4, 'group3');
$groupBackend->addToGroup($this->TEST_FILES_SHARING_API_USER2, self::TEST_FILES_SHARING_API_GROUP1);
\OC::$server->getGroupManager()->addBackend($groupBackend);
}
protected function setUp(): void {
parent::setUp();
//login as user1
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->data = 'foobar';
$this->view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
$this->view = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER1 . '/files');
$this->shareManager = \OC::$server->getShareManager();
$this->rootFolder = \OC::$server->getRootFolder();
}
protected function tearDown(): void {
$qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$qb->delete('share');
$qb->execute();
$qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$qb->delete('mounts');
$qb->execute();
$qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$qb->delete('filecache');
$qb->execute();
parent::tearDown();
}
public static function tearDownAfterClass(): void {
// cleanup users
$user = \OC::$server->getUserManager()->get(self::TEST_FILES_SHARING_API_USER1);
$user = \OC::$server->getUserManager()->get($this->TEST_FILES_SHARING_API_USER1);
if ($user !== null) {
$user->delete();
}
$user = \OC::$server->getUserManager()->get(self::TEST_FILES_SHARING_API_USER2);
$user = \OC::$server->getUserManager()->get($this->TEST_FILES_SHARING_API_USER2);
if ($user !== null) {
$user->delete();
}
$user = \OC::$server->getUserManager()->get(self::TEST_FILES_SHARING_API_USER3);
$user = \OC::$server->getUserManager()->get($this->TEST_FILES_SHARING_API_USER3);
if ($user !== null) {
$user->delete();
}
@ -167,7 +153,19 @@ abstract class TestCase extends \Test\TestCase {
\OC::$server->getGroupManager()->clearBackends();
\OC::$server->getGroupManager()->addBackend(new \OC\Group\Database());
parent::tearDownAfterClass();
$qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$qb->delete('share');
$qb->execute();
$qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$qb->delete('mounts');
$qb->execute();
$qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
$qb->delete('filecache');
$qb->execute();
parent::tearDown();
}
/**

View File

@ -82,15 +82,15 @@ class UnshareChildrenTest extends TestCase {
$this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL
);
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
// one folder should be shared with the user
$shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, IShare::TYPE_USER);
$shares = $this->shareManager->getSharedWith($this->TEST_FILES_SHARING_API_USER2, IShare::TYPE_USER);
$this->assertCount(1, $shares);
// move shared folder to 'localDir'
@ -100,13 +100,13 @@ class UnshareChildrenTest extends TestCase {
\OC\Files\Filesystem::unlink('localDir');
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
// after the parent directory was deleted the share should be unshared
$shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, IShare::TYPE_USER);
$shares = $this->shareManager->getSharedWith($this->TEST_FILES_SHARING_API_USER2, IShare::TYPE_USER);
$this->assertEmpty($shares);
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
// the folder for the owner should still exists
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));

View File

@ -89,13 +89,13 @@ class UpdaterTest extends TestCase {
$this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL
);
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
$this->loginHelper($this->TEST_FILES_SHARING_API_USER2);
$view = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
// check if user2 can see the shared folder
$this->assertTrue($view->file_exists($this->folder));
@ -114,15 +114,15 @@ class UpdaterTest extends TestCase {
$view->unlink('localFolder');
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->loginHelper($this->TEST_FILES_SHARING_API_USER2);
// shared folder should be unshared
$foldersShared = \OC\Share\Share::getItemsSharedWith('folder');
$this->assertTrue(empty($foldersShared));
// trashbin should contain the local file but not the mount point
$rootView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
$trashContent = \OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_FILES_SHARING_API_USER2);
$rootView = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2);
$trashContent = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $this->TEST_FILES_SHARING_API_USER2);
$this->assertSame(1, count($trashContent));
$firstElement = reset($trashContent);
$timestamp = $firstElement['mtime'];
@ -158,7 +158,7 @@ class UpdaterTest extends TestCase {
$oldShareFolder = $config->getSystemValue('share_folder');
$config->setSystemValue('share_folder', $shareFolder);
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->loginHelper($this->TEST_FILES_SHARING_API_USER2);
$beforeShareRoot = \OC\Files\Filesystem::getFileInfo('');
$etagBeforeShareRoot = $beforeShareRoot->getEtag();
@ -168,17 +168,17 @@ class UpdaterTest extends TestCase {
$beforeShareDir = \OC\Files\Filesystem::getFileInfo($shareFolder);
$etagBeforeShareDir = $beforeShareDir->getEtag();
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
$this->loginHelper($this->TEST_FILES_SHARING_API_USER1);
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL
);
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->loginHelper($this->TEST_FILES_SHARING_API_USER2);
$afterShareRoot = \OC\Files\Filesystem::getFileInfo('');
$etagAfterShareRoot = $afterShareRoot->getEtag();
@ -194,7 +194,7 @@ class UpdaterTest extends TestCase {
$this->assertTrue($etagBeforeShareDir !== $etagAfterShareDir);
// cleanup
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
$this->loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->shareManager->deleteShare($share);
$config->setSystemValue('share_folder', $oldShareFolder);
@ -209,12 +209,12 @@ class UpdaterTest extends TestCase {
$share = $this->share(
IShare::TYPE_USER,
$this->folder,
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL
);
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->loginHelper($this->TEST_FILES_SHARING_API_USER2);
// make sure that the shared folder exists
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
@ -226,12 +226,12 @@ class UpdaterTest extends TestCase {
\OC\Files\Filesystem::rename($this->folder, 'oldTarget/subfolder/' . $this->folder);
// re-login to make sure that the new mount points are initialized
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->loginHelper($this->TEST_FILES_SHARING_API_USER2);
\OC\Files\Filesystem::rename('/oldTarget', '/newTarget/oldTarget');
// re-login to make sure that the new mount points are initialized
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
$this->loginHelper($this->TEST_FILES_SHARING_API_USER2);
$this->assertTrue(\OC\Files\Filesystem::file_exists('/newTarget/oldTarget/subfolder/' . $this->folder));

View File

@ -57,7 +57,7 @@ class WatcherTest extends TestCase {
protected function setUp(): void {
parent::setUp();
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
// prepare user1's dir structure
$this->view->mkdir('container');
@ -72,8 +72,8 @@ class WatcherTest extends TestCase {
$this->_share = $this->share(
IShare::TYPE_USER,
'container/shareddir',
self::TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2,
$this->TEST_FILES_SHARING_API_USER1,
$this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL
);
@ -81,10 +81,10 @@ class WatcherTest extends TestCase {
$this->shareManager->updateShare($this->_share);
// login as user2
self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
// retrieve the shared storage
$secondView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
$secondView = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2);
[$this->sharedStorage, $internalPath] = $secondView->resolvePath('files/shareddir');
$this->sharedCache = $this->sharedStorage->getCache();
}
@ -94,7 +94,7 @@ class WatcherTest extends TestCase {
$this->sharedCache->clear();
}
self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
if ($this->view) {
$this->shareManager->deleteShare($this->_share);

View File

@ -987,8 +987,8 @@ class ShareByMailProviderTest extends TestCase {
$provider = $this->getInstance(['sendMailNotification', 'createShareActivity']);
$u1 = $userManager->createUser('testFed', md5(time()));
$u2 = $userManager->createUser('testFed2', md5(time()));
$u1 = $userManager->createUser(self::getUniqueID('testFed'), md5(time()));
$u2 = $userManager->createUser(self::getUniqueID('testFed2'), md5(time()));
$folder1 = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo');
$file1 = $folder1->newFile('bar1');
@ -1033,8 +1033,8 @@ class ShareByMailProviderTest extends TestCase {
$provider = $this->getInstance(['sendMailNotification', 'createShareActivity']);
$u1 = $userManager->createUser('testFed', md5(time()));
$u2 = $userManager->createUser('testFed2', md5(time()));
$u1 = $userManager->createUser(self::getUniqueID('testFed'), md5(time()));
$u2 = $userManager->createUser(self::getUniqueID('testFed2'), md5(time()));
$folder = $rootFolder->getUserFolder($u1->getUID())->newFolder('foo');

View File

@ -48,6 +48,11 @@ return [
'url' => '/api/v1/app/{appid}/{configkey}',
'verb' => 'DELETE',
],
[
'name' => 'FlushUsedUserNames#executeFlush',
'url' => '/api/v1/flushDupeUsernames',
'verb' => 'POST',
],
[
'name' => 'Locking#isLockingEnabled',
'url' => '/api/v1/lockprovisioning',

View File

@ -10,6 +10,7 @@ return array(
'OCA\\Testing\\AlternativeHomeUserBackend' => $baseDir . '/../lib/AlternativeHomeUserBackend.php',
'OCA\\Testing\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
'OCA\\Testing\\Controller\\ConfigController' => $baseDir . '/../lib/Controller/ConfigController.php',
'OCA\\Testing\\Controller\\FlushUsedUserNamesController' => $baseDir . '/../lib/Controller/FlushUsedUserNamesController.php',
'OCA\\Testing\\Controller\\LockingController' => $baseDir . '/../lib/Controller/LockingController.php',
'OCA\\Testing\\Controller\\RateLimitTestController' => $baseDir . '/../lib/Controller/RateLimitTestController.php',
'OCA\\Testing\\Locking\\FakeDBLockingProvider' => $baseDir . '/../lib/Locking/FakeDBLockingProvider.php',

View File

@ -25,6 +25,7 @@ class ComposerStaticInitTesting
'OCA\\Testing\\AlternativeHomeUserBackend' => __DIR__ . '/..' . '/../lib/AlternativeHomeUserBackend.php',
'OCA\\Testing\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
'OCA\\Testing\\Controller\\ConfigController' => __DIR__ . '/..' . '/../lib/Controller/ConfigController.php',
'OCA\\Testing\\Controller\\FlushUsedUserNamesController' => __DIR__ . '/..' . '/../lib/Controller/FlushUsedUserNamesController.php',
'OCA\\Testing\\Controller\\LockingController' => __DIR__ . '/..' . '/../lib/Controller/LockingController.php',
'OCA\\Testing\\Controller\\RateLimitTestController' => __DIR__ . '/..' . '/../lib/Controller/RateLimitTestController.php',
'OCA\\Testing\\Locking\\FakeDBLockingProvider' => __DIR__ . '/..' . '/../lib/Locking/FakeDBLockingProvider.php',

View File

@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2021 Lukas Reschke <lukas@statuscode.ch>
*
* @author Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Testing\Controller;
use OC\User\UsernameDuplicationPreventionManager;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
class FlushUsedUserNamesController extends OCSController {
/** @var UsernameDuplicationPreventionManager */
private $usernameDuplicationPreventionManager;
/**
* @param string $appName
* @param IRequest $request
* @param UsernameDuplicationPreventionManager $usernameDuplicationPreventionManager
*/
public function __construct($appName,
IRequest $request,
UsernameDuplicationPreventionManager $usernameDuplicationPreventionManager) {
parent::__construct($appName, $request);
$this->usernameDuplicationPreventionManager = $usernameDuplicationPreventionManager;
}
public function executeFlush() : DataResponse {
$this->usernameDuplicationPreventionManager->cleanUp();
return new DataResponse();
}
}

View File

@ -414,6 +414,40 @@ trait Provisioning {
$this->response = $client->put($fullUrl, $options);
}
private function flushDeletedUserList() {
$previousUser = $this->currentUser;
$this->currentUser = 'admin';
$fullUrl = $this->baseUrl . "v2.php/cloud/apps?filter=disabled";
$client = new Client();
$options = [];
if ($this->currentUser === 'admin') {
$options['auth'] = $this->adminUser;
}
$options['headers'] = [
'OCS-APIREQUEST' => 'true',
];
$response = $client->get($fullUrl, $options);
$respondedArray = $this->getArrayOfAppsResponded($response);
$isTestingAppEnabled = true;
if (array_key_exists('testing', $respondedArray)) {
$isTestingAppEnabled = false;
}
if (!$isTestingAppEnabled) {
$this->sendingTo('POST', "/cloud/apps/testing");
}
$this->sendingTo('POST', "/apps/testing/api/v1/flushDupeUsernames");
if (!$isTestingAppEnabled) {
$this->sendingTo('DELETE', "/cloud/apps/testing");
}
$this->currentUser = $previousUser;
}
/**
* @When /^Deleting the user "([^"]*)"$/
* @param string $user
@ -908,6 +942,8 @@ trait Provisioning {
* @AfterScenario
*/
public function cleanupUsers() {
$this->flushDeletedUserList();
$previousServer = $this->currentServer;
$this->usingServer('LOCAL');
foreach ($this->createdUsers as $user) {

View File

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace OC\Core\Migrations;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
class Version22000Date20210525173326 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if (!$schema->hasTable('previously_used_userids')) {
$table = $schema->createTable('previously_used_userids');
$table->addColumn('user_id_hash', \OCP\DB\Types::STRING, [
'notnull' => true,
'length' => 128,
]);
$table->setPrimaryKey(['user_id_hash'], 'uid_hash_idx');
}
return $schema;
}
}

View File

@ -960,6 +960,7 @@ return array(
'OC\\Core\\Migrations\\Version21000Date20210309185126' => $baseDir . '/core/Migrations/Version21000Date20210309185126.php',
'OC\\Core\\Migrations\\Version21000Date20210309185127' => $baseDir . '/core/Migrations/Version21000Date20210309185127.php',
'OC\\Core\\Migrations\\Version22000Date20210216080825' => $baseDir . '/core/Migrations/Version22000Date20210216080825.php',
'OC\\Core\\Migrations\\Version22000Date20210525173326' => $baseDir . '/core/Migrations/Version22000Date20210525173326.php',
'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php',
'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php',
'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php',
@ -1433,6 +1434,8 @@ return array(
'OC\\User\\NoUserException' => $baseDir . '/lib/private/User/NoUserException.php',
'OC\\User\\Session' => $baseDir . '/lib/private/User/Session.php',
'OC\\User\\User' => $baseDir . '/lib/private/User/User.php',
'OC\\User\\UserDeletedListener' => $baseDir . '/lib/private/User/UserDeletedListener.php',
'OC\\User\\UsernameDuplicationPreventionManager' => $baseDir . '/lib/private/User/UsernameDuplicationPreventionManager.php',
'OC_API' => $baseDir . '/lib/private/legacy/OC_API.php',
'OC_App' => $baseDir . '/lib/private/legacy/OC_App.php',
'OC_DB' => $baseDir . '/lib/private/legacy/OC_DB.php',

View File

@ -989,6 +989,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Core\\Migrations\\Version21000Date20210309185126' => __DIR__ . '/../../..' . '/core/Migrations/Version21000Date20210309185126.php',
'OC\\Core\\Migrations\\Version21000Date20210309185127' => __DIR__ . '/../../..' . '/core/Migrations/Version21000Date20210309185127.php',
'OC\\Core\\Migrations\\Version22000Date20210216080825' => __DIR__ . '/../../..' . '/core/Migrations/Version22000Date20210216080825.php',
'OC\\Core\\Migrations\\Version22000Date20210525173326' => __DIR__ . '/../../..' . '/core/Migrations/Version22000Date20210525173326.php',
'OC\\Core\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php',
'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php',
'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php',
@ -1462,6 +1463,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\User\\NoUserException' => __DIR__ . '/../../..' . '/lib/private/User/NoUserException.php',
'OC\\User\\Session' => __DIR__ . '/../../..' . '/lib/private/User/Session.php',
'OC\\User\\User' => __DIR__ . '/../../..' . '/lib/private/User/User.php',
'OC\\User\\UserDeletedListener' => __DIR__ . '/../../..' . '/lib/private/User/UserDeletedListener.php',
'OC\\User\\UsernameDuplicationPreventionManager' => __DIR__ . '/../../..' . '/lib/private/User/UsernameDuplicationPreventionManager.php',
'OC_API' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_API.php',
'OC_App' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_App.php',
'OC_DB' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_DB.php',

View File

@ -142,6 +142,7 @@ use OC\Share20\ShareHelper;
use OC\SystemTag\ManagerFactory as SystemTagManagerFactory;
use OC\Tagging\TagMapper;
use OC\Template\JSCombiner;
use OC\User\UserDeletedListener;
use OCA\Theming\ImageManager;
use OCA\Theming\ThemingDefaults;
use OCA\Theming\Util;
@ -1445,6 +1446,7 @@ class Server extends ServerContainer implements IServerContainer {
$eventDispatched = $this->get(IEventDispatcher::class);
$eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class);
$eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
$eventDispatched->addServiceListener(UserDeletedEvent::class, UserDeletedListener::class);
}
/**

View File

@ -378,6 +378,10 @@ class Manager extends PublicEmitter implements IUserManager {
throw new HintException($l->t('The user limit has been reached and the user was not created.'));
}
if (\OC::$server->get(UsernameDuplicationPreventionManager::class)->wasUsed($uid)) {
$l = \OC::$server->getL10N('lib');
throw new HintException($l->t('The user name has already been used previously.'));
}
$localBackends = [];
foreach ($this->backends as $backend) {
if ($backend instanceof Database) {

View File

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2021 Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\User;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\User\Events\UserDeletedEvent;
class UserDeletedListener implements IEventListener {
/** @var UsernameDuplicationPreventionManager */
private $usernameDuplicationPreventionManager;
public function __construct(UsernameDuplicationPreventionManager $usernameDuplicationPreventionManager) {
$this->usernameDuplicationPreventionManager = $usernameDuplicationPreventionManager;
}
public function handle(Event $event): void {
if (!($event instanceof UserDeletedEvent)) {
return;
}
$user = $event->getUser();
$this->usernameDuplicationPreventionManager->markUsed($user->getUID());
}
}

View File

@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2021, Lukas Reschke <lukas@statuscode.ch>
*
* @author Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\User;
use OCP\IDBConnection;
class UsernameDuplicationPreventionManager {
/** @var IDBConnection */
private $dbConnection;
private const TABLE_NAME = 'previously_used_userids';
private const HASHED_USER_ID_NAME = 'user_id_hash';
public function __construct(IDBConnection $connection) {
$this->dbConnection = $connection;
}
private function calculateUserNameHash(string $username) : string {
return hash('sha512', $username);
}
public function markUsed(string $userName) : void {
$queryBuilder = $this->dbConnection->getQueryBuilder();
$queryBuilder->insert(self::TABLE_NAME)
->values([
self::HASHED_USER_ID_NAME => $queryBuilder->createNamedParameter($this->calculateUserNameHash($userName)),
])
->executeStatement();
}
public function wasUsed(string $userName) : bool {
$queryBuilder = $this->dbConnection->getQueryBuilder();
$result = $queryBuilder->select($queryBuilder->func()->count())
->from(self::TABLE_NAME)
->where(
$queryBuilder->expr()->eq(
self::HASHED_USER_ID_NAME,
$queryBuilder->expr()->literal($this->calculateUserNameHash($userName))
)
)
->executeQuery();
return (int)$result->fetchOne() !== 0;
}
public function cleanUp(): void {
$qb = $this->dbConnection->getQueryBuilder();
$qb
->delete(self::TABLE_NAME)
->executeStatement();
}
}

View File

@ -21,9 +21,9 @@ use Psr\Log\LoggerInterface;
* @group DB
*/
class AppTest extends \Test\TestCase {
public const TEST_USER1 = 'user1';
public const TEST_USER2 = 'user2';
public const TEST_USER3 = 'user3';
public $TEST_USER1 = 'user1-';
public $TEST_USER2 = 'user2-';
public $TEST_USER3 = 'user3-';
public const TEST_GROUP1 = 'group1';
public const TEST_GROUP2 = 'group2';
@ -304,6 +304,13 @@ class AppTest extends \Test\TestCase {
];
}
public function setUp(): void {
parent::setUp();
$this->TEST_USER1 = self::getUniqueID($this->TEST_USER1);
$this->TEST_USER2 = self::getUniqueID($this->TEST_USER2);
$this->TEST_USER3 = self::getUniqueID($this->TEST_USER3);
}
/**
* @dataProvider appVersionsProvider
*/
@ -330,73 +337,6 @@ class AppTest extends \Test\TestCase {
*/
public function appConfigValuesProvider() {
return [
// logged in user1
[
self::TEST_USER1,
[
'files',
'app1',
'app3',
'appforgroup1',
'appforgroup12',
'cloud_federation_api',
'dav',
'federatedfilesharing',
'lookup_server_connector',
'oauth2',
'provisioning_api',
'settings',
'twofactor_backupcodes',
'viewer',
'workflowengine',
],
false
],
// logged in user2
[
self::TEST_USER2,
[
'files',
'app1',
'app3',
'appforgroup12',
'appforgroup2',
'cloud_federation_api',
'dav',
'federatedfilesharing',
'lookup_server_connector',
'oauth2',
'provisioning_api',
'settings',
'twofactor_backupcodes',
'viewer',
'workflowengine',
],
false
],
// logged in user3
[
self::TEST_USER3,
[
'files',
'app1',
'app3',
'appforgroup1',
'appforgroup12',
'appforgroup2',
'cloud_federation_api',
'dav',
'federatedfilesharing',
'lookup_server_connector',
'oauth2',
'provisioning_api',
'settings',
'twofactor_backupcodes',
'viewer',
'workflowengine',
],
false
],
// no user, returns all apps
[
null,
@ -420,9 +360,76 @@ class AppTest extends \Test\TestCase {
],
false,
],
// logged in user1
[
$this->TEST_USER1,
[
'files',
'app1',
'app3',
'appforgroup1',
'appforgroup12',
'cloud_federation_api',
'dav',
'federatedfilesharing',
'lookup_server_connector',
'oauth2',
'provisioning_api',
'settings',
'twofactor_backupcodes',
'viewer',
'workflowengine',
],
false
],
// logged in user2
[
$this->TEST_USER2,
[
'files',
'app1',
'app3',
'appforgroup12',
'appforgroup2',
'cloud_federation_api',
'dav',
'federatedfilesharing',
'lookup_server_connector',
'oauth2',
'provisioning_api',
'settings',
'twofactor_backupcodes',
'viewer',
'workflowengine',
],
false
],
// logged in user3
[
$this->TEST_USER3,
[
'files',
'app1',
'app3',
'appforgroup1',
'appforgroup12',
'appforgroup2',
'cloud_federation_api',
'dav',
'federatedfilesharing',
'lookup_server_connector',
'oauth2',
'provisioning_api',
'settings',
'twofactor_backupcodes',
'viewer',
'workflowengine',
],
false
],
// user given, but ask for all
[
self::TEST_USER1,
$this->TEST_USER1,
[
'files',
'app1',
@ -446,17 +453,32 @@ class AppTest extends \Test\TestCase {
];
}
private function mapDataProviderUserIds(?string $user): ?string {
if ($user === 'user1-') {
$user = $this->TEST_USER1;
} elseif ($user === 'user2-') {
$user = $this->TEST_USER2;
} elseif ($user === 'user3-') {
$user = $this->TEST_USER3;
}
return $user;
}
/**
* Test enabled apps
*
* @dataProvider appConfigValuesProvider
*/
public function testEnabledApps($user, $expectedApps, $forceAll) {
$user = $this->mapDataProviderUserIds($user);
$userManager = \OC::$server->getUserManager();
$groupManager = \OC::$server->getGroupManager();
$user1 = $userManager->createUser(self::TEST_USER1, self::TEST_USER1);
$user2 = $userManager->createUser(self::TEST_USER2, self::TEST_USER2);
$user3 = $userManager->createUser(self::TEST_USER3, self::TEST_USER3);
$user1 = $userManager->createUser($this->TEST_USER1, $this->TEST_USER1);
$user2 = $userManager->createUser($this->TEST_USER2, $this->TEST_USER2);
$user3 = $userManager->createUser($this->TEST_USER3, $this->TEST_USER3);
$group1 = $groupManager->createGroup(self::TEST_GROUP1);
$group1->addUser($user1);
@ -502,9 +524,9 @@ class AppTest extends \Test\TestCase {
*/
public function testEnabledAppsCache() {
$userManager = \OC::$server->getUserManager();
$user1 = $userManager->createUser(self::TEST_USER1, self::TEST_USER1);
$user1 = $userManager->createUser($this->TEST_USER1, $this->TEST_USER1);
\OC_User::setUserId(self::TEST_USER1);
\OC_User::setUserId($this->TEST_USER1);
$this->setupAppConfigMock()->expects($this->once())
->method('getValues')

View File

@ -36,6 +36,8 @@ class FileCacheTest extends TestCache {
* @var string
* */
private $user;
/** @var string */
private $userId;
/**
* @var string
* */
@ -49,10 +51,6 @@ class FileCacheTest extends TestCache {
* */
private $rootView;
public function skip() {
//$this->skipUnless(OC_User::isLoggedIn());
}
protected function setUp(): void {
parent::setUp();
@ -73,14 +71,15 @@ class FileCacheTest extends TestCache {
\OC_User::useBackend(new \Test\Util\User\Dummy());
//login
\OC::$server->getUserManager()->createUser('test', 'test');
$this->userId = self::getUniqueID('test');
\OC::$server->getUserManager()->createUser($this->userId, 'test');
$this->user = \OC_User::getUser();
\OC_User::setUserId('test');
\OC_User::setUserId($this->userId);
//set up the users dir
$this->rootView = new \OC\Files\View('');
$this->rootView->mkdir('/test');
$this->rootView->mkdir("/{$this->userId}");
$this->instance = new \OC\Cache\File();
@ -102,7 +101,7 @@ class FileCacheTest extends TestCache {
}
//tear down the users dir aswell
$user = \OC::$server->getUserManager()->get('test');
$user = \OC::$server->getUserManager()->get($this->userId);
$user->delete();
// Restore the original mount point
@ -118,7 +117,7 @@ class FileCacheTest extends TestCache {
->setConstructorArgs([['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]])
->getMock();
\OC\Files\Filesystem::mount($mockStorage, [], '/test/cache');
\OC\Files\Filesystem::mount($mockStorage, [], "/{$this->userId}/cache");
return $mockStorage;
}

View File

@ -52,10 +52,7 @@ class UpdaterLegacyTest extends \Test\TestCase {
$this->scanner->scan('');
$this->cache = $this->storage->getCache();
if (!self::$user) {
self::$user = $this->getUniqueID();
}
\OC::$server->getUserManager()->createUser(self::$user, 'password');
$this->loginAsUser(self::$user);

View File

@ -96,8 +96,8 @@ class ViewTest extends \Test\TestCase {
//login
$userManager = \OC::$server->getUserManager();
$groupManager = \OC::$server->getGroupManager();
$this->user = 'test';
$this->userObject = $userManager->createUser('test', 'test');
$this->user = self::getUniqueID('test');
$this->userObject = $userManager->createUser($this->user, 'test');
$this->groupObject = $groupManager->createGroup('group1');
$this->groupObject->addUser($this->userObject);
@ -2195,7 +2195,7 @@ class ViewTest extends \Test\TestCase {
* Test rename operation: unlock first path when second path was locked
*/
public function testLockFileRenameUnlockOnException() {
self::loginAsUser('test');
self::loginAsUser($this->user);
$view = new View('/' . $this->user . '/files/');
@ -2228,31 +2228,31 @@ class ViewTest extends \Test\TestCase {
* Test rename operation: unlock first path when second path was locked
*/
public function testGetOwner() {
self::loginAsUser('test');
self::loginAsUser($this->user);
$view = new View('/test/files/');
$view = new View("/{$this->user}/files/");
$path = 'foo.txt';
$view->file_put_contents($path, 'meh');
$this->assertEquals('test', $view->getFileInfo($path)->getOwner()->getUID());
$this->assertEquals($this->user, $view->getFileInfo($path)->getOwner()->getUID());
$folderInfo = $view->getDirectoryContent('');
$folderInfo = array_values(array_filter($folderInfo, function (FileInfo $info) {
return $info->getName() === 'foo.txt';
}));
$this->assertEquals('test', $folderInfo[0]->getOwner()->getUID());
$this->assertEquals($this->user, $folderInfo[0]->getOwner()->getUID());
$subStorage = new Temporary();
Filesystem::mount($subStorage, [], '/test/files/asd');
Filesystem::mount($subStorage, [], "/{$this->user}/files/asd");
$folderInfo = $view->getDirectoryContent('');
$folderInfo = array_values(array_filter($folderInfo, function (FileInfo $info) {
return $info->getName() === 'asd';
}));
$this->assertEquals('test', $folderInfo[0]->getOwner()->getUID());
$this->assertEquals($this->user, $folderInfo[0]->getOwner()->getUID());
}
public function lockFileRenameOrCopyCrossStorageDataProvider() {
@ -2342,8 +2342,7 @@ class ViewTest extends \Test\TestCase {
* Test locks when moving a mount point
*/
public function testLockMoveMountPoint() {
self::loginAsUser('test');
self::loginAsUser($this->user);
[$mount] = $this->createTestMovableMountPoints([
$this->user . '/files/substorage',
]);

View File

@ -2492,9 +2492,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
$password = md5(time());
$u1 = $userManager->createUser('testShare1', $password);
$u2 = $userManager->createUser('testShare2', $password);
$u3 = $userManager->createUser('testShare3', $password);
$u1 = $userManager->createUser(self::getUniqueID('testShare1'), $password);
$u2 = $userManager->createUser(self::getUniqueID('testShare2'), $password);
$u3 = $userManager->createUser(self::getUniqueID('testShare3'), $password);
$g1 = $groupManager->createGroup('group1');
@ -2588,11 +2588,11 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->config
);
$u1 = $userManager->createUser('testShare1', 'test');
$u2 = $userManager->createUser('testShare2', 'test');
$u3 = $userManager->createUser('testShare3', 'test');
$u4 = $userManager->createUser('testShare4', 'test');
$u5 = $userManager->createUser('testShare5', 'test');
$u1 = $userManager->createUser(self::getUniqueID('testShare1'), 'test');
$u2 = $userManager->createUser(self::getUniqueID('testShare2'), 'test');
$u3 = $userManager->createUser(self::getUniqueID('testShare3'),'test');
$u4 = $userManager->createUser(self::getUniqueID('testShare4'), 'test');
$u5 = $userManager->createUser(self::getUniqueID('testShare5'), 'test');
$g1 = $groupManager->createGroup('group1');
$g1->addUser($u3);
@ -2648,10 +2648,10 @@ class DefaultShareProviderTest extends \Test\TestCase {
$result = $provider->getAccessList([$folder1, $folder2, $file1], false);
$this->assertCount(4, $result['users']);
$this->assertContains('testShare2', $result['users']);
$this->assertContains('testShare3', $result['users']);
$this->assertContains('testShare4', $result['users']);
$this->assertContains('testShare5', $result['users']);
$this->assertContains($u2->getUID(), $result['users']);
$this->assertContains($u3->getUID(), $result['users']);
$this->assertContains($u4->getUID(), $result['users']);
$this->assertContains($u5->getUID(), $result['users']);
$this->assertTrue($result['public']);
$provider->delete($share1);
@ -2684,11 +2684,11 @@ class DefaultShareProviderTest extends \Test\TestCase {
$this->config
);
$u1 = $userManager->createUser('testShare1', 'test');
$u2 = $userManager->createUser('testShare2', 'test');
$u3 = $userManager->createUser('testShare3', 'test');
$u4 = $userManager->createUser('testShare4', 'test');
$u5 = $userManager->createUser('testShare5', 'test');
$u1 = $userManager->createUser(self::getUniqueID('testShare1'), 'test');
$u2 = $userManager->createUser(self::getUniqueID('testShare2'), 'test');
$u3 = $userManager->createUser(self::getUniqueID('testShare3'), 'test');
$u4 = $userManager->createUser(self::getUniqueID('testShare4'), 'test');
$u5 = $userManager->createUser(self::getUniqueID('testShare5'),'test');
$g1 = $groupManager->createGroup('group1');
$g1->addUser($u3);
@ -2744,9 +2744,9 @@ class DefaultShareProviderTest extends \Test\TestCase {
$result = $provider->getAccessList([$folder1, $folder2, $file1], true);
$this->assertCount(3, $result['users']);
$this->assertArrayHasKey('testShare2', $result['users']);
$this->assertArrayHasKey('testShare3', $result['users']);
$this->assertArrayHasKey('testShare5', $result['users']);
$this->assertArrayHasKey($u2->getUID(), $result['users']);
$this->assertArrayHasKey($u3->getUID(), $result['users']);
$this->assertArrayHasKey($u5->getUID(), $result['users']);
$this->assertTrue($result['public']);
$provider->delete($share1);

View File

@ -59,7 +59,7 @@ class SubAdminTest extends \Test\TestCase {
// Create 3 users and 3 groups
for ($i = 0; $i < 3; $i++) {
$this->users[] = $this->userManager->createUser('user'.$i, 'user');
$this->users[] = $this->userManager->createUser(self::getUniqueID('user'.$i), 'user');
$this->groups[] = $this->groupManager->createGroup('group'.$i);
}

View File

@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2021, Lukas Reschke <lukas@statuscode.ch>
*
* @author Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace Test\User;
use OC\User\UserDeletedListener;
use OC\User\UsernameDuplicationPreventionManager;
use OCP\IUser;
use OCP\User\Events\UserDeletedEvent;
use Test\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
class UserDeletedListenerTest extends TestCase {
public function testHandle() {
/** @var UsernameDuplicationPreventionManager|MockObject $usernameDuplicationPreventionManager */
$usernameDuplicationPreventionManager = $this->createMock(UsernameDuplicationPreventionManager::class);
$usernameDuplicationPreventionManager
->expects($this->once())
->method('markUsed')
->with($this->equalTo('ThisIsTheUsername'));
/** @var IUser|MockObject $mockUser */
$mockUser = $this->createMock(IUser::class);
$mockUser
->expects($this->once())
->method('getUID')
->willReturn('ThisIsTheUsername');
$listener = new UserDeletedListener($usernameDuplicationPreventionManager);
$listener->handle(new UserDeletedEvent($mockUser));
}
}

View File

@ -504,14 +504,15 @@ class UserTest extends TestCase {
->method('deleteUser')
->willReturn($result);
$emitter = new PublicEmitter();
$user = new User('foo', $backend, $this->dispatcher, $emitter);
$userId = self::getUniqueID('foo');
$user = new User($userId, $backend, $this->dispatcher, $emitter);
/**
* @param User $user
*/
$hook = function ($user) use ($test, &$hooksCalled) {
$hook = function ($user) use ($test, $userId, &$hooksCalled) {
$hooksCalled++;
$test->assertEquals('foo', $user->getUID());
$test->assertEquals($userId, $user->getUID());
};
$emitter->listen('\OC\User', 'preDelete', $hook);
@ -524,11 +525,11 @@ class UserTest extends TestCase {
if ($result) {
$config->expects($this->once())
->method('deleteAllUserValues')
->with('foo');
->with($user->getUID());
$commentsManager->expects($this->once())
->method('deleteReferencesOfActor')
->with('users', 'foo');
->with('users', $user->getUID());
$commentsManager->expects($this->once())
->method('deleteReadMarksFromUser')
->with($user);
@ -536,7 +537,7 @@ class UserTest extends TestCase {
$notification = $this->createMock(INotification::class);
$notification->expects($this->once())
->method('setUser')
->with('foo');
->with($user->getUID());
$notificationManager->expects($this->once())
->method('createNotification')

View File

@ -0,0 +1,61 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2021, Lukas Reschke <lukas@statuscode.ch>
*
* @author Lukas Reschke <lukas@statuscode.ch>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace Test\User;
use OC\User\UsernameDuplicationPreventionManager;
use Test\TestCase;
/**
* @group DB
*/
class UsernameDuplicationPreventionManagerTest extends TestCase {
/** @var UsernameDuplicationPreventionManager */
private $usernameDuplicationPreventionManager;
protected function setUp(): void {
parent::setUp();
$this->usernameDuplicationPreventionManager = \OC::$server->get(UsernameDuplicationPreventionManager::class);
}
protected function tearDown(): void {
parent::tearDown();
$this->usernameDuplicationPreventionManager->cleanUp();
}
public function testNotMarkedAsDeleted() {
$return = $this->usernameDuplicationPreventionManager->wasUsed('not_deleted_user');
$this->assertFalse($return);
}
public function testMarkedAsDeleted() {
$this->usernameDuplicationPreventionManager->markUsed('deleted_user');
$return = $this->usernameDuplicationPreventionManager->wasUsed('deleted_user');
$this->assertTrue($return);
}
}