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(); \OC_Hook::clear();
$this->user = 'test_user'; $this->user = self::getUniqueID('test_user');
$this->createUser($this->user, 'pass'); $this->createUser($this->user, 'pass');
$this->loginAsUser($this->user); $this->loginAsUser($this->user);

View File

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

View File

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

View File

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

View File

@ -69,12 +69,12 @@ class CacheTest extends TestCase {
$userManager = \OC::$server->getUserManager(); $userManager = \OC::$server->getUserManager();
$userManager->get(self::TEST_FILES_SHARING_API_USER1)->setDisplayName('User One'); $userManager->get($this->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_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 // prepare user1's dir structure
$this->view->mkdir('container'); $this->view->mkdir('container');
@ -95,14 +95,14 @@ class CacheTest extends TestCase {
$this->ownerStorage->getScanner()->scan(''); $this->ownerStorage->getScanner()->scan('');
// share "shareddir" with user2 // 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'); $node = $rootFolder->get('container/shareddir');
$share = $this->shareManager->newShare(); $share = $this->shareManager->newShare();
$share->setNode($node) $share->setNode($node)
->setShareType(IShare::TYPE_USER) ->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2) ->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1) ->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL); ->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $this->shareManager->createShare($share); $share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED); $share->setStatus(IShare::STATUS_ACCEPTED);
@ -112,18 +112,18 @@ class CacheTest extends TestCase {
$share = $this->shareManager->newShare(); $share = $this->shareManager->newShare();
$share->setNode($node) $share->setNode($node)
->setShareType(IShare::TYPE_USER) ->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2) ->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1) ->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE)); ->setPermissions(\OCP\Constants::PERMISSION_ALL & ~(\OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_DELETE));
$share = $this->shareManager->createShare($share); $share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED); $share->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share); $this->shareManager->updateShare($share);
// login as user2 // login as user2
self::loginHelper(self::TEST_FILES_SHARING_API_USER2); self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
// retrieve the shared storage // 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->sharedStorage,] = $secondView->resolvePath('files/shareddir');
$this->sharedCache = $this->sharedStorage->getCache(); $this->sharedCache = $this->sharedStorage->getCache();
} }
@ -133,9 +133,9 @@ class CacheTest extends TestCase {
$this->sharedCache->clear(); $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) { foreach ($shares as $share) {
$this->shareManager->deleteShare($share); $this->shareManager->deleteShare($share);
} }
@ -259,14 +259,14 @@ class CacheTest extends TestCase {
'name' => 'shareddir', 'name' => 'shareddir',
'path' => 'files/shareddir', 'path' => 'files/shareddir',
'mimetype' => 'httpd/unix-directory', 'mimetype' => 'httpd/unix-directory',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One', 'displayname_owner' => 'User One',
], ],
[ [
'name' => 'shared single file.txt', 'name' => 'shared single file.txt',
'path' => 'files/shared single file.txt', 'path' => 'files/shared single file.txt',
'mimetype' => 'text/plain', 'mimetype' => 'text/plain',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One', 'displayname_owner' => 'User One',
], ],
], ],
@ -283,21 +283,21 @@ class CacheTest extends TestCase {
'name' => 'bar.txt', 'name' => 'bar.txt',
'path' => 'bar.txt', 'path' => 'bar.txt',
'mimetype' => 'text/plain', 'mimetype' => 'text/plain',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One', 'displayname_owner' => 'User One',
], ],
[ [
'name' => 'emptydir', 'name' => 'emptydir',
'path' => 'emptydir', 'path' => 'emptydir',
'mimetype' => 'httpd/unix-directory', 'mimetype' => 'httpd/unix-directory',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One', 'displayname_owner' => 'User One',
], ],
[ [
'name' => 'subdir', 'name' => 'subdir',
'path' => 'subdir', 'path' => 'subdir',
'mimetype' => 'httpd/unix-directory', 'mimetype' => 'httpd/unix-directory',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One', 'displayname_owner' => 'User One',
], ],
], ],
@ -306,23 +306,23 @@ class CacheTest extends TestCase {
} }
public function testGetFolderContentsWhenSubSubdirShared() { 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'); $node = $rootFolder->get('container/shareddir/subdir');
$share = $this->shareManager->newShare(); $share = $this->shareManager->newShare();
$share->setNode($node) $share->setNode($node)
->setShareType(IShare::TYPE_USER) ->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER3) ->setSharedWith($this->TEST_FILES_SHARING_API_USER3)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1) ->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL); ->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $this->shareManager->createShare($share); $share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED); $share->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share); $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'); $results = $thirdView->getDirectoryContent('/subdir');
$this->verifyFiles( $this->verifyFiles(
@ -331,28 +331,28 @@ class CacheTest extends TestCase {
'name' => 'another too.txt', 'name' => 'another too.txt',
'path' => 'another too.txt', 'path' => 'another too.txt',
'mimetype' => 'text/plain', 'mimetype' => 'text/plain',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One', 'displayname_owner' => 'User One',
], ],
[ [
'name' => 'another.txt', 'name' => 'another.txt',
'path' => 'another.txt', 'path' => 'another.txt',
'mimetype' => 'text/plain', 'mimetype' => 'text/plain',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One', 'displayname_owner' => 'User One',
], ],
[ [
'name' => 'not a text file.xml', 'name' => 'not a text file.xml',
'path' => 'not a text file.xml', 'path' => 'not a text file.xml',
'mimetype' => 'application/xml', 'mimetype' => 'application/xml',
'uid_owner' => self::TEST_FILES_SHARING_API_USER1, 'uid_owner' => $this->TEST_FILES_SHARING_API_USER1,
'displayname_owner' => 'User One', 'displayname_owner' => 'User One',
], ],
], ],
$results $results
); );
self::loginHelper(self::TEST_FILES_SHARING_API_USER1); self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->shareManager->deleteShare($share); $this->shareManager->deleteShare($share);
} }
@ -390,17 +390,17 @@ class CacheTest extends TestCase {
} }
public function testGetPathByIdDirectShare() { 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'); \OC\Files\Filesystem::file_put_contents('test.txt', 'foo');
$info = \OC\Files\Filesystem::getFileInfo('test.txt'); $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'); $node = $rootFolder->get('test.txt');
$share = $this->shareManager->newShare(); $share = $this->shareManager->newShare();
$share->setNode($node) $share->setNode($node)
->setShareType(IShare::TYPE_USER) ->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2) ->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1) ->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE); ->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
$share = $this->shareManager->createShare($share); $share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED); $share->setStatus(IShare::STATUS_ACCEPTED);
@ -408,9 +408,9 @@ class CacheTest extends TestCase {
\OC_Util::tearDownFS(); \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')); $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 * @var \OCA\Files_Sharing\SharedStorage $sharedStorage
*/ */
@ -420,29 +420,29 @@ class CacheTest extends TestCase {
} }
public function testGetPathByIdShareSubFolder() { 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');
\OC\Files\Filesystem::mkdir('foo/bar'); \OC\Files\Filesystem::mkdir('foo/bar');
\OC\Files\Filesystem::touch('foo/bar/test.txt'); \OC\Files\Filesystem::touch('foo/bar/test.txt');
$folderInfo = \OC\Files\Filesystem::getFileInfo('foo'); $folderInfo = \OC\Files\Filesystem::getFileInfo('foo');
$fileInfo = \OC\Files\Filesystem::getFileInfo('foo/bar/test.txt'); $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'); $node = $rootFolder->get('foo');
$share = $this->shareManager->newShare(); $share = $this->shareManager->newShare();
$share->setNode($node) $share->setNode($node)
->setShareType(IShare::TYPE_USER) ->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2) ->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1) ->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL); ->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $this->shareManager->createShare($share); $share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED); $share->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share); $this->shareManager->updateShare($share);
\OC_Util::tearDownFS(); \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')); $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 * @var \OCA\Files_Sharing\SharedStorage $sharedStorage
*/ */
@ -453,28 +453,28 @@ class CacheTest extends TestCase {
} }
public function testNumericStorageId() { public function testNumericStorageId() {
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');
$rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1); $rootFolder = \OC::$server->getUserFolder($this->TEST_FILES_SHARING_API_USER1);
$node = $rootFolder->get('foo'); $node = $rootFolder->get('foo');
$share = $this->shareManager->newShare(); $share = $this->shareManager->newShare();
$share->setNode($node) $share->setNode($node)
->setShareType(IShare::TYPE_USER) ->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2) ->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1) ->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL); ->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $this->shareManager->createShare($share); $share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED); $share->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share); $this->shareManager->updateShare($share);
\OC_Util::tearDownFS(); \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')); $this->assertTrue(\OC\Files\Filesystem::file_exists('/foo'));
/** @var SharedStorage $sharedStorage */ /** @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()); $this->assertEquals($sourceStorage->getCache()->getNumericStorageId(), $sharedStorage->getCache()->getNumericStorageId());
} }
@ -489,29 +489,29 @@ class CacheTest extends TestCase {
'root' => 'jail' 'root' => 'jail'
]); ]);
$sourceStorage->getScanner()->scan(''); $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'); $node = $rootFolder->get('foo/sub');
$share = $this->shareManager->newShare(); $share = $this->shareManager->newShare();
$share->setNode($node) $share->setNode($node)
->setShareType(IShare::TYPE_USER) ->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2) ->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1) ->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL); ->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $this->shareManager->createShare($share); $share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED); $share->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share); $this->shareManager->updateShare($share);
\OC_Util::tearDownFS(); \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')); $this->assertEquals('foo', \OC\Files\Filesystem::file_get_contents('/sub/foo.txt'));
\OC\Files\Filesystem::file_put_contents('/sub/bar.txt', 'bar'); \OC\Files\Filesystem::file_put_contents('/sub/bar.txt', 'bar');
/** @var SharedStorage $sharedStorage */ /** @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')); $this->assertTrue($sharedStorage->getCache()->inCache('bar.txt'));
@ -528,27 +528,27 @@ class CacheTest extends TestCase {
'root' => 'jail' 'root' => 'jail'
]); ]);
$sourceStorage->getScanner()->scan(''); $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'); $node = $rootFolder->get('foo/sub');
$share = $this->shareManager->newShare(); $share = $this->shareManager->newShare();
$share->setNode($node) $share->setNode($node)
->setShareType(IShare::TYPE_USER) ->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2) ->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1) ->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL); ->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $this->shareManager->createShare($share); $share = $this->shareManager->createShare($share);
$share->setStatus(IShare::STATUS_ACCEPTED); $share->setStatus(IShare::STATUS_ACCEPTED);
$this->shareManager->updateShare($share); $this->shareManager->updateShare($share);
\OC_Util::tearDownFS(); \OC_Util::tearDownFS();
self::loginHelper(self::TEST_FILES_SHARING_API_USER2); self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
/** @var SharedStorage $sharedStorage */ /** @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"); $results = $sharedStorage->getCache()->search("foo.txt");
$this->assertCount(1, $results); $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) * "user4" puts the received "inside" folder into "sub1/sub2/inside" (this is to check if it propagates across multiple subfolders)
*/ */
protected function setUpShares() { protected function setUpShares() {
$this->fileIds[self::TEST_FILES_SHARING_API_USER1] = []; $this->fileIds[$this->TEST_FILES_SHARING_API_USER1] = [];
$this->fileIds[self::TEST_FILES_SHARING_API_USER2] = []; $this->fileIds[$this->TEST_FILES_SHARING_API_USER2] = [];
$this->fileIds[self::TEST_FILES_SHARING_API_USER3] = []; $this->fileIds[$this->TEST_FILES_SHARING_API_USER3] = [];
$this->fileIds[self::TEST_FILES_SHARING_API_USER4] = []; $this->fileIds[$this->TEST_FILES_SHARING_API_USER4] = [];
$rootFolder = \OC::$server->getRootFolder(); $rootFolder = \OC::$server->getRootFolder();
$shareManager = \OC::$server->getShareManager(); $shareManager = \OC::$server->getShareManager();
$this->rootView = new View(''); $this->rootView = new View('');
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); $this->loginAsUser($this->TEST_FILES_SHARING_API_USER1);
$view1 = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files'); $view1 = new View('/' . $this->TEST_FILES_SHARING_API_USER1 . '/files');
$view1->mkdir('/sub1/sub2/folder/inside'); $view1->mkdir('/sub1/sub2/folder/inside');
$view1->mkdir('/directReshare'); $view1->mkdir('/directReshare');
$view1->mkdir('/sub1/sub2/folder/other'); $view1->mkdir('/sub1/sub2/folder/other');
@ -72,117 +72,117 @@ class EtagPropagationTest extends PropagationTestCase {
$fileInfo = $view1->getFileInfo('/foo.txt'); $fileInfo = $view1->getFileInfo('/foo.txt');
$this->assertInstanceOf('\OC\Files\FileInfo', $fileInfo); $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'); ->get('/foo.txt');
$share = $shareManager->newShare(); $share = $shareManager->newShare();
$share->setNode($node) $share->setNode($node)
->setShareType(IShare::TYPE_USER) ->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2) ->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1) ->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE); ->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE);
$share = $shareManager->createShare($share); $share = $shareManager->createShare($share);
$this->shareManager->acceptShare($share, self::TEST_FILES_SHARING_API_USER2); $this->shareManager->acceptShare($share, $this->TEST_FILES_SHARING_API_USER2);
$node = $rootFolder->getUserFolder(self::TEST_FILES_SHARING_API_USER1) $node = $rootFolder->getUserFolder($this->TEST_FILES_SHARING_API_USER1)
->get('/sub1/sub2/folder'); ->get('/sub1/sub2/folder');
$share = $shareManager->newShare(); $share = $shareManager->newShare();
$share->setNode($node) $share->setNode($node)
->setShareType(IShare::TYPE_USER) ->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2) ->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1) ->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL); ->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $shareManager->createShare($share); $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 = $shareManager->newShare();
$share->setNode($node) $share->setNode($node)
->setShareType(IShare::TYPE_USER) ->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER3) ->setSharedWith($this->TEST_FILES_SHARING_API_USER3)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1) ->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL); ->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $shareManager->createShare($share); $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'); $folderInfo = $view1->getFileInfo('/directReshare');
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo); $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'); ->get('/directReshare');
$share = $shareManager->newShare(); $share = $shareManager->newShare();
$share->setNode($node) $share->setNode($node)
->setShareType(IShare::TYPE_USER) ->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER2) ->setSharedWith($this->TEST_FILES_SHARING_API_USER2)
->setSharedBy(self::TEST_FILES_SHARING_API_USER1) ->setSharedBy($this->TEST_FILES_SHARING_API_USER1)
->setPermissions(\OCP\Constants::PERMISSION_ALL); ->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $shareManager->createShare($share); $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[$this->TEST_FILES_SHARING_API_USER1][''] = $view1->getFileInfo('')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER1]['sub1'] = $view1->getFileInfo('sub1')->getId(); $this->fileIds[$this->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]['sub1/sub2'] = $view1->getFileInfo('sub1/sub2')->getId();
/* /*
* User 2 * User 2
*/ */
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2); $this->loginAsUser($this->TEST_FILES_SHARING_API_USER2);
$view2 = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); $view2 = new View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
$view2->mkdir('/sub1/sub2'); $view2->mkdir('/sub1/sub2');
$view2->rename('/folder', '/sub1/sub2/folder'); $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'); $insideInfo = $view2->getFileInfo('/sub1/sub2/folder/inside');
$this->assertInstanceOf('\OC\Files\FileInfo', $insideInfo); $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'); ->get('/sub1/sub2/folder/inside');
$share = $shareManager->newShare(); $share = $shareManager->newShare();
$share->setNode($node) $share->setNode($node)
->setShareType(IShare::TYPE_USER) ->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER4) ->setSharedWith($this->TEST_FILES_SHARING_API_USER4)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2) ->setSharedBy($this->TEST_FILES_SHARING_API_USER2)
->setPermissions(\OCP\Constants::PERMISSION_ALL); ->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $shareManager->createShare($share); $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'); $folderInfo = $view2->getFileInfo('/directReshare');
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo); $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'); ->get('/directReshare');
$share = $shareManager->newShare(); $share = $shareManager->newShare();
$share->setNode($node) $share->setNode($node)
->setShareType(IShare::TYPE_USER) ->setShareType(IShare::TYPE_USER)
->setSharedWith(self::TEST_FILES_SHARING_API_USER4) ->setSharedWith($this->TEST_FILES_SHARING_API_USER4)
->setSharedBy(self::TEST_FILES_SHARING_API_USER2) ->setSharedBy($this->TEST_FILES_SHARING_API_USER2)
->setPermissions(\OCP\Constants::PERMISSION_ALL); ->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $shareManager->createShare($share); $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[$this->TEST_FILES_SHARING_API_USER2][''] = $view2->getFileInfo('')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER2]['sub1'] = $view2->getFileInfo('sub1')->getId(); $this->fileIds[$this->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]['sub1/sub2'] = $view2->getFileInfo('sub1/sub2')->getId();
/* /*
* User 3 * User 3
*/ */
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER3); $this->loginAsUser($this->TEST_FILES_SHARING_API_USER3);
$view3 = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files'); $view3 = new View('/' . $this->TEST_FILES_SHARING_API_USER3 . '/files');
$view3->mkdir('/sub1/sub2'); $view3->mkdir('/sub1/sub2');
$view3->rename('/folder', '/sub1/sub2/folder'); $view3->rename('/folder', '/sub1/sub2/folder');
$this->fileIds[self::TEST_FILES_SHARING_API_USER3][''] = $view3->getFileInfo('')->getId(); $this->fileIds[$this->TEST_FILES_SHARING_API_USER3][''] = $view3->getFileInfo('')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER3]['sub1'] = $view3->getFileInfo('sub1')->getId(); $this->fileIds[$this->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]['sub1/sub2'] = $view3->getFileInfo('sub1/sub2')->getId();
/* /*
* User 4 * User 4
*/ */
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER4); $this->loginAsUser($this->TEST_FILES_SHARING_API_USER4);
$view4 = new View('/' . self::TEST_FILES_SHARING_API_USER4 . '/files'); $view4 = new View('/' . $this->TEST_FILES_SHARING_API_USER4 . '/files');
$view4->mkdir('/sub1/sub2'); $view4->mkdir('/sub1/sub2');
$view4->rename('/inside', '/sub1/sub2/inside'); $view4->rename('/inside', '/sub1/sub2/inside');
$this->fileIds[self::TEST_FILES_SHARING_API_USER4][''] = $view4->getFileInfo('')->getId(); $this->fileIds[$this->TEST_FILES_SHARING_API_USER4][''] = $view4->getFileInfo('')->getId();
$this->fileIds[self::TEST_FILES_SHARING_API_USER4]['sub1'] = $view4->getFileInfo('sub1')->getId(); $this->fileIds[$this->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]['sub1/sub2'] = $view4->getFileInfo('sub1/sub2')->getId();
foreach ($this->fileIds as $user => $ids) { foreach ($this->fileIds as $user => $ids) {
$this->loginAsUser($user); $this->loginAsUser($user);
@ -195,122 +195,122 @@ class EtagPropagationTest extends PropagationTestCase {
} }
public function testOwnerWritesToShare() { 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'); 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, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3]); $this->TEST_FILES_SHARING_API_USER3]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testOwnerWritesToSingleFileShare() { 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'); Filesystem::file_put_contents('/foo.txt', 'longer_bar');
$t = (int)Filesystem::filemtime('/foo.txt') - 1; $t = (int)Filesystem::filemtime('/foo.txt') - 1;
Filesystem::touch('/foo.txt', $t); Filesystem::touch('/foo.txt', $t);
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER4, self::TEST_FILES_SHARING_API_USER3]); $this->assertEtagsNotChanged([$this->TEST_FILES_SHARING_API_USER4, $this->TEST_FILES_SHARING_API_USER3]);
$this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2]); $this->assertEtagsChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testOwnerWritesToShareWithReshare() { 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'); 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, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]); $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testOwnerRenameInShare() { public function testOwnerRenameInShare() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); $this->loginAsUser($this->TEST_FILES_SHARING_API_USER1);
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER4]); $this->assertEtagsNotChanged([$this->TEST_FILES_SHARING_API_USER4]);
Filesystem::rename('/sub1/sub2/folder/file.txt', '/sub1/sub2/folder/renamed.txt'); 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, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3]); $this->TEST_FILES_SHARING_API_USER3]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testOwnerRenameInReShare() { 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'); 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, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]); $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testOwnerRenameIntoReShare() { 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'); 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, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]); $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testOwnerRenameOutOfReShare() { 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'); 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, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]); $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testOwnerDeleteInShare() { 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'); Filesystem::unlink('/sub1/sub2/folder/file.txt');
$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, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3]); $this->TEST_FILES_SHARING_API_USER3]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testOwnerDeleteInReShare() { 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'); Filesystem::unlink('/sub1/sub2/folder/inside/file.txt');
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]); $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testOwnerUnshares() { public function testOwnerUnshares() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); $this->loginAsUser($this->TEST_FILES_SHARING_API_USER1);
$folderInfo = $this->rootView->getFileInfo('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder'); $folderInfo = $this->rootView->getFileInfo('/' . $this->TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder');
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo); $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(); $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) { 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); $shareManager->deleteShare($share);
} }
} }
$this->assertEtagsForFoldersChanged([ $this->assertEtagsForFoldersChanged([
// direct recipient affected // direct recipient affected
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
]); ]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testOwnerUnsharesFlatReshares() { public function testOwnerUnsharesFlatReshares() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER1); $this->loginAsUser($this->TEST_FILES_SHARING_API_USER1);
$folderInfo = $this->rootView->getFileInfo('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder/inside'); $folderInfo = $this->rootView->getFileInfo('/' . $this->TEST_FILES_SHARING_API_USER1 . '/files/sub1/sub2/folder/inside');
$this->assertInstanceOf('\OC\Files\FileInfo', $folderInfo); $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(); $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) { foreach ($shares as $share) {
$shareManager->deleteShare($share); $shareManager->deleteShare($share);
@ -318,150 +318,150 @@ class EtagPropagationTest extends PropagationTestCase {
$this->assertEtagsForFoldersChanged([ $this->assertEtagsForFoldersChanged([
// direct recipient affected // direct recipient affected
self::TEST_FILES_SHARING_API_USER4, $this->TEST_FILES_SHARING_API_USER4,
]); ]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testRecipientUnsharesFromSelf() { public function testRecipientUnsharesFromSelf() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2); $this->loginAsUser($this->TEST_FILES_SHARING_API_USER2);
$ls = $this->rootView->getDirectoryContent('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub1/sub2/'); $ls = $this->rootView->getDirectoryContent('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files/sub1/sub2/');
$this->assertTrue( $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([ $this->assertEtagsForFoldersChanged([
// direct recipient affected // direct recipient affected
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
]); ]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testRecipientWritesToShare() { 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'); 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([ $this->assertEtagsForFoldersChanged([
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3 $this->TEST_FILES_SHARING_API_USER3
]); ]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testRecipientWritesToReshare() { 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'); 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, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]); $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testRecipientWritesToOtherRecipientsReshare() { 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'); 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, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]); $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testRecipientRenameInShare() { 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'); Filesystem::rename('/sub1/sub2/folder/file.txt', '/sub1/sub2/folder/renamed.txt');
$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, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3]); $this->TEST_FILES_SHARING_API_USER3]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testRecipientRenameInReShare() { 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'); 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, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]); $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testRecipientRenameResharedFolder() { public function testRecipientRenameResharedFolder() {
$this->loginAsUser(self::TEST_FILES_SHARING_API_USER2); $this->loginAsUser($this->TEST_FILES_SHARING_API_USER2);
Filesystem::rename('/directReshare', '/sub1/directReshare'); 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->assertEtagsNotChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertEtagsChanged([self::TEST_FILES_SHARING_API_USER2]); $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(); $this->assertAllUnchanged();
} }
public function testRecipientDeleteInShare() { 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'); Filesystem::unlink('/sub1/sub2/folder/file.txt');
$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, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3]); $this->TEST_FILES_SHARING_API_USER3]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testRecipientDeleteInReShare() { 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'); Filesystem::unlink('/sub1/sub2/folder/inside/file.txt');
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]); $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testReshareRecipientWritesToReshare() { 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'); Filesystem::file_put_contents('/sub1/sub2/inside/asd.txt', 'bar');
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]); $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testReshareRecipientRenameInReShare() { 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'); 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, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]); $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testReshareRecipientDeleteInReShare() { 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'); Filesystem::unlink('/sub1/sub2/inside/file.txt');
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]); $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testRecipientUploadInDirectReshare() { 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'); Filesystem::file_put_contents('/directReshare/test.txt', 'sad');
$this->assertEtagsNotChanged([self::TEST_FILES_SHARING_API_USER3]); $this->assertEtagsNotChanged([$this->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->assertEtagsChanged([$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER4]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }
public function testEtagChangeOnPermissionsChange() { 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'); $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 */ /** @var \OCP\Share\IShare[] $shares */
$shares = array_filter($shares, function (\OCP\Share\IShare $share) { $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); $this->assertCount(1, $shares);
@ -469,7 +469,7 @@ class EtagPropagationTest extends PropagationTestCase {
$share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE); $share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_SHARE);
$this->shareManager->updateShare($share); $this->shareManager->updateShare($share);
$this->assertEtagsForFoldersChanged([self::TEST_FILES_SHARING_API_USER2]); $this->assertEtagsForFoldersChanged([$this->TEST_FILES_SHARING_API_USER2]);
$this->assertAllUnchanged(); $this->assertAllUnchanged();
} }

View File

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

View File

@ -99,8 +99,8 @@ abstract class PropagationTestCase extends TestCase {
} }
protected function assertAllUnchanged() { protected function assertAllUnchanged() {
$users = [self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER2, $users = [$this->TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER2,
self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER4]; $this->TEST_FILES_SHARING_API_USER3, $this->TEST_FILES_SHARING_API_USER4];
$this->assertEtagsNotChanged($users); $this->assertEtagsNotChanged($users);
} }
} }

View File

@ -59,7 +59,7 @@ class ShareTest extends TestCase {
} }
protected function tearDown(): void { 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->unlink($this->filename);
$this->view->deleteAll($this->folder); $this->view->deleteAll($this->folder);
@ -73,43 +73,43 @@ class ShareTest extends TestCase {
$userManager = \OC::$server->getUserManager(); $userManager = \OC::$server->getUserManager();
$testGroup = $groupManager->createGroup('testGroup'); $testGroup = $groupManager->createGroup('testGroup');
$user1 = $userManager->get(self::TEST_FILES_SHARING_API_USER2); $user1 = $userManager->get($this->TEST_FILES_SHARING_API_USER2);
$user2 = $userManager->get(self::TEST_FILES_SHARING_API_USER3); $user2 = $userManager->get($this->TEST_FILES_SHARING_API_USER3);
$testGroup->addUser($user1); $testGroup->addUser($user1);
$testGroup->addUser($user2); $testGroup->addUser($user2);
$share1 = $this->share( $share1 = $this->share(
IShare::TYPE_USER, IShare::TYPE_USER,
$this->filename, $this->filename,
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
); );
$share2 = $this->share( $share2 = $this->share(
IShare::TYPE_GROUP, IShare::TYPE_GROUP,
$this->filename, $this->filename,
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
'testGroup', 'testGroup',
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE \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, $this->TEST_FILES_SHARING_API_USER2);
$this->shareManager->acceptShare($share2, self::TEST_FILES_SHARING_API_USER3); $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)); $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)); $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); \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 // both group share and user share should be gone
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename)); $this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename));
// for user3 nothing should change // 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->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
$this->shareManager->deleteShare($share1); $this->shareManager->deleteShare($share1);
@ -135,8 +135,8 @@ class ShareTest extends TestCase {
$share = $this->share( $share = $this->share(
IShare::TYPE_USER, IShare::TYPE_USER,
$this->filename, $this->filename,
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
); );
@ -145,12 +145,12 @@ class ShareTest extends TestCase {
$share = $this->share( $share = $this->share(
IShare::TYPE_USER, IShare::TYPE_USER,
$this->folder, $this->folder,
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL \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($this->filename));
$this->assertTrue(\OC\Files\Filesystem::file_exists('/Shared/subfolder/' . $this->folder)); $this->assertTrue(\OC\Files\Filesystem::file_exists('/Shared/subfolder/' . $this->folder));
@ -162,27 +162,27 @@ class ShareTest extends TestCase {
public function testShareWithGroupUniqueName() { public function testShareWithGroupUniqueName() {
$this->markTestSkipped('TODO: Disable because fails on drone'); $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'); \OC\Files\Filesystem::file_put_contents('test.txt', 'test');
$share = $this->share( $share = $this->share(
IShare::TYPE_GROUP, IShare::TYPE_GROUP,
'test.txt', 'test.txt',
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_GROUP1, self::TEST_FILES_SHARING_API_GROUP1,
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE \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]; $share = $shares[0];
$this->assertSame('/test.txt' ,$share->getTarget()); $this->assertSame('/test.txt' ,$share->getTarget());
$this->assertSame(19, $share->getPermissions()); $this->assertSame(19, $share->getPermissions());
\OC\Files\Filesystem::rename('test.txt', 'new test.txt'); \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]; $share = $shares[0];
$this->assertSame('/new test.txt' ,$share->getTarget()); $this->assertSame('/new test.txt' ,$share->getTarget());
$this->assertSame(19, $share->getPermissions()); $this->assertSame(19, $share->getPermissions());
@ -190,8 +190,8 @@ class ShareTest extends TestCase {
$share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE); $share->setPermissions(\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE);
$this->shareManager->updateShare($share); $this->shareManager->updateShare($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]; $share = $shares[0];
$this->assertSame('/new test.txt' ,$share->getTarget()); $this->assertSame('/new test.txt' ,$share->getTarget());
@ -208,8 +208,8 @@ class ShareTest extends TestCase {
$this->share( $this->share(
IShare::TYPE_USER, IShare::TYPE_USER,
$this->filename, $this->filename,
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
$permission $permission
); );
} catch (\Exception $e) { } catch (\Exception $e) {
@ -239,15 +239,15 @@ class ShareTest extends TestCase {
$this->share( $this->share(
IShare::TYPE_USER, IShare::TYPE_USER,
$this->filename, $this->filename,
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_READ \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); $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( $share = $this->share(
IShare::TYPE_USER, IShare::TYPE_USER,
$this->folder, $this->folder,
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL); \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); $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()); $share = $this->shareManager->getShareById($share->getFullId());
$this->assertSame('/foo/bar' . $this->folder, $share->getTarget()); $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 should have moved up
$share = $this->shareManager->getShareById($share->getFullId()); $share = $this->shareManager->getShareById($share->getFullId());
$this->assertSame($this->folder, $share->getTarget()); $this->assertSame($this->folder, $share->getTarget());
//cleanup //cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1); self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->shareManager->deleteShare($share); $this->shareManager->deleteShare($share);
$this->view->unlink($this->folder); $this->view->unlink($this->folder);
} }
@ -118,13 +118,13 @@ class SharedMountTest extends TestCase {
$share = $this->share( $share = $this->share(
IShare::TYPE_USER, IShare::TYPE_USER,
$this->folder, $this->folder,
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL \OCP\Constants::PERMISSION_ALL
); );
self::loginHelper(self::TEST_FILES_SHARING_API_USER2); self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
$user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files'); $user2View = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2 . '/files');
$this->assertTrue($user2View->file_exists($this->folder)); $this->assertTrue($user2View->file_exists($this->folder));
// create a local folder // create a local folder
@ -143,13 +143,13 @@ class SharedMountTest extends TestCase {
$this->assertTrue($result); $this->assertTrue($result);
//enforce reload of the mount points //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 //mount point should be back at the root
$this->assertTrue($user2View->is_dir($this->folder)); $this->assertTrue($user2View->is_dir($this->folder));
//cleanup //cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1); self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->view->unlink($this->folder); $this->view->unlink($this->folder);
} }
@ -157,24 +157,24 @@ class SharedMountTest extends TestCase {
$share = $this->share( $share = $this->share(
IShare::TYPE_USER, IShare::TYPE_USER,
$this->filename, $this->filename,
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE \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'); \OC\Files\Filesystem::rename($this->filename, $this->filename . '_renamed');
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename . '_renamed')); $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename . '_renamed'));
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename)); $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->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename . '_renamed')); $this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename . '_renamed'));
// rename back to original name // 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); \OC\Files\Filesystem::rename($this->filename . '_renamed', $this->filename);
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename . '_renamed')); $this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename . '_renamed'));
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename)); $this->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
@ -189,9 +189,9 @@ class SharedMountTest extends TestCase {
*/ */
public function testMoveGroupShare() { public function testMoveGroupShare() {
$testGroup = $this->groupManager->createGroup('testGroup'); $testGroup = $this->groupManager->createGroup('testGroup');
$user1 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER1); $user1 = $this->userManager->get($this->TEST_FILES_SHARING_API_USER1);
$user2 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER2); $user2 = $this->userManager->get($this->TEST_FILES_SHARING_API_USER2);
$user3 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER3); $user3 = $this->userManager->get($this->TEST_FILES_SHARING_API_USER3);
$testGroup->addUser($user1); $testGroup->addUser($user1);
$testGroup->addUser($user2); $testGroup->addUser($user2);
$testGroup->addUser($user3); $testGroup->addUser($user3);
@ -200,7 +200,7 @@ class SharedMountTest extends TestCase {
$share = $this->share( $share = $this->share(
IShare::TYPE_GROUP, IShare::TYPE_GROUP,
$this->filename, $this->filename,
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
'testGroup', 'testGroup',
\OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE \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, $user2->getUID());
$this->shareManager->acceptShare($share, $user3->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)); $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->assertTrue(\OC\Files\Filesystem::file_exists('newFileName'));
$this->assertFalse(\OC\Files\Filesystem::file_exists($this->filename)); $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->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
$this->assertFalse(\OC\Files\Filesystem::file_exists('newFileName')); $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->assertTrue(\OC\Files\Filesystem::file_exists($this->filename));
$this->assertFalse(\OC\Files\Filesystem::file_exists('newFileName')); $this->assertFalse(\OC\Files\Filesystem::file_exists('newFileName'));
//cleanup //cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1); self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->shareManager->deleteShare($share); $this->shareManager->deleteShare($share);
$testGroup->removeUser($user1); $testGroup->removeUser($user1);
$testGroup->removeUser($user2); $testGroup->removeUser($user2);
@ -270,9 +270,9 @@ class SharedMountTest extends TestCase {
*/ */
public function testPermissionUpgradeOnUserDeletedGroupShare() { public function testPermissionUpgradeOnUserDeletedGroupShare() {
$testGroup = $this->groupManager->createGroup('testGroup'); $testGroup = $this->groupManager->createGroup('testGroup');
$user1 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER1); $user1 = $this->userManager->get($this->TEST_FILES_SHARING_API_USER1);
$user2 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER2); $user2 = $this->userManager->get($this->TEST_FILES_SHARING_API_USER2);
$user3 = $this->userManager->get(self::TEST_FILES_SHARING_API_USER3); $user3 = $this->userManager->get($this->TEST_FILES_SHARING_API_USER3);
$testGroup->addUser($user1); $testGroup->addUser($user1);
$testGroup->addUser($user2); $testGroup->addUser($user2);
$testGroup->addUser($user3); $testGroup->addUser($user3);
@ -284,7 +284,7 @@ class SharedMountTest extends TestCase {
$share = $this->share( $share = $this->share(
IShare::TYPE_GROUP, IShare::TYPE_GROUP,
$this->folder, $this->folder,
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
'testGroup', 'testGroup',
\OCP\Constants::PERMISSION_READ \OCP\Constants::PERMISSION_READ
); );
@ -293,9 +293,9 @@ class SharedMountTest extends TestCase {
$this->shareManager->acceptShare($share, $user3->getUID()); $this->shareManager->acceptShare($share, $user3->getUID());
// Login as user 2 and verify the item exists // 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)); $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->assertNotEmpty($result);
$this->assertEquals(\OCP\Constants::PERMISSION_READ, $result->getPermissions()); $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)); $this->assertFalse(\OC\Files\Filesystem::file_exists($this->folder));
// Verify we do not get a share // 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()); $this->assertEquals(0, $result->getPermissions());
// Login as user 1 again and change permissions // 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->setPermissions(\OCP\Constants::PERMISSION_ALL);
$share = $this->shareManager->updateShare($share); $share = $this->shareManager->updateShare($share);
// Login as user 2 and verify // 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)); $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->assertEquals(0, $result->getPermissions());
$this->shareManager->deleteShare($share); $this->shareManager->deleteShare($share);
//cleanup //cleanup
self::loginHelper(self::TEST_FILES_SHARING_API_USER1); self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$testGroup->removeUser($user1); $testGroup->removeUser($user1);
$testGroup->removeUser($user2); $testGroup->removeUser($user2);
$testGroup->removeUser($user3); $testGroup->removeUser($user3);

View File

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

View File

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

View File

@ -48,10 +48,10 @@ use Test\Traits\MountProviderTrait;
abstract class TestCase extends \Test\TestCase { abstract class TestCase extends \Test\TestCase {
use MountProviderTrait; use MountProviderTrait;
public const TEST_FILES_SHARING_API_USER1 = "test-share-user1"; public $TEST_FILES_SHARING_API_USER1 = "test-share-user1-";
public const TEST_FILES_SHARING_API_USER2 = "test-share-user2"; public $TEST_FILES_SHARING_API_USER2 = "test-share-user2-";
public const TEST_FILES_SHARING_API_USER3 = "test-share-user3"; public $TEST_FILES_SHARING_API_USER3 = "test-share-user3-";
public const TEST_FILES_SHARING_API_USER4 = "test-share-user4"; public $TEST_FILES_SHARING_API_USER4 = "test-share-user4-";
public const TEST_FILES_SHARING_API_GROUP1 = "test-share-group1"; public const TEST_FILES_SHARING_API_GROUP1 = "test-share-group1";
@ -69,8 +69,8 @@ abstract class TestCase extends \Test\TestCase {
/** @var \OCP\Files\IRootFolder */ /** @var \OCP\Files\IRootFolder */
protected $rootFolder; protected $rootFolder;
public static function setUpBeforeClass(): void { protected function setUp(): void {
parent::setUpBeforeClass(); parent::setUp();
new Application(); new Application();
@ -82,13 +82,19 @@ abstract class TestCase extends \Test\TestCase {
\OC_Hook::clear('OCP\\Share'); \OC_Hook::clear('OCP\\Share');
\OC::registerShareHooks(\OC::$server->getSystemConfig()); \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 // create users
$backend = new \Test\Util\User\Dummy(); $backend = new \Test\Util\User\Dummy();
\OC_User::useBackend($backend); \OC_User::useBackend($backend);
$backend->createUser(self::TEST_FILES_SHARING_API_USER1, self::TEST_FILES_SHARING_API_USER1); $backend->createUser($this->TEST_FILES_SHARING_API_USER1, $this->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_USER2, $this->TEST_FILES_SHARING_API_USER2);
$backend->createUser(self::TEST_FILES_SHARING_API_USER3, self::TEST_FILES_SHARING_API_USER3); $backend->createUser($this->TEST_FILES_SHARING_API_USER3, $this->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_USER4, $this->TEST_FILES_SHARING_API_USER4);
// create group // create group
$groupBackend = new \Test\Util\Group\Dummy(); $groupBackend = new \Test\Util\Group\Dummy();
@ -97,56 +103,36 @@ abstract class TestCase extends \Test\TestCase {
$groupBackend->createGroup('group1'); $groupBackend->createGroup('group1');
$groupBackend->createGroup('group2'); $groupBackend->createGroup('group2');
$groupBackend->createGroup('group3'); $groupBackend->createGroup('group3');
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER1, 'group'); $groupBackend->addToGroup($this->TEST_FILES_SHARING_API_USER1, 'group');
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER2, 'group'); $groupBackend->addToGroup($this->TEST_FILES_SHARING_API_USER2, 'group');
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER3, 'group'); $groupBackend->addToGroup($this->TEST_FILES_SHARING_API_USER3, 'group');
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER2, 'group1'); $groupBackend->addToGroup($this->TEST_FILES_SHARING_API_USER2, 'group1');
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER3, 'group2'); $groupBackend->addToGroup($this->TEST_FILES_SHARING_API_USER3, 'group2');
$groupBackend->addToGroup(self::TEST_FILES_SHARING_API_USER4, 'group3'); $groupBackend->addToGroup($this->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_USER2, self::TEST_FILES_SHARING_API_GROUP1);
\OC::$server->getGroupManager()->addBackend($groupBackend); \OC::$server->getGroupManager()->addBackend($groupBackend);
}
protected function setUp(): void {
parent::setUp();
//login as user1 //login as user1
self::loginHelper(self::TEST_FILES_SHARING_API_USER1); self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->data = 'foobar'; $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->shareManager = \OC::$server->getShareManager();
$this->rootFolder = \OC::$server->getRootFolder(); $this->rootFolder = \OC::$server->getRootFolder();
} }
protected function tearDown(): void { 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 // 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) { if ($user !== null) {
$user->delete(); $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) { if ($user !== null) {
$user->delete(); $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) { if ($user !== null) {
$user->delete(); $user->delete();
} }
@ -167,7 +153,19 @@ abstract class TestCase extends \Test\TestCase {
\OC::$server->getGroupManager()->clearBackends(); \OC::$server->getGroupManager()->clearBackends();
\OC::$server->getGroupManager()->addBackend(new \OC\Group\Database()); \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( $this->share(
IShare::TYPE_USER, IShare::TYPE_USER,
$this->folder, $this->folder,
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL \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 // 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); $this->assertCount(1, $shares);
// move shared folder to 'localDir' // move shared folder to 'localDir'
@ -100,13 +100,13 @@ class UnshareChildrenTest extends TestCase {
\OC\Files\Filesystem::unlink('localDir'); \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 // 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); $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 // the folder for the owner should still exists
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder)); $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));

View File

@ -89,13 +89,13 @@ class UpdaterTest extends TestCase {
$this->share( $this->share(
IShare::TYPE_USER, IShare::TYPE_USER,
$this->folder, $this->folder,
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL \OCP\Constants::PERMISSION_ALL
); );
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->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');
// check if user2 can see the shared folder // check if user2 can see the shared folder
$this->assertTrue($view->file_exists($this->folder)); $this->assertTrue($view->file_exists($this->folder));
@ -114,15 +114,15 @@ class UpdaterTest extends TestCase {
$view->unlink('localFolder'); $view->unlink('localFolder');
$this->loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->loginHelper($this->TEST_FILES_SHARING_API_USER2);
// shared folder should be unshared // shared folder should be unshared
$foldersShared = \OC\Share\Share::getItemsSharedWith('folder'); $foldersShared = \OC\Share\Share::getItemsSharedWith('folder');
$this->assertTrue(empty($foldersShared)); $this->assertTrue(empty($foldersShared));
// trashbin should contain the local file but not the mount point // trashbin should contain the local file but not the mount point
$rootView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2); $rootView = new \OC\Files\View('/' . $this->TEST_FILES_SHARING_API_USER2);
$trashContent = \OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_FILES_SHARING_API_USER2); $trashContent = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $this->TEST_FILES_SHARING_API_USER2);
$this->assertSame(1, count($trashContent)); $this->assertSame(1, count($trashContent));
$firstElement = reset($trashContent); $firstElement = reset($trashContent);
$timestamp = $firstElement['mtime']; $timestamp = $firstElement['mtime'];
@ -158,7 +158,7 @@ class UpdaterTest extends TestCase {
$oldShareFolder = $config->getSystemValue('share_folder'); $oldShareFolder = $config->getSystemValue('share_folder');
$config->setSystemValue('share_folder', $shareFolder); $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(''); $beforeShareRoot = \OC\Files\Filesystem::getFileInfo('');
$etagBeforeShareRoot = $beforeShareRoot->getEtag(); $etagBeforeShareRoot = $beforeShareRoot->getEtag();
@ -168,17 +168,17 @@ class UpdaterTest extends TestCase {
$beforeShareDir = \OC\Files\Filesystem::getFileInfo($shareFolder); $beforeShareDir = \OC\Files\Filesystem::getFileInfo($shareFolder);
$etagBeforeShareDir = $beforeShareDir->getEtag(); $etagBeforeShareDir = $beforeShareDir->getEtag();
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1); $this->loginHelper($this->TEST_FILES_SHARING_API_USER1);
$share = $this->share( $share = $this->share(
IShare::TYPE_USER, IShare::TYPE_USER,
$this->folder, $this->folder,
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL \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(''); $afterShareRoot = \OC\Files\Filesystem::getFileInfo('');
$etagAfterShareRoot = $afterShareRoot->getEtag(); $etagAfterShareRoot = $afterShareRoot->getEtag();
@ -194,7 +194,7 @@ class UpdaterTest extends TestCase {
$this->assertTrue($etagBeforeShareDir !== $etagAfterShareDir); $this->assertTrue($etagBeforeShareDir !== $etagAfterShareDir);
// cleanup // cleanup
$this->loginHelper(self::TEST_FILES_SHARING_API_USER1); $this->loginHelper($this->TEST_FILES_SHARING_API_USER1);
$this->shareManager->deleteShare($share); $this->shareManager->deleteShare($share);
$config->setSystemValue('share_folder', $oldShareFolder); $config->setSystemValue('share_folder', $oldShareFolder);
@ -209,12 +209,12 @@ class UpdaterTest extends TestCase {
$share = $this->share( $share = $this->share(
IShare::TYPE_USER, IShare::TYPE_USER,
$this->folder, $this->folder,
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL \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 // make sure that the shared folder exists
$this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder)); $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); \OC\Files\Filesystem::rename($this->folder, 'oldTarget/subfolder/' . $this->folder);
// re-login to make sure that the new mount points are initialized // 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'); \OC\Files\Filesystem::rename('/oldTarget', '/newTarget/oldTarget');
// re-login to make sure that the new mount points are initialized // 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)); $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 { protected function setUp(): void {
parent::setUp(); parent::setUp();
self::loginHelper(self::TEST_FILES_SHARING_API_USER1); self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
// prepare user1's dir structure // prepare user1's dir structure
$this->view->mkdir('container'); $this->view->mkdir('container');
@ -72,8 +72,8 @@ class WatcherTest extends TestCase {
$this->_share = $this->share( $this->_share = $this->share(
IShare::TYPE_USER, IShare::TYPE_USER,
'container/shareddir', 'container/shareddir',
self::TEST_FILES_SHARING_API_USER1, $this->TEST_FILES_SHARING_API_USER1,
self::TEST_FILES_SHARING_API_USER2, $this->TEST_FILES_SHARING_API_USER2,
\OCP\Constants::PERMISSION_ALL \OCP\Constants::PERMISSION_ALL
); );
@ -81,10 +81,10 @@ class WatcherTest extends TestCase {
$this->shareManager->updateShare($this->_share); $this->shareManager->updateShare($this->_share);
// login as user2 // login as user2
self::loginHelper(self::TEST_FILES_SHARING_API_USER2); self::loginHelper($this->TEST_FILES_SHARING_API_USER2);
// retrieve the shared storage // 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->sharedStorage, $internalPath] = $secondView->resolvePath('files/shareddir');
$this->sharedCache = $this->sharedStorage->getCache(); $this->sharedCache = $this->sharedStorage->getCache();
} }
@ -94,7 +94,7 @@ class WatcherTest extends TestCase {
$this->sharedCache->clear(); $this->sharedCache->clear();
} }
self::loginHelper(self::TEST_FILES_SHARING_API_USER1); self::loginHelper($this->TEST_FILES_SHARING_API_USER1);
if ($this->view) { if ($this->view) {
$this->shareManager->deleteShare($this->_share); $this->shareManager->deleteShare($this->_share);

View File

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

View File

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

View File

@ -10,6 +10,7 @@ return array(
'OCA\\Testing\\AlternativeHomeUserBackend' => $baseDir . '/../lib/AlternativeHomeUserBackend.php', 'OCA\\Testing\\AlternativeHomeUserBackend' => $baseDir . '/../lib/AlternativeHomeUserBackend.php',
'OCA\\Testing\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', 'OCA\\Testing\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
'OCA\\Testing\\Controller\\ConfigController' => $baseDir . '/../lib/Controller/ConfigController.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\\LockingController' => $baseDir . '/../lib/Controller/LockingController.php',
'OCA\\Testing\\Controller\\RateLimitTestController' => $baseDir . '/../lib/Controller/RateLimitTestController.php', 'OCA\\Testing\\Controller\\RateLimitTestController' => $baseDir . '/../lib/Controller/RateLimitTestController.php',
'OCA\\Testing\\Locking\\FakeDBLockingProvider' => $baseDir . '/../lib/Locking/FakeDBLockingProvider.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\\AlternativeHomeUserBackend' => __DIR__ . '/..' . '/../lib/AlternativeHomeUserBackend.php',
'OCA\\Testing\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', 'OCA\\Testing\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
'OCA\\Testing\\Controller\\ConfigController' => __DIR__ . '/..' . '/../lib/Controller/ConfigController.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\\LockingController' => __DIR__ . '/..' . '/../lib/Controller/LockingController.php',
'OCA\\Testing\\Controller\\RateLimitTestController' => __DIR__ . '/..' . '/../lib/Controller/RateLimitTestController.php', 'OCA\\Testing\\Controller\\RateLimitTestController' => __DIR__ . '/..' . '/../lib/Controller/RateLimitTestController.php',
'OCA\\Testing\\Locking\\FakeDBLockingProvider' => __DIR__ . '/..' . '/../lib/Locking/FakeDBLockingProvider.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); $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 "([^"]*)"$/ * @When /^Deleting the user "([^"]*)"$/
* @param string $user * @param string $user
@ -908,6 +942,8 @@ trait Provisioning {
* @AfterScenario * @AfterScenario
*/ */
public function cleanupUsers() { public function cleanupUsers() {
$this->flushDeletedUserList();
$previousServer = $this->currentServer; $previousServer = $this->currentServer;
$this->usingServer('LOCAL'); $this->usingServer('LOCAL');
foreach ($this->createdUsers as $user) { 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\\Version21000Date20210309185126' => $baseDir . '/core/Migrations/Version21000Date20210309185126.php',
'OC\\Core\\Migrations\\Version21000Date20210309185127' => $baseDir . '/core/Migrations/Version21000Date20210309185127.php', 'OC\\Core\\Migrations\\Version21000Date20210309185127' => $baseDir . '/core/Migrations/Version21000Date20210309185127.php',
'OC\\Core\\Migrations\\Version22000Date20210216080825' => $baseDir . '/core/Migrations/Version22000Date20210216080825.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\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php',
'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php', 'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php',
'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.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\\NoUserException' => $baseDir . '/lib/private/User/NoUserException.php',
'OC\\User\\Session' => $baseDir . '/lib/private/User/Session.php', 'OC\\User\\Session' => $baseDir . '/lib/private/User/Session.php',
'OC\\User\\User' => $baseDir . '/lib/private/User/User.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_API' => $baseDir . '/lib/private/legacy/OC_API.php',
'OC_App' => $baseDir . '/lib/private/legacy/OC_App.php', 'OC_App' => $baseDir . '/lib/private/legacy/OC_App.php',
'OC_DB' => $baseDir . '/lib/private/legacy/OC_DB.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\\Version21000Date20210309185126' => __DIR__ . '/../../..' . '/core/Migrations/Version21000Date20210309185126.php',
'OC\\Core\\Migrations\\Version21000Date20210309185127' => __DIR__ . '/../../..' . '/core/Migrations/Version21000Date20210309185127.php', 'OC\\Core\\Migrations\\Version21000Date20210309185127' => __DIR__ . '/../../..' . '/core/Migrations/Version21000Date20210309185127.php',
'OC\\Core\\Migrations\\Version22000Date20210216080825' => __DIR__ . '/../../..' . '/core/Migrations/Version22000Date20210216080825.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\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php',
'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php', 'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php',
'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.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\\NoUserException' => __DIR__ . '/../../..' . '/lib/private/User/NoUserException.php',
'OC\\User\\Session' => __DIR__ . '/../../..' . '/lib/private/User/Session.php', 'OC\\User\\Session' => __DIR__ . '/../../..' . '/lib/private/User/Session.php',
'OC\\User\\User' => __DIR__ . '/../../..' . '/lib/private/User/User.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_API' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_API.php',
'OC_App' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_App.php', 'OC_App' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_App.php',
'OC_DB' => __DIR__ . '/../../..' . '/lib/private/legacy/OC_DB.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\SystemTag\ManagerFactory as SystemTagManagerFactory;
use OC\Tagging\TagMapper; use OC\Tagging\TagMapper;
use OC\Template\JSCombiner; use OC\Template\JSCombiner;
use OC\User\UserDeletedListener;
use OCA\Theming\ImageManager; use OCA\Theming\ImageManager;
use OCA\Theming\ThemingDefaults; use OCA\Theming\ThemingDefaults;
use OCA\Theming\Util; use OCA\Theming\Util;
@ -1445,6 +1446,7 @@ class Server extends ServerContainer implements IServerContainer {
$eventDispatched = $this->get(IEventDispatcher::class); $eventDispatched = $this->get(IEventDispatcher::class);
$eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class);
$eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::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.')); 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 = []; $localBackends = [];
foreach ($this->backends as $backend) { foreach ($this->backends as $backend) {
if ($backend instanceof Database) { 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 * @group DB
*/ */
class AppTest extends \Test\TestCase { class AppTest extends \Test\TestCase {
public const TEST_USER1 = 'user1'; public $TEST_USER1 = 'user1-';
public const TEST_USER2 = 'user2'; public $TEST_USER2 = 'user2-';
public const TEST_USER3 = 'user3'; public $TEST_USER3 = 'user3-';
public const TEST_GROUP1 = 'group1'; public const TEST_GROUP1 = 'group1';
public const TEST_GROUP2 = 'group2'; 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 * @dataProvider appVersionsProvider
*/ */
@ -330,73 +337,6 @@ class AppTest extends \Test\TestCase {
*/ */
public function appConfigValuesProvider() { public function appConfigValuesProvider() {
return [ 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 // no user, returns all apps
[ [
null, null,
@ -420,9 +360,76 @@ class AppTest extends \Test\TestCase {
], ],
false, 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 // user given, but ask for all
[ [
self::TEST_USER1, $this->TEST_USER1,
[ [
'files', 'files',
'app1', '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 * Test enabled apps
* *
* @dataProvider appConfigValuesProvider * @dataProvider appConfigValuesProvider
*/ */
public function testEnabledApps($user, $expectedApps, $forceAll) { public function testEnabledApps($user, $expectedApps, $forceAll) {
$user = $this->mapDataProviderUserIds($user);
$userManager = \OC::$server->getUserManager(); $userManager = \OC::$server->getUserManager();
$groupManager = \OC::$server->getGroupManager(); $groupManager = \OC::$server->getGroupManager();
$user1 = $userManager->createUser(self::TEST_USER1, self::TEST_USER1);
$user2 = $userManager->createUser(self::TEST_USER2, self::TEST_USER2); $user1 = $userManager->createUser($this->TEST_USER1, $this->TEST_USER1);
$user3 = $userManager->createUser(self::TEST_USER3, self::TEST_USER3); $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 = $groupManager->createGroup(self::TEST_GROUP1);
$group1->addUser($user1); $group1->addUser($user1);
@ -502,9 +524,9 @@ class AppTest extends \Test\TestCase {
*/ */
public function testEnabledAppsCache() { public function testEnabledAppsCache() {
$userManager = \OC::$server->getUserManager(); $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()) $this->setupAppConfigMock()->expects($this->once())
->method('getValues') ->method('getValues')

View File

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

View File

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

View File

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

View File

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

View File

@ -59,7 +59,7 @@ class SubAdminTest extends \Test\TestCase {
// Create 3 users and 3 groups // Create 3 users and 3 groups
for ($i = 0; $i < 3; $i++) { 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); $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') ->method('deleteUser')
->willReturn($result); ->willReturn($result);
$emitter = new PublicEmitter(); $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 * @param User $user
*/ */
$hook = function ($user) use ($test, &$hooksCalled) { $hook = function ($user) use ($test, $userId, &$hooksCalled) {
$hooksCalled++; $hooksCalled++;
$test->assertEquals('foo', $user->getUID()); $test->assertEquals($userId, $user->getUID());
}; };
$emitter->listen('\OC\User', 'preDelete', $hook); $emitter->listen('\OC\User', 'preDelete', $hook);
@ -524,11 +525,11 @@ class UserTest extends TestCase {
if ($result) { if ($result) {
$config->expects($this->once()) $config->expects($this->once())
->method('deleteAllUserValues') ->method('deleteAllUserValues')
->with('foo'); ->with($user->getUID());
$commentsManager->expects($this->once()) $commentsManager->expects($this->once())
->method('deleteReferencesOfActor') ->method('deleteReferencesOfActor')
->with('users', 'foo'); ->with('users', $user->getUID());
$commentsManager->expects($this->once()) $commentsManager->expects($this->once())
->method('deleteReadMarksFromUser') ->method('deleteReadMarksFromUser')
->with($user); ->with($user);
@ -536,7 +537,7 @@ class UserTest extends TestCase {
$notification = $this->createMock(INotification::class); $notification = $this->createMock(INotification::class);
$notification->expects($this->once()) $notification->expects($this->once())
->method('setUser') ->method('setUser')
->with('foo'); ->with($user->getUID());
$notificationManager->expects($this->once()) $notificationManager->expects($this->once())
->method('createNotification') ->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);
}
}