1313use OCA \DAV \Db \DirectMapper ;
1414use OCP \AppFramework \Http \DataResponse ;
1515use OCP \AppFramework \OCS \OCSBadRequestException ;
16+ use OCP \AppFramework \OCS \OCSForbiddenException ;
1617use OCP \AppFramework \OCS \OCSNotFoundException ;
1718use OCP \AppFramework \Utility \ITimeFactory ;
1819use OCP \EventDispatcher \IEventDispatcher ;
2223use OCP \IRequest ;
2324use OCP \IURLGenerator ;
2425use OCP \Security \ISecureRandom ;
26+ use OCP \Share \IManager ;
2527use PHPUnit \Framework \MockObject \MockObject ;
2628use Test \TestCase ;
2729
@@ -32,6 +34,7 @@ class DirectControllerTest extends TestCase {
3234 private ITimeFactory &MockObject $ timeFactory ;
3335 private IURLGenerator &MockObject $ urlGenerator ;
3436 private IEventDispatcher &MockObject $ eventDispatcher ;
37+ private IManager &MockObject $ shareManager ;
3538
3639 private DirectController $ controller ;
3740
@@ -44,6 +47,7 @@ protected function setUp(): void {
4447 $ this ->timeFactory = $ this ->createMock (ITimeFactory::class);
4548 $ this ->urlGenerator = $ this ->createMock (IURLGenerator::class);
4649 $ this ->eventDispatcher = $ this ->createMock (IEventDispatcher::class);
50+ $ this ->shareManager = $ this ->createMock (IManager::class);
4751
4852 $ this ->controller = new DirectController (
4953 'dav ' ,
@@ -54,11 +58,15 @@ protected function setUp(): void {
5458 $ this ->random ,
5559 $ this ->timeFactory ,
5660 $ this ->urlGenerator ,
57- $ this ->eventDispatcher
61+ $ this ->eventDispatcher ,
62+ $ this ->shareManager ,
5863 );
5964 }
6065
6166 public function testGetUrlNonExistingFileId (): void {
67+ $ this ->shareManager ->method ('shareApiAllowLinks ' )
68+ ->willReturn (true );
69+
6270 $ userFolder = $ this ->createMock (Folder::class);
6371 $ this ->rootFolder ->method ('getUserFolder ' )
6472 ->with ('awesomeUser ' )
@@ -73,6 +81,9 @@ public function testGetUrlNonExistingFileId(): void {
7381 }
7482
7583 public function testGetUrlForFolder (): void {
84+ $ this ->shareManager ->method ('shareApiAllowLinks ' )
85+ ->willReturn (true );
86+
7687 $ userFolder = $ this ->createMock (Folder::class);
7788 $ this ->rootFolder ->method ('getUserFolder ' )
7889 ->with ('awesomeUser ' )
@@ -89,6 +100,9 @@ public function testGetUrlForFolder(): void {
89100 }
90101
91102 public function testGetUrlValid (): void {
103+ $ this ->shareManager ->method ('shareApiAllowLinks ' )
104+ ->willReturn (true );
105+
92106 $ userFolder = $ this ->createMock (Folder::class);
93107 $ this ->rootFolder ->method ('getUserFolder ' )
94108 ->with ('awesomeUser ' )
@@ -135,4 +149,23 @@ public function testGetUrlValid(): void {
135149 'url ' => 'https://my.nextcloud/remote.php/direct/superduperlongtoken ' ,
136150 ], $ result ->getData ());
137151 }
152+
153+ public function testGetUrlNoLinkShares (): void {
154+ $ this ->shareManager ->method ('shareApiAllowLinks ' )
155+ ->willReturn (false );
156+
157+ $ userFolder = $ this ->createMock (Folder::class);
158+ $ this ->rootFolder ->method ('getUserFolder ' )
159+ ->with ('awesomeUser ' )
160+ ->willReturn ($ userFolder );
161+
162+ $ file = $ this ->createMock (File::class);
163+
164+ $ userFolder ->method ('getFirstNodeById ' )
165+ ->with (101 )
166+ ->willReturn ($ file );
167+
168+ $ this ->expectException (OCSForbiddenException::class);
169+ $ this ->controller ->getUrl (101 );
170+ }
138171}
0 commit comments