fix encryption tests after the removal of the shared folder
This commit is contained in:
parent
4c840cb61d
commit
a86d97295e
7 changed files with 59 additions and 67 deletions
|
@ -342,9 +342,7 @@ class Hooks {
|
|||
|
||||
// if parent has the same type than the child it is a 1:1 share
|
||||
if ($parent['item_type'] === $params['itemType']) {
|
||||
|
||||
// prefix path with Shared
|
||||
$path = '/Shared' . $parent['file_target'];
|
||||
$path = $parent['file_target'];
|
||||
} else {
|
||||
|
||||
// NOTE: parent is folder but shared was a file!
|
||||
|
@ -376,11 +374,9 @@ class Hooks {
|
|||
break;
|
||||
}
|
||||
}
|
||||
// prefix path with Shared
|
||||
$path = '/Shared' . $parent['file_target'] . $path;
|
||||
$path = $parent['file_target'] . $path;
|
||||
} else {
|
||||
// prefix path with Shared
|
||||
$path = '/Shared' . $parent['file_target'] . $params['fileTarget'];
|
||||
$path = $parent['file_target'] . $params['fileTarget'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -388,7 +384,8 @@ class Hooks {
|
|||
$sharingEnabled = \OCP\Share::isEnabled();
|
||||
|
||||
// get the path including mount point only if not a shared folder
|
||||
if (strncmp($path, '/Shared', strlen('/Shared') !== 0)) {
|
||||
list($storage, ) = \OC\Files\Filesystem::resolvePath('/' . $userId . '/files' . $path);
|
||||
if (!($storage instanceof \OC\Files\Storage\Shared)) {
|
||||
// get path including the the storage mount point
|
||||
$path = $util->getPathWithMountPoint($params['itemSource']);
|
||||
}
|
||||
|
@ -454,7 +451,7 @@ class Hooks {
|
|||
}
|
||||
|
||||
// prefix path with Shared
|
||||
$path = '/Shared' . $parent['file_target'] . $path;
|
||||
$path = $parent['file_target'] . $path;
|
||||
}
|
||||
|
||||
// for group shares get a list of the group members
|
||||
|
@ -469,9 +466,10 @@ class Hooks {
|
|||
}
|
||||
|
||||
// get the path including mount point only if not a shared folder
|
||||
if (strncmp($path, '/Shared', strlen('/Shared') !== 0)) {
|
||||
list($storage, ) = \OC\Files\Filesystem::resolvePath($path);
|
||||
if (!($storage instanceof \OC\Files\Storage\Shared)) {
|
||||
// get path including the the storage mount point
|
||||
$path = $util->getPathWithMountPoint($params['itemSource']);
|
||||
//$path = $util->getPathWithMountPoint($params['itemSource']);
|
||||
}
|
||||
|
||||
// if we unshare a folder we need a list of all (sub-)files
|
||||
|
@ -510,6 +508,8 @@ class Hooks {
|
|||
// otherwise we perform a stream copy, so we get a new set of keys
|
||||
$mp1 = $view->getMountPoint('/' . $user . '/files/' . $params['oldpath']);
|
||||
$mp2 = $view->getMountPoint('/' . $user . '/files/' . $params['newpath']);
|
||||
list($storage1, ) = Filesystem::resolvePath($params['oldpath']);
|
||||
|
||||
if ($mp1 === $mp2) {
|
||||
self::$renamedFiles[$params['oldpath']] = array(
|
||||
'uid' => $ownerOld,
|
||||
|
|
|
@ -1408,11 +1408,10 @@ class Util {
|
|||
$this->userFilesDir . '/' . $dir));
|
||||
|
||||
foreach ($content as $c) {
|
||||
$usersPath = isset($c['usersPath']) ? $c['usersPath'] : $c['path'];
|
||||
if ($c['type'] === 'dir') {
|
||||
$dirList[] = substr($usersPath, strlen("files"));
|
||||
$dirList[] = substr($c['path'], strlen("files"));
|
||||
} else {
|
||||
$result[] = substr($usersPath, strlen("files"));
|
||||
$result[] = substr($c['path'], strlen("files"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -219,18 +219,20 @@ class Test_Encryption_Hooks extends \PHPUnit_Framework_TestCase {
|
|||
\Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
|
||||
\OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2);
|
||||
|
||||
// user2 has a local file with the same name
|
||||
// user2 update the shared file
|
||||
$this->user2View->file_put_contents($this->filename, $this->data);
|
||||
|
||||
// check if all keys are generated
|
||||
$this->assertTrue($this->rootView->file_exists(
|
||||
// keys should be stored at user1s dir, not in user2s
|
||||
$this->assertFalse($this->rootView->file_exists(
|
||||
self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
|
||||
. $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
|
||||
$this->assertTrue($this->rootView->file_exists(
|
||||
$this->assertFalse($this->rootView->file_exists(
|
||||
self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
|
||||
|
||||
// delete the Shared file from user1 in data/user2/files/Shared
|
||||
$this->user2View->unlink('/Shared/' . $this->filename);
|
||||
$result = $this->user2View->unlink($this->filename);
|
||||
|
||||
$this->assertTrue($result);
|
||||
|
||||
// now keys from user1s home should be gone
|
||||
$this->assertFalse($this->rootView->file_exists(
|
||||
|
@ -242,26 +244,12 @@ class Test_Encryption_Hooks extends \PHPUnit_Framework_TestCase {
|
|||
$this->assertFalse($this->rootView->file_exists(
|
||||
self::TEST_ENCRYPTION_HOOKS_USER1 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
|
||||
|
||||
// but user2 keys should still exist
|
||||
$this->assertTrue($this->rootView->file_exists(
|
||||
self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/share-keys/'
|
||||
. $this->filename . '.' . \Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER2 . '.shareKey'));
|
||||
$this->assertTrue($this->rootView->file_exists(
|
||||
self::TEST_ENCRYPTION_HOOKS_USER2 . '/files_encryption/keyfiles/' . $this->filename . '.key'));
|
||||
|
||||
// cleanup
|
||||
|
||||
$this->user2View->unlink($this->filename);
|
||||
|
||||
\Test_Encryption_Util::logoutHelper();
|
||||
\Test_Encryption_Util::loginHelper(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
|
||||
\OC_User::setUserId(\Test_Encryption_Hooks::TEST_ENCRYPTION_HOOKS_USER1);
|
||||
|
||||
// unshare the file
|
||||
\OCP\Share::unshare('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, self::TEST_ENCRYPTION_HOOKS_USER2);
|
||||
|
||||
$this->user1View->unlink($this->filename);
|
||||
|
||||
if ($stateFilesTrashbin) {
|
||||
OC_App::enable('files_trashbin');
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
// get file contents
|
||||
$retrievedCryptedFile = $this->view->file_get_contents(
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared/' . $this->filename);
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);
|
||||
|
||||
// check if data is the same as we previously written
|
||||
$this->assertEquals($this->dataShort, $retrievedCryptedFile);
|
||||
|
@ -213,14 +213,14 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
|||
function testReShareFile($withTeardown = true) {
|
||||
$this->testShareFile(false);
|
||||
|
||||
// login as user1
|
||||
// login as user2
|
||||
\Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
|
||||
|
||||
// get the file info
|
||||
$fileInfo = $this->view->getFileInfo(
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared/' . $this->filename);
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);
|
||||
|
||||
// share the file with user2
|
||||
// share the file with user3
|
||||
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, OCP\PERMISSION_ALL);
|
||||
|
||||
// login as admin
|
||||
|
@ -236,7 +236,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
// get file contents
|
||||
$retrievedCryptedFile = $this->view->file_get_contents(
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/Shared/' . $this->filename);
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->filename);
|
||||
|
||||
// check if data is the same as previously written
|
||||
$this->assertEquals($this->dataShort, $retrievedCryptedFile);
|
||||
|
@ -333,7 +333,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
// get file contents
|
||||
$retrievedCryptedFile = $this->view->file_get_contents(
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared' . $this->folder1
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1
|
||||
. $this->subfolder . $this->subsubfolder . '/' . $this->filename);
|
||||
|
||||
// check if data is the same
|
||||
|
@ -376,7 +376,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
|||
function testReShareFolder($withTeardown = true) {
|
||||
$fileInfoFolder1 = $this->testShareFolder(false);
|
||||
|
||||
// login as user1
|
||||
// login as user2
|
||||
\Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
|
||||
|
||||
// disable encryption proxy to prevent recursive calls
|
||||
|
@ -385,7 +385,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
// get the file info from previous created folder
|
||||
$fileInfoSubFolder = $this->view->getFileInfo(
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared' . $this->folder1
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1
|
||||
. $this->subfolder);
|
||||
|
||||
// check if we have a valid file info
|
||||
|
@ -394,24 +394,24 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
|||
// re-enable the file proxy
|
||||
\OC_FileProxy::$enabled = $proxyStatus;
|
||||
|
||||
// share the file with user2
|
||||
// share the file with user3
|
||||
\OCP\Share::shareItem('folder', $fileInfoSubFolder['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3, OCP\PERMISSION_ALL);
|
||||
|
||||
// login as admin
|
||||
\Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
|
||||
|
||||
// check if share key for user2 exists
|
||||
// check if share key for user3 exists
|
||||
$this->assertTrue($this->view->file_exists(
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys' . $this->folder1
|
||||
. $this->subfolder . $this->subsubfolder . '/'
|
||||
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '.shareKey'));
|
||||
|
||||
// login as user2
|
||||
// login as user3
|
||||
\Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3);
|
||||
|
||||
// get file contents
|
||||
$retrievedCryptedFile = $this->view->file_get_contents(
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/Shared' . $this->subfolder
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->subfolder
|
||||
. $this->subsubfolder . '/' . $this->filename);
|
||||
|
||||
// check if data is the same
|
||||
|
@ -419,7 +419,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
// get the file info
|
||||
$fileInfo = $this->view->getFileInfo(
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/Shared' . $this->subfolder
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->subfolder
|
||||
. $this->subsubfolder . '/' . $this->filename);
|
||||
|
||||
// check if we have fileInfos
|
||||
|
@ -442,7 +442,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
// get file contents
|
||||
$retrievedCryptedFile = $this->view->file_get_contents(
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '/files/Shared/' . $this->filename);
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER4 . '/files/' . $this->filename);
|
||||
|
||||
// check if data is the same
|
||||
$this->assertEquals($this->dataShort, $retrievedCryptedFile);
|
||||
|
@ -624,7 +624,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
// get file contents
|
||||
$retrievedCryptedFile = $this->view->file_get_contents(
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/Shared/' . $this->filename);
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER3 . '/files/' . $this->filename);
|
||||
|
||||
// check if data is the same as we previously written
|
||||
$this->assertEquals($this->dataShort, $retrievedCryptedFile);
|
||||
|
@ -676,6 +676,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
// enable recovery for admin
|
||||
$this->assertTrue($util->setRecoveryForUser(1));
|
||||
$util->addRecoveryKeys();
|
||||
|
||||
// create folder structure
|
||||
$this->view->mkdir('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files' . $this->folder1);
|
||||
|
@ -981,7 +982,7 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
|||
// share the file
|
||||
\OCP\Share::shareItem('file', $fileInfo['fileid'], \OCP\Share::SHARE_TYPE_USER, \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2, OCP\PERMISSION_ALL);
|
||||
|
||||
// check if share key for user2exists
|
||||
// check if share key for user2 exists
|
||||
$this->assertTrue($this->view->file_exists(
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files_encryption/share-keys/'
|
||||
. $this->filename . '.' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '.shareKey'));
|
||||
|
@ -990,31 +991,29 @@ class Test_Encryption_Share extends \PHPUnit_Framework_TestCase {
|
|||
// login as user2
|
||||
\Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2);
|
||||
|
||||
$this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared/' . $this->filename));
|
||||
$this->assertTrue($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename));
|
||||
|
||||
// get file contents
|
||||
$retrievedCryptedFile = $this->view->file_get_contents(
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared/' . $this->filename);
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);
|
||||
|
||||
// check if data is the same as we previously written
|
||||
$this->assertEquals($this->dataShort, $retrievedCryptedFile);
|
||||
|
||||
// move the file out of the shared folder
|
||||
$this->view->rename('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/Shared/' . $this->filename,
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);
|
||||
// move the file to a subfolder
|
||||
$this->view->rename('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename,
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 . $this->filename);
|
||||
|
||||
// check if we can read the moved file
|
||||
$retrievedRenamedFile = $this->view->file_get_contents(
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);
|
||||
'/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->folder1 . $this->filename);
|
||||
|
||||
// check if data is the same as we previously written
|
||||
$this->assertEquals($this->dataShort, $retrievedRenamedFile);
|
||||
|
||||
// the owners file should be deleted
|
||||
$this->assertFalse($this->view->file_exists('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename));
|
||||
|
||||
// cleanup
|
||||
$this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER2 . '/files/' . $this->filename);
|
||||
\Test_Encryption_Util::loginHelper(\Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1);
|
||||
$this->view->unlink('/' . \Test_Encryption_Share::TEST_ENCRYPTION_SHARE_USER1 . '/files/' . $this->filename);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -520,8 +520,8 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
|
|||
\OC_Util::tearDownFS();
|
||||
\OC_User::setUserId('');
|
||||
\OC\Files\Filesystem::tearDown();
|
||||
\OC_Util::setupFS($user);
|
||||
\OC_User::setUserId($user);
|
||||
\OC_Util::setupFS($user);
|
||||
|
||||
$params['uid'] = $user;
|
||||
$params['password'] = $password;
|
||||
|
|
|
@ -60,6 +60,12 @@ class OC_Share_Backend_File implements OCP\Share_Backend_File_Dependent {
|
|||
*/
|
||||
public function generateTarget($filePath, $shareWith, $exclude = null) {
|
||||
$target = '/'.basename($filePath);
|
||||
|
||||
// for group shares we return the target right away
|
||||
if ($shareWith === false) {
|
||||
return $target;
|
||||
}
|
||||
|
||||
\OC\Files\Filesystem::initMountPoints($shareWith);
|
||||
$view = new \OC\Files\View('/' . $shareWith . '/files');
|
||||
$excludeList = \OCP\Share::getItemsSharedWithUser('file', $shareWith, self::FORMAT_TARGET_NAMES);
|
||||
|
|
|
@ -195,7 +195,7 @@ class Shared extends \OC\Files\Storage\Common {
|
|||
|
||||
public function isCreatable($path) {
|
||||
if ($path == '') {
|
||||
return ($this->getPermissions($this->getMountPoint()) & \OCP\PERMISSION_CREATE);
|
||||
$path = $this->mountPoint;
|
||||
}
|
||||
return ($this->getPermissions($path) & \OCP\PERMISSION_CREATE);
|
||||
}
|
||||
|
@ -206,21 +206,21 @@ class Shared extends \OC\Files\Storage\Common {
|
|||
|
||||
public function isUpdatable($path) {
|
||||
if ($path == '') {
|
||||
return false;
|
||||
$path = $this->mountPoint;
|
||||
}
|
||||
return ($this->getPermissions($path) & \OCP\PERMISSION_UPDATE);
|
||||
}
|
||||
|
||||
public function isDeletable($path) {
|
||||
if ($path == '') {
|
||||
return true;
|
||||
$path = $this->mountPoint;
|
||||
}
|
||||
return ($this->getPermissions($path) & \OCP\PERMISSION_DELETE);
|
||||
}
|
||||
|
||||
public function isSharable($path) {
|
||||
if ($path == '') {
|
||||
return false;
|
||||
$path = $this->mountPoint;
|
||||
}
|
||||
return ($this->getPermissions($path) & \OCP\PERMISSION_SHARE);
|
||||
}
|
||||
|
@ -441,7 +441,7 @@ class Shared extends \OC\Files\Storage\Common {
|
|||
|
||||
public function free_space($path) {
|
||||
if ($path == '') {
|
||||
return \OC\Files\SPACE_UNKNOWN;
|
||||
$path = $this->mountPoint;
|
||||
}
|
||||
$source = $this->getSourcePath($path);
|
||||
if ($source) {
|
||||
|
@ -531,7 +531,7 @@ class Shared extends \OC\Files\Storage\Common {
|
|||
|
||||
public function getOwner($path) {
|
||||
if ($path == '') {
|
||||
return false;
|
||||
$path = $this->mountPoint;
|
||||
}
|
||||
$source = $this->getFile($path);
|
||||
if ($source) {
|
||||
|
@ -542,7 +542,7 @@ class Shared extends \OC\Files\Storage\Common {
|
|||
|
||||
public function getETag($path) {
|
||||
if ($path == '') {
|
||||
return parent::getETag($path);
|
||||
$path = $this->mountPoint;
|
||||
}
|
||||
if ($source = $this->getSourcePath($path)) {
|
||||
list($storage, $internalPath) = \OC\Files\Filesystem::resolvePath($source);
|
||||
|
|
Loading…
Reference in a new issue