summaryrefslogtreecommitdiffstats
path: root/apps/federatedfilesharing/tests
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2016-05-11 20:48:27 +0200
committerBjörn Schießle <schiessle@owncloud.com>2016-05-20 21:15:15 +0200
commit7b25839bd51b3b6cd920209c254f014c03437113 (patch)
tree2e9885bdb068d56ff7bb9fde344c4da0cc95e2d3 /apps/federatedfilesharing/tests
parent81e3787f9cb4936f186b25e0dccb07b4e6dcce83 (diff)
downloadnextcloud-server-7b25839bd51b3b6cd920209c254f014c03437113.tar.gz
nextcloud-server-7b25839bd51b3b6cd920209c254f014c03437113.zip
use share initiator as fall back to access the file
in case of federated re-shares the owner can be a remote user. Therefore we can't always use to owner to access the local file
Diffstat (limited to 'apps/federatedfilesharing/tests')
-rw-r--r--apps/federatedfilesharing/tests/FederatedShareProviderTest.php52
1 files changed, 49 insertions, 3 deletions
diff --git a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
index 10770f00af5..9b3edf0398d 100644
--- a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
+++ b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
@@ -30,6 +30,7 @@ use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IL10N;
use OCP\ILogger;
+use OCP\IUserManager;
use OCP\Share\IManager;
/**
@@ -56,6 +57,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
protected $rootFolder;
/** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */
protected $config;
+ /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */
+ protected $userManager;
/** @var IManager */
protected $shareManager;
@@ -81,7 +84,9 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->logger = $this->getMock('OCP\ILogger');
$this->rootFolder = $this->getMock('OCP\Files\IRootFolder');
$this->config = $this->getMock('OCP\IConfig');
- $this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l);
+ $this->userManager = $this->getMock('OCP\IUserManager');
+ //$this->addressHandler = new AddressHandler(\OC::$server->getURLGenerator(), $this->l);
+ $this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')->disableOriginalConstructor()->getMock();
$this->userManager->expects($this->any())->method('userExists')->willReturn(true);
@@ -93,7 +98,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->l,
$this->logger,
$this->rootFolder,
- $this->config
+ $this->config,
+ $this->userManager
);
$this->shareManager = \OC::$server->getShareManager();
@@ -120,6 +126,11 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->tokenHandler->method('generateToken')->willReturn('token');
+ $this->addressHandler->expects($this->any())->method('generateRemoteURL')
+ ->willReturn('http://localhost/');
+ $this->addressHandler->expects($this->any())->method('splitUserRemote')
+ ->willReturn(['user', 'server.com']);
+
$this->notifications->expects($this->once())
->method('sendRemoteShare')
->with(
@@ -186,6 +197,11 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->tokenHandler->method('generateToken')->willReturn('token');
+ $this->addressHandler->expects($this->any())->method('generateRemoteURL')
+ ->willReturn('http://localhost/');
+ $this->addressHandler->expects($this->any())->method('splitUserRemote')
+ ->willReturn(['user', 'server.com']);
+
$this->notifications->expects($this->once())
->method('sendRemoteShare')
->with(
@@ -233,7 +249,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
$node->method('getId')->willReturn(42);
$node->method('getName')->willReturn('myFile');
- $shareWith = 'sharedBy@' . $this->addressHandler->generateRemoteURL();
+ $this->addressHandler->expects($this->any())->method('compareAddresses')
+ ->willReturn(true);
+
+ $shareWith = 'sharedBy@localhost';
$share->setSharedWith($shareWith)
->setSharedBy('sharedBy')
@@ -269,6 +288,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
$node->method('getId')->willReturn(42);
$node->method('getName')->willReturn('myFile');
+
+ $this->addressHandler->expects($this->any())->method('splitUserRemote')
+ ->willReturn(['user', 'server.com']);
+
$share->setSharedWith('user@server.com')
->setSharedBy('sharedBy')
->setShareOwner('shareOwner')
@@ -277,6 +300,9 @@ class FederatedShareProviderTest extends \Test\TestCase {
$this->tokenHandler->method('generateToken')->willReturn('token');
+ $this->addressHandler->expects($this->any())->method('generateRemoteURL')
+ ->willReturn('http://localhost/');
+
$this->notifications->expects($this->once())
->method('sendRemoteShare')
->with(
@@ -328,6 +354,10 @@ class FederatedShareProviderTest extends \Test\TestCase {
$node->method('getId')->willReturn(42);
$node->method('getName')->willReturn('myFile');
+
+ $this->addressHandler->expects($this->any())->method('splitUserRemote')
+ ->willReturn(['user', 'server.com']);
+
$share->setSharedWith('user@server.com')
->setSharedBy($sharedBy)
->setShareOwner($owner)
@@ -335,6 +365,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
->setNode($node);
$this->tokenHandler->method('generateToken')->willReturn('token');
+ $this->addressHandler->expects($this->any())->method('generateRemoteURL')
+ ->willReturn('http://localhost/');
$this->notifications->expects($this->once())
->method('sendRemoteShare')
@@ -379,6 +411,12 @@ class FederatedShareProviderTest extends \Test\TestCase {
$node->method('getId')->willReturn(42);
$node->method('getName')->willReturn('myFile');
+ $this->addressHandler->expects($this->at(0))->method('splitUserRemote')
+ ->willReturn(['user', 'server.com']);
+
+ $this->addressHandler->expects($this->at(1))->method('splitUserRemote')
+ ->willReturn(['user2', 'server.com']);
+
$this->tokenHandler->method('generateToken')->willReturn('token');
$this->notifications
->method('sendRemoteShare')
@@ -485,6 +523,14 @@ class FederatedShareProviderTest extends \Test\TestCase {
$node->method('getId')->willReturn(42);
$node->method('getName')->willReturn('myFile');
+ $this->addressHandler->expects($this->any())->method('splitUserRemote')
+ ->willReturnCallback(function ($uid) {
+ if ($uid === 'user@server.com') {
+ return ['user', 'server.com'];
+ }
+ return ['user2', 'server.com'];
+ });
+
$this->tokenHandler->method('generateToken')->willReturn('token');
$this->notifications
->method('sendRemoteShare')