diff --git a/apps/federatedfilesharing/tests/AdminPanelTest.php b/apps/federatedfilesharing/tests/AdminPanelTest.php
index 02c6ba730cef..2d2d18378c31 100644
--- a/apps/federatedfilesharing/tests/AdminPanelTest.php
+++ b/apps/federatedfilesharing/tests/AdminPanelTest.php
@@ -23,6 +23,7 @@
use OCA\FederatedFileSharing\AdminPanel;
use OCA\FederatedFileSharing\FederatedShareProvider;
+use OCP\IConfig;
/**
* @package OCA\FederatedFileSharing\Tests
@@ -33,13 +34,16 @@ class AdminPanelTest extends \Test\TestCase {
private $panel;
/** @var FederatedShareProvider */
private $shareProvider;
+ /** @var IConfig */
+ private $config;
public function setUp() {
parent::setUp();
$this->shareProvider = $this->getMockBuilder(FederatedShareProvider::class)
->disableOriginalConstructor()
->getMock();
- $this->panel = new AdminPanel($this->shareProvider);
+ $this->config = $this->createMock(IConfig::class);
+ $this->panel = new AdminPanel($this->shareProvider, $this->config);
}
public function testGetSection() {
diff --git a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
index ffb0fbd6574c..0129703ab5f1 100644
--- a/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
+++ b/apps/federatedfilesharing/tests/FederatedShareProviderTest.php
@@ -39,6 +39,8 @@
use OCP\Share\IShare;
use OCP\Files\Folder;
use OCP\IUser;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\EventDispatcher\GenericEvent;
/**
* Class FederatedShareProviderTest
@@ -50,6 +52,8 @@ class FederatedShareProviderTest extends \Test\TestCase {
/** @var IDBConnection */
protected $connection;
+ /** @var EventDispatcherInterface */
+ protected $eventDispatcher;
/** @var AddressHandler | \PHPUnit_Framework_MockObject_MockObject */
protected $addressHandler;
/** @var Notifications | \PHPUnit_Framework_MockObject_MockObject */
@@ -76,6 +80,9 @@ public function setUp() {
parent::setUp();
$this->connection = \OC::$server->getDatabaseConnection();
+ $this->eventDispatcher = $this->getMockBuilder(EventDispatcherInterface::class)
+ ->disableOriginalConstructor()
+ ->getMock();
$this->notifications = $this->getMockBuilder('OCA\FederatedFileSharing\Notifications')
->disableOriginalConstructor()
->getMock();
@@ -91,13 +98,13 @@ public function setUp() {
$this->rootFolder = $this->createMock('OCP\Files\IRootFolder');
$this->config = $this->createMock('OCP\IConfig');
$this->userManager = $this->createMock('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);
$this->provider = new FederatedShareProvider(
$this->connection,
+ $this->eventDispatcher,
$this->addressHandler,
$this->notifications,
$this->tokenHandler,
@@ -464,10 +471,11 @@ public function testCreateAlreadyShared() {
*
*/
public function testUpdate($owner, $sharedBy) {
- $this->provider = $this->getMockBuilder('OCA\FederatedFileSharing\FederatedShareProvider')
+ $this->provider = $this->getMockBuilder(FederatedShareProvider::class)
->setConstructorArgs(
[
$this->connection,
+ \OC::$server->getEventDispatcher(),
$this->addressHandler,
$this->notifications,
$this->tokenHandler,
@@ -884,4 +892,50 @@ public function testUpdateForRecipientReturnsShare() {
$this->assertEquals($share, $returnedShare);
}
+
+ /**
+ * @dataProvider dataTestGetAccepted
+ *
+ */
+ public function testGetAccepted($autoAddServers, $autoAccept, $isRemoteTrusted, $expected) {
+ $this->config->method('getAppValue')
+ ->with('federatedfilesharing', 'auto_accept_trusted', 'no')
+ ->willReturn($autoAccept);
+
+ $event = new GenericEvent(
+ '',
+ [
+ 'autoAddServers' => $autoAddServers,
+ 'isRemoteTrusted' => $isRemoteTrusted
+ ]
+ );
+ $this->eventDispatcher->method('dispatch')
+ ->with('remoteshare.received', $this->anything())
+ ->willReturn($event);
+
+ $shouldAutoAccept = $this->invokePrivate(
+ $this->provider,
+ 'getAccepted',
+ ['remote']
+ );
+
+ $this->assertEquals($expected, $shouldAutoAccept);
+ }
+
+ public function dataTestGetAccepted() {
+ return [
+ // never autoaccept when auto add to trusted is on
+ [true, 'yes', true, false],
+ [true, 'yes', false, false],
+ [true, 'no', true, false],
+ [true, 'no', false, false],
+ // never autoaccept when auto autoaccept is off
+ [false, 'no', false, false],
+ [false, 'no', true, false],
+ // never autoaccept when remote is not trusted
+ [false, 'yes', false, false],
+ // autoaccept
+ [false, 'yes', true, true],
+ ];
+ }
}
diff --git a/apps/federation/lib/AppInfo/Application.php b/apps/federation/lib/AppInfo/Application.php
index f2a6cf243a23..0bb39fa4b81f 100644
--- a/apps/federation/lib/AppInfo/Application.php
+++ b/apps/federation/lib/AppInfo/Application.php
@@ -120,6 +120,16 @@ public function registerHooks() {
}
}
});
+
+ $dispatcher->addListener(
+ 'remoteshare.received',
+ function ($event) use ($container) {
+ $remote = $event->getArgument('remote');
+ $trustedServers = $container->query('TrustedServers');
+ $event->setArgument('autoAddServers', $trustedServers->getAutoAddServers());
+ $event->setArgument('isRemoteTrusted', $trustedServers->isTrustedServer($remote));
+ }
+ );
}
/**
diff --git a/tests/acceptance/features/webUISharingExternal/federationSharing.feature b/tests/acceptance/features/webUISharingExternal/federationSharing.feature
index 11d6236c2de3..e9d2b8e59976 100644
--- a/tests/acceptance/features/webUISharingExternal/federationSharing.feature
+++ b/tests/acceptance/features/webUISharingExternal/federationSharing.feature
@@ -10,6 +10,7 @@ Feature: Federation Sharing - sharing with users on other cloud storages
And using server "LOCAL"
And user "user1" has been created with default attributes
And user "user1" has logged in using the webUI
+ And parameter "auto_accept_trusted" of app "federatedfilesharing" has been set to "no"
Scenario: test the single steps of sharing a folder to a remote server
When the user shares folder "simple-folder" with remote user "user1@%remote_server_without_scheme%" using the webUI
@@ -53,6 +54,17 @@ Feature: Federation Sharing - sharing with users on other cloud storages
Then file "lorem (2).txt" should not be listed on the webUI
And file "lorem (2).txt" should not be listed in the shared-with-you page on the webUI
+ Scenario: automatically accept a federation share when it is allowed by the config
+ Given parameter "autoAddServers" of app "federation" has been set to "1"
+ And user "user1" from server "REMOTE" has shared "simple-folder" with user "user1" from server "LOCAL"
+ And user "user1" from server "LOCAL" has accepted the last pending share
+ And the user has reloaded the current page of the webUI
+ And parameter "auto_accept_trusted" of app "federatedfilesharing" has been set to "yes"
+ And parameter "autoAddServers" of app "federation" has been set to "0"
+ When user "user1" from server "REMOTE" shares "/lorem.txt" with user "user1" from server "LOCAL" using the sharing API
+ And the user has reloaded the current page of the webUI
+ Then file "lorem (2).txt" should be listed on the webUI
+
@skipOnMICROSOFTEDGE
Scenario: share a folder with an remote user and prohibit deleting - local server shares - remote server receives
When the user shares folder "simple-folder" with remote user "user1@%remote_server_without_scheme%" using the webUI