|
|
|
|
@ -32,6 +32,7 @@ |
|
|
|
|
namespace OCA\Files_Sharing\Tests\Controllers; |
|
|
|
|
|
|
|
|
|
use OC\Files\Filesystem; |
|
|
|
|
use OC\Files\Node\Folder; |
|
|
|
|
use OCA\FederatedFileSharing\FederatedShareProvider; |
|
|
|
|
use OCA\Files_Sharing\Controller\ShareController; |
|
|
|
|
use OCP\AppFramework\Http\DataResponse; |
|
|
|
|
@ -39,7 +40,9 @@ use OCP\AppFramework\Http\Template\ExternalShareMenuAction; |
|
|
|
|
use OCP\AppFramework\Http\Template\LinkMenuAction; |
|
|
|
|
use OCP\AppFramework\Http\Template\PublicTemplateResponse; |
|
|
|
|
use OCP\AppFramework\Http\Template\SimpleMenuAction; |
|
|
|
|
use OCP\Constants; |
|
|
|
|
use OCP\Files\NotFoundException; |
|
|
|
|
use OCP\Files\Storage; |
|
|
|
|
use OCP\IConfig; |
|
|
|
|
use OCP\IL10N; |
|
|
|
|
use OCP\ILogger; |
|
|
|
|
@ -47,14 +50,12 @@ use OCP\IPreview; |
|
|
|
|
use OCP\IRequest; |
|
|
|
|
use OCP\IUser; |
|
|
|
|
use OCP\Share\Exceptions\ShareNotFound; |
|
|
|
|
use OCP\AppFramework\Http\NotFoundResponse; |
|
|
|
|
use OCP\AppFramework\Http\RedirectResponse; |
|
|
|
|
use OCP\AppFramework\Http\TemplateResponse; |
|
|
|
|
use OCP\ISession; |
|
|
|
|
use OCP\IUserManager; |
|
|
|
|
use OCP\Security\ISecureRandom; |
|
|
|
|
use OCP\IURLGenerator; |
|
|
|
|
use OCP\Share\IShare; |
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -423,6 +424,102 @@ class ShareControllerTest extends \Test\TestCase { |
|
|
|
|
$this->assertEquals($expectedResponse, $response); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Checks file drop shares: |
|
|
|
|
* - there must not be any header action |
|
|
|
|
* - the template param "hideFileList" should be true |
|
|
|
|
* |
|
|
|
|
* @test |
|
|
|
|
* @return void |
|
|
|
|
*/ |
|
|
|
|
public function testShareFileDrop() { |
|
|
|
|
$this->shareController->setToken('token'); |
|
|
|
|
|
|
|
|
|
$owner = $this->getMockBuilder(IUser::class)->getMock(); |
|
|
|
|
$owner->method('getDisplayName')->willReturn('ownerDisplay'); |
|
|
|
|
$owner->method('getUID')->willReturn('ownerUID'); |
|
|
|
|
|
|
|
|
|
/* @var MockObject|Storage $storage */ |
|
|
|
|
$storage = $this->getMockBuilder(Storage::class) |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
|
|
|
|
|
/* @var MockObject|Folder $folder */ |
|
|
|
|
$folder = $this->getMockBuilder(Folder::class) |
|
|
|
|
->disableOriginalConstructor() |
|
|
|
|
->getMock(); |
|
|
|
|
$folder->method('getName')->willReturn('/fileDrop'); |
|
|
|
|
$folder->method('isReadable')->willReturn(true); |
|
|
|
|
$folder->method('isShareable')->willReturn(true); |
|
|
|
|
$folder->method('getStorage')->willReturn($storage); |
|
|
|
|
$folder->method('get')->with('')->willReturn($folder); |
|
|
|
|
$folder->method('getSize')->willReturn(1337); |
|
|
|
|
|
|
|
|
|
$share = \OC::$server->getShareManager()->newShare(); |
|
|
|
|
$share->setId(42); |
|
|
|
|
$share->setPermissions(Constants::PERMISSION_CREATE) |
|
|
|
|
->setShareOwner('ownerUID') |
|
|
|
|
->setNode($folder) |
|
|
|
|
->setTarget('/fileDrop'); |
|
|
|
|
|
|
|
|
|
$this->shareManager |
|
|
|
|
->expects($this->once()) |
|
|
|
|
->method('getShareByToken') |
|
|
|
|
->with('token') |
|
|
|
|
->willReturn($share); |
|
|
|
|
|
|
|
|
|
$this->userManager->method('get')->with('ownerUID')->willReturn($owner); |
|
|
|
|
|
|
|
|
|
$this->l10n->expects($this->any()) |
|
|
|
|
->method('t') |
|
|
|
|
->will($this->returnCallback(function($text, $parameters) { |
|
|
|
|
return vsprintf($text, $parameters); |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
$response = $this->shareController->showShare(); |
|
|
|
|
// skip the "folder" param for tests |
|
|
|
|
$responseParams = $response->getParams(); |
|
|
|
|
unset($responseParams['folder']); |
|
|
|
|
$response->setParams($responseParams); |
|
|
|
|
|
|
|
|
|
$sharedTmplParams = array( |
|
|
|
|
'displayName' => 'ownerDisplay', |
|
|
|
|
'owner' => 'ownerUID', |
|
|
|
|
'filename' => '/fileDrop', |
|
|
|
|
'directory_path' => '/fileDrop', |
|
|
|
|
'mimetype' => null, |
|
|
|
|
'dirToken' => 'token', |
|
|
|
|
'sharingToken' => 'token', |
|
|
|
|
'server2serversharing' => true, |
|
|
|
|
'protected' => 'false', |
|
|
|
|
'dir' => null, |
|
|
|
|
'downloadURL' => '', |
|
|
|
|
'fileSize' => '1 KB', |
|
|
|
|
'nonHumanFileSize' => 1337, |
|
|
|
|
'maxSizeAnimateGif' => null, |
|
|
|
|
'previewSupported' => null, |
|
|
|
|
'previewEnabled' => null, |
|
|
|
|
'previewMaxX' => null, |
|
|
|
|
'previewMaxY' => null, |
|
|
|
|
'hideFileList' => true, |
|
|
|
|
'shareOwner' => 'ownerDisplay', |
|
|
|
|
'disclaimer' => null, |
|
|
|
|
'shareUrl' => '', |
|
|
|
|
'previewImage' => '', |
|
|
|
|
'previewURL' => '', |
|
|
|
|
'note' => '' |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$csp = new \OCP\AppFramework\Http\ContentSecurityPolicy(); |
|
|
|
|
$csp->addAllowedFrameDomain('\'self\''); |
|
|
|
|
$expectedResponse = new PublicTemplateResponse($this->appName, 'public', $sharedTmplParams); |
|
|
|
|
$expectedResponse->setContentSecurityPolicy($csp); |
|
|
|
|
$expectedResponse->setHeaderTitle($sharedTmplParams['filename']); |
|
|
|
|
$expectedResponse->setHeaderDetails('shared by ' . $sharedTmplParams['displayName']); |
|
|
|
|
|
|
|
|
|
self::assertEquals($expectedResponse, $response); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @expectedException \OCP\Files\NotFoundException |
|
|
|
|
*/ |
|
|
|
|
|