|
|
|
|
@ -7,6 +7,7 @@ |
|
|
|
|
*/ |
|
|
|
|
namespace OCA\Files_Sharing\Tests\Controller; |
|
|
|
|
|
|
|
|
|
use OCA\Federation\TrustedServers; |
|
|
|
|
use OCA\Files_Sharing\Controller\ShareAPIController; |
|
|
|
|
use OCP\App\IAppManager; |
|
|
|
|
use OCP\AppFramework\Http\DataResponse; |
|
|
|
|
@ -82,6 +83,7 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
|
private IProviderFactory&MockObject $factory; |
|
|
|
|
private IMailer&MockObject $mailer; |
|
|
|
|
private ITagManager&MockObject $tagManager; |
|
|
|
|
private TrustedServers&MockObject $trustedServers; |
|
|
|
|
|
|
|
|
|
protected function setUp(): void { |
|
|
|
|
$this->shareManager = $this->createMock(IManager::class); |
|
|
|
|
@ -119,6 +121,7 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
|
$this->factory = $this->createMock(IProviderFactory::class); |
|
|
|
|
$this->mailer = $this->createMock(IMailer::class); |
|
|
|
|
$this->tagManager = $this->createMock(ITagManager::class); |
|
|
|
|
$this->trustedServers = $this->createMock(TrustedServers::class); |
|
|
|
|
|
|
|
|
|
$this->ocs = new ShareAPIController( |
|
|
|
|
$this->appName, |
|
|
|
|
@ -140,8 +143,10 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
|
$this->factory, |
|
|
|
|
$this->mailer, |
|
|
|
|
$this->tagManager, |
|
|
|
|
$this->currentUser, |
|
|
|
|
$this->trustedServers, |
|
|
|
|
$this->currentUser |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -169,6 +174,7 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
|
$this->factory, |
|
|
|
|
$this->mailer, |
|
|
|
|
$this->tagManager, |
|
|
|
|
$this->trustedServers, |
|
|
|
|
$this->currentUser, |
|
|
|
|
])->onlyMethods(['formatShare']) |
|
|
|
|
->getMock(); |
|
|
|
|
@ -853,6 +859,7 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
|
$this->factory, |
|
|
|
|
$this->mailer, |
|
|
|
|
$this->tagManager, |
|
|
|
|
$this->trustedServers, |
|
|
|
|
$this->currentUser, |
|
|
|
|
]) |
|
|
|
|
->onlyMethods(['canAccessShare']) |
|
|
|
|
@ -1485,6 +1492,7 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
|
$this->factory, |
|
|
|
|
$this->mailer, |
|
|
|
|
$this->tagManager, |
|
|
|
|
$this->trustedServers, |
|
|
|
|
$this->currentUser, |
|
|
|
|
]) |
|
|
|
|
->onlyMethods(['formatShare']) |
|
|
|
|
@ -1873,6 +1881,7 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
|
$this->factory, |
|
|
|
|
$this->mailer, |
|
|
|
|
$this->tagManager, |
|
|
|
|
$this->trustedServers, |
|
|
|
|
$this->currentUser, |
|
|
|
|
])->onlyMethods(['formatShare']) |
|
|
|
|
->getMock(); |
|
|
|
|
@ -1972,6 +1981,7 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
|
$this->factory, |
|
|
|
|
$this->mailer, |
|
|
|
|
$this->tagManager, |
|
|
|
|
$this->trustedServers, |
|
|
|
|
$this->currentUser, |
|
|
|
|
])->onlyMethods(['formatShare']) |
|
|
|
|
->getMock(); |
|
|
|
|
@ -2399,6 +2409,7 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
|
$this->factory, |
|
|
|
|
$this->mailer, |
|
|
|
|
$this->tagManager, |
|
|
|
|
$this->trustedServers, |
|
|
|
|
$this->currentUser, |
|
|
|
|
])->onlyMethods(['formatShare']) |
|
|
|
|
->getMock(); |
|
|
|
|
@ -2471,6 +2482,7 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
|
$this->factory, |
|
|
|
|
$this->mailer, |
|
|
|
|
$this->tagManager, |
|
|
|
|
$this->trustedServers, |
|
|
|
|
$this->currentUser, |
|
|
|
|
])->onlyMethods(['formatShare']) |
|
|
|
|
->getMock(); |
|
|
|
|
@ -2710,6 +2722,7 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
|
$this->factory, |
|
|
|
|
$this->mailer, |
|
|
|
|
$this->tagManager, |
|
|
|
|
$this->trustedServers, |
|
|
|
|
$this->currentUser, |
|
|
|
|
])->onlyMethods(['formatShare']) |
|
|
|
|
->getMock(); |
|
|
|
|
@ -4492,6 +4505,7 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
|
'mount-type' => '', |
|
|
|
|
'attributes' => null, |
|
|
|
|
'item_permissions' => 1, |
|
|
|
|
'is_trusted_server' => false, |
|
|
|
|
], $share, [], false |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
@ -4545,6 +4559,7 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
|
'mount-type' => '', |
|
|
|
|
'attributes' => null, |
|
|
|
|
'item_permissions' => 1, |
|
|
|
|
'is_trusted_server' => false, |
|
|
|
|
], $share, [], false |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
@ -5228,4 +5243,138 @@ class ShareAPIControllerTest extends TestCase { |
|
|
|
|
['file_source' => 42, 'x' => 'y', 'tags' => ['tag1', 'tag2']], |
|
|
|
|
], $result); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function trustedServerProvider(): array { |
|
|
|
|
return [ |
|
|
|
|
'Trusted server' => [true, true], |
|
|
|
|
'Untrusted server' => [false, false], |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @dataProvider trustedServerProvider |
|
|
|
|
*/ |
|
|
|
|
public function testFormatShareWithFederatedShare(bool $isKnownServer, bool $isTrusted): void { |
|
|
|
|
$nodeId = 12; |
|
|
|
|
$nodePath = '/test.txt'; |
|
|
|
|
$share = $this->createShare( |
|
|
|
|
1, |
|
|
|
|
IShare::TYPE_REMOTE, |
|
|
|
|
'recipient@remoteserver.com', // shared with |
|
|
|
|
'sender@testserver.com', // shared by |
|
|
|
|
'shareOwner', // share owner |
|
|
|
|
$nodePath, // path |
|
|
|
|
Constants::PERMISSION_READ, |
|
|
|
|
time(), |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
$nodePath, |
|
|
|
|
$nodeId |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$node = $this->createMock(\OCP\Files\File::class); |
|
|
|
|
$node->method('getId')->willReturn($nodeId); |
|
|
|
|
$node->method('getPath')->willReturn($nodePath); |
|
|
|
|
$node->method('getInternalPath')->willReturn(ltrim($nodePath, '/')); |
|
|
|
|
$mountPoint = $this->createMock(\OCP\Files\Mount\IMountPoint::class); |
|
|
|
|
$mountPoint->method('getMountType')->willReturn('local'); |
|
|
|
|
$node->method('getMountPoint')->willReturn($mountPoint); |
|
|
|
|
$node->method('getMimetype')->willReturn('text/plain'); |
|
|
|
|
$storage = $this->createMock(\OCP\Files\Storage\IStorage::class); |
|
|
|
|
$storageCache = $this->createMock(\OCP\Files\Cache\ICache::class); |
|
|
|
|
$storageCache->method('getNumericStorageId')->willReturn(1); |
|
|
|
|
$storage->method('getCache')->willReturn($storageCache); |
|
|
|
|
$storage->method('getId')->willReturn('home::shareOwner'); |
|
|
|
|
$node->method('getStorage')->willReturn($storage); |
|
|
|
|
$parent = $this->createMock(\OCP\Files\Folder::class); |
|
|
|
|
$parent->method('getId')->willReturn(2); |
|
|
|
|
$node->method('getParent')->willReturn($parent); |
|
|
|
|
$node->method('getSize')->willReturn(1234); |
|
|
|
|
$node->method('getMTime')->willReturn(1234567890); |
|
|
|
|
|
|
|
|
|
$this->previewManager->method('isAvailable')->with($node)->willReturn(false); |
|
|
|
|
|
|
|
|
|
$this->rootFolder->method('getUserFolder') |
|
|
|
|
->with($this->currentUser) |
|
|
|
|
->willReturnSelf(); |
|
|
|
|
|
|
|
|
|
$this->rootFolder->method('getFirstNodeById') |
|
|
|
|
->with($share->getNodeId()) |
|
|
|
|
->willReturn($node); |
|
|
|
|
|
|
|
|
|
$this->rootFolder->method('getRelativePath') |
|
|
|
|
->with($node->getPath()) |
|
|
|
|
->willReturnArgument(0); |
|
|
|
|
|
|
|
|
|
$serverName = 'remoteserver.com'; |
|
|
|
|
$this->trustedServers->method('isTrustedServer') |
|
|
|
|
->with($serverName) |
|
|
|
|
->willReturn($isKnownServer); |
|
|
|
|
|
|
|
|
|
$result = $this->invokePrivate($this->ocs, 'formatShare', [$share]); |
|
|
|
|
|
|
|
|
|
$this->assertSame($isTrusted, $result['is_trusted_server']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function testFormatShareWithFederatedShareWithAtInUsername(): void { |
|
|
|
|
$nodeId = 12; |
|
|
|
|
$nodePath = '/test.txt'; |
|
|
|
|
$share = $this->createShare( |
|
|
|
|
1, |
|
|
|
|
IShare::TYPE_REMOTE, |
|
|
|
|
'recipient@domain.com@remoteserver.com', |
|
|
|
|
'sender@testserver.com', |
|
|
|
|
'shareOwner', |
|
|
|
|
$nodePath, |
|
|
|
|
Constants::PERMISSION_READ, |
|
|
|
|
time(), |
|
|
|
|
null, |
|
|
|
|
null, |
|
|
|
|
$nodePath, |
|
|
|
|
$nodeId |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$node = $this->createMock(\OCP\Files\File::class); |
|
|
|
|
$node->method('getId')->willReturn($nodeId); |
|
|
|
|
$node->method('getPath')->willReturn($nodePath); |
|
|
|
|
$node->method('getInternalPath')->willReturn(ltrim($nodePath, '/')); |
|
|
|
|
$mountPoint = $this->createMock(\OCP\Files\Mount\IMountPoint::class); |
|
|
|
|
$mountPoint->method('getMountType')->willReturn('local'); |
|
|
|
|
$node->method('getMountPoint')->willReturn($mountPoint); |
|
|
|
|
$node->method('getMimetype')->willReturn('text/plain'); |
|
|
|
|
$storage = $this->createMock(\OCP\Files\Storage\IStorage::class); |
|
|
|
|
$storageCache = $this->createMock(\OCP\Files\Cache\ICache::class); |
|
|
|
|
$storageCache->method('getNumericStorageId')->willReturn(1); |
|
|
|
|
$storage->method('getCache')->willReturn($storageCache); |
|
|
|
|
$storage->method('getId')->willReturn('home::shareOwner'); |
|
|
|
|
$node->method('getStorage')->willReturn($storage); |
|
|
|
|
$parent = $this->createMock(\OCP\Files\Folder::class); |
|
|
|
|
$parent->method('getId')->willReturn(2); |
|
|
|
|
$node->method('getParent')->willReturn($parent); |
|
|
|
|
$node->method('getSize')->willReturn(1234); |
|
|
|
|
$node->method('getMTime')->willReturn(1234567890); |
|
|
|
|
|
|
|
|
|
$this->previewManager->method('isAvailable')->with($node)->willReturn(false); |
|
|
|
|
|
|
|
|
|
$this->rootFolder->method('getUserFolder') |
|
|
|
|
->with($this->currentUser) |
|
|
|
|
->willReturnSelf(); |
|
|
|
|
|
|
|
|
|
$this->rootFolder->method('getFirstNodeById') |
|
|
|
|
->with($share->getNodeId()) |
|
|
|
|
->willReturn($node); |
|
|
|
|
|
|
|
|
|
$this->rootFolder->method('getRelativePath') |
|
|
|
|
->with($node->getPath()) |
|
|
|
|
->willReturnArgument(0); |
|
|
|
|
|
|
|
|
|
$serverName = 'remoteserver.com'; |
|
|
|
|
$this->trustedServers->method('isTrustedServer') |
|
|
|
|
->with($serverName) |
|
|
|
|
->willReturn(true); |
|
|
|
|
|
|
|
|
|
$result = $this->invokePrivate($this->ocs, 'formatShare', [$share]); |
|
|
|
|
|
|
|
|
|
$this->assertTrue($result['is_trusted_server']); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|