summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/tests
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-06-14 10:20:10 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2018-06-20 08:53:37 +0200
commit9f658febcafb0a51c20ef114a2a8e76bc9d05445 (patch)
tree2657f88ec740d0a234c5dbd263558bf95f6a5103 /apps/files_sharing/tests
parentff3f63fd4746441c08bdb79d771b5c3e3da259c8 (diff)
downloadnextcloud-server-9f658febcafb0a51c20ef114a2a8e76bc9d05445.tar.gz
nextcloud-server-9f658febcafb0a51c20ef114a2a8e76bc9d05445.zip
Fix ShareControllerTest
* Removed tests that are now handled by the middleware * Updated tests Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'apps/files_sharing/tests')
-rw-r--r--apps/files_sharing/tests/Controller/ShareControllerTest.php226
1 files changed, 16 insertions, 210 deletions
diff --git a/apps/files_sharing/tests/Controller/ShareControllerTest.php b/apps/files_sharing/tests/Controller/ShareControllerTest.php
index be99c5ee194..fb417878647 100644
--- a/apps/files_sharing/tests/Controller/ShareControllerTest.php
+++ b/apps/files_sharing/tests/Controller/ShareControllerTest.php
@@ -39,6 +39,7 @@ 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\Files\NotFoundException;
use OCP\IConfig;
use OCP\IL10N;
use OCP\ILogger;
@@ -156,193 +157,24 @@ class ShareControllerTest extends \Test\TestCase {
parent::tearDown();
}
- public function testShowAuthenticateNotAuthenticated() {
- $share = \OC::$server->getShareManager()->newShare();
-
- $this->shareManager
- ->expects($this->once())
- ->method('getShareByToken')
- ->with('token')
- ->willReturn($share);
-
- $response = $this->shareController->showAuthenticate('token');
- $expectedResponse = new TemplateResponse($this->appName, 'authenticate', [], 'guest');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testShowAuthenticateAuthenticatedForDifferentShare() {
- $share = \OC::$server->getShareManager()->newShare();
- $share->setId(1);
-
- $this->shareManager
- ->expects($this->once())
- ->method('getShareByToken')
- ->with('token')
- ->willReturn($share);
-
- $this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
- $this->session->method('get')->with('public_link_authenticated')->willReturn('2');
-
- $response = $this->shareController->showAuthenticate('token');
- $expectedResponse = new TemplateResponse($this->appName, 'authenticate', [], 'guest');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testShowAuthenticateCorrectShare() {
- $share = \OC::$server->getShareManager()->newShare();
- $share->setId(1);
-
- $this->shareManager
- ->expects($this->once())
- ->method('getShareByToken')
- ->with('token')
- ->willReturn($share);
-
- $this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
- $this->session->method('get')->with('public_link_authenticated')->willReturn('1');
-
- $this->urlGenerator->expects($this->once())
- ->method('linkToRoute')
- ->with('files_sharing.sharecontroller.showShare', ['token' => 'token'])
- ->willReturn('redirect');
-
- $response = $this->shareController->showAuthenticate('token');
- $expectedResponse = new RedirectResponse('redirect');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testAuthenticateInvalidToken() {
- $this->shareManager
- ->expects($this->once())
- ->method('getShareByToken')
- ->with('token')
- ->will($this->throwException(new \OCP\Share\Exceptions\ShareNotFound()));
-
- $response = $this->shareController->authenticate('token', 'preview');
- $expectedResponse = new NotFoundResponse();
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testAuthenticateValidPassword() {
- $share = \OC::$server->getShareManager()->newShare();
- $share->setId(42);
-
- $this->shareManager
- ->expects($this->once())
- ->method('getShareByToken')
- ->with('token')
- ->willReturn($share);
-
- $this->shareManager
- ->expects($this->once())
- ->method('checkPassword')
- ->with($share, 'validpassword')
- ->willReturn(true);
-
- $this->session
- ->expects($this->once())
- ->method('set')
- ->with('public_link_authenticated', '42');
-
- $this->urlGenerator->expects($this->once())
- ->method('linkToRoute')
- ->with('files_sharing.sharecontroller.showShare', ['token'=>'token'])
- ->willReturn('redirect');
-
- $response = $this->shareController->authenticate('token', 'preview', 'validpassword');
- $expectedResponse = new RedirectResponse('redirect');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testAuthenticateValidPasswordAndDownload() {
- $share = \OC::$server->getShareManager()->newShare();
- $share->setId(42);
-
- $this->shareManager
- ->expects($this->once())
- ->method('getShareByToken')
- ->with('token')
- ->willReturn($share);
-
- $this->shareManager
- ->expects($this->once())
- ->method('checkPassword')
- ->with($share, 'validpassword')
- ->willReturn(true);
-
- $this->session
- ->expects($this->once())
- ->method('set')
- ->with('public_link_authenticated', '42');
-
- $this->urlGenerator->expects($this->once())
- ->method('linkToRoute')
- ->with('files_sharing.sharecontroller.downloadShare', ['token'=>'token'])
- ->willReturn('redirect');
-
- $response = $this->shareController->authenticate('token', 'download', 'validpassword');
- $expectedResponse = new RedirectResponse('redirect');
- $this->assertEquals($expectedResponse, $response);
- }
-
- public function testAuthenticateInvalidPassword() {
- $share = \OC::$server->getShareManager()->newShare();
- $share->setNodeId(100)
- ->setNodeType('file')
- ->setToken('token')
- ->setSharedBy('initiator')
- ->setId(42);
-
- $this->shareManager
- ->expects($this->once())
- ->method('getShareByToken')
- ->with('token')
- ->willReturn($share);
-
- $this->shareManager
- ->expects($this->once())
- ->method('checkPassword')
- ->with($share, 'invalidpassword')
- ->willReturn(false);
-
- $this->session
- ->expects($this->never())
- ->method('set');
-
- $hookListner = $this->getMockBuilder('Dummy')->setMethods(['access'])->getMock();
- \OCP\Util::connectHook('OCP\Share', 'share_link_access', $hookListner, 'access');
-
- $hookListner->expects($this->once())
- ->method('access')
- ->with($this->callback(function(array $data) {
- return $data['itemType'] === 'file' &&
- $data['itemSource'] === 100 &&
- $data['uidOwner'] === 'initiator' &&
- $data['token'] === 'token' &&
- $data['errorCode'] === 403 &&
- $data['errorMessage'] === 'Wrong password';
- }));
-
- $response = $this->shareController->authenticate('token', 'preview', 'invalidpassword');
- $expectedResponse = new TemplateResponse($this->appName, 'authenticate', array('wrongpw' => true), 'guest');
- $expectedResponse->throttle();
- $this->assertEquals($expectedResponse, $response);
- }
-
public function testShowShareInvalidToken() {
+ $this->shareController->setToken('invalidtoken');
+
$this->shareManager
->expects($this->once())
->method('getShareByToken')
->with('invalidtoken')
->will($this->throwException(new ShareNotFound()));
+ $this->expectException(NotFoundException::class);
+
// Test without a not existing token
- $response = $this->shareController->showShare('invalidtoken');
- $expectedResponse = new NotFoundResponse();
- $this->assertEquals($expectedResponse, $response);
+ $this->shareController->showShare();
}
public function testShowShareNotAuthenticated() {
+ $this->shareController->setToken('validtoken');
+
$share = \OC::$server->getShareManager()->newShare();
$share->setPassword('password');
@@ -352,19 +184,16 @@ class ShareControllerTest extends \Test\TestCase {
->with('validtoken')
->willReturn($share);
- $this->urlGenerator->expects($this->once())
- ->method('linkToRoute')
- ->with('files_sharing.sharecontroller.authenticate', ['token' => 'validtoken', 'redirect' => 'preview'])
- ->willReturn('redirect');
+ $this->expectException(NotFoundException::class);
// Test without a not existing token
- $response = $this->shareController->showShare('validtoken');
- $expectedResponse = new RedirectResponse('redirect');
- $this->assertEquals($expectedResponse, $response);
+ $this->shareController->showShare();
}
public function testShowShare() {
+ $this->shareController->setToken('token');
+
$owner = $this->getMockBuilder(IUser::class)->getMock();
$owner->method('getDisplayName')->willReturn('ownerDisplay');
$owner->method('getUID')->willReturn('ownerUID');
@@ -428,7 +257,7 @@ class ShareControllerTest extends \Test\TestCase {
return vsprintf($text, $parameters);
}));
- $response = $this->shareController->showShare('token');
+ $response = $this->shareController->showShare();
$sharedTmplParams = array(
'displayName' => 'ownerDisplay',
'owner' => 'ownerUID',
@@ -476,6 +305,8 @@ class ShareControllerTest extends \Test\TestCase {
* @expectedException \OCP\Files\NotFoundException
*/
public function testShowShareInvalid() {
+ $this->shareController->setToken('token');
+
$owner = $this->getMockBuilder(IUser::class)->getMock();
$owner->method('getDisplayName')->willReturn('ownerDisplay');
$owner->method('getUID')->willReturn('ownerUID');
@@ -517,32 +348,7 @@ class ShareControllerTest extends \Test\TestCase {
$this->userManager->method('get')->with('ownerUID')->willReturn($owner);
- $this->shareController->showShare('token');
- }
-
- public function testDownloadShare() {
- $share = $this->getMockBuilder(IShare::class)->getMock();
- $share->method('getPassword')->willReturn('password');
- $share
- ->expects($this->once())
- ->method('getPermissions')
- ->willReturn(\OCP\Constants::PERMISSION_READ);
-
- $this->shareManager
- ->expects($this->once())
- ->method('getShareByToken')
- ->with('validtoken')
- ->willReturn($share);
-
- $this->urlGenerator->expects($this->once())
- ->method('linkToRoute')
- ->with('files_sharing.sharecontroller.authenticate', ['token' => 'validtoken', 'redirect' => 'download'])
- ->willReturn('redirect');
-
- // Test with a password protected share and no authentication
- $response = $this->shareController->downloadShare('validtoken');
- $expectedResponse = new RedirectResponse('redirect');
- $this->assertEquals($expectedResponse, $response);
+ $this->shareController->showShare();
}
public function testDownloadShareWithCreateOnlyShare() {