diff --git a/apps/federatedfilesharing/lib/AppInfo/Application.php b/apps/federatedfilesharing/lib/AppInfo/Application.php index 77648e7c75c1..7ec68d56b4cc 100644 --- a/apps/federatedfilesharing/lib/AppInfo/Application.php +++ b/apps/federatedfilesharing/lib/AppInfo/Application.php @@ -57,7 +57,8 @@ protected function initFederatedShareProvider() { $addressHandler, \OC::$server->getHTTPClientService(), $discoveryManager, - \OC::$server->getJobList() + \OC::$server->getJobList(), + \OC::$server->getConfig() ); $tokenHandler = new \OCA\FederatedFileSharing\TokenHandler( \OC::$server->getSecureRandom() diff --git a/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php b/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php index ec192352c7fb..3d7be49d85d7 100644 --- a/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php +++ b/apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php @@ -74,7 +74,8 @@ public function __construct(Notifications $notifications = null) { $addressHandler, \OC::$server->getHTTPClientService(), $discoveryManager, - \OC::$server->getJobList() + \OC::$server->getJobList(), + \OC::$server->getConfig() ); } diff --git a/apps/federatedfilesharing/lib/Notifications.php b/apps/federatedfilesharing/lib/Notifications.php index 2557d916086d..4b62b496695d 100644 --- a/apps/federatedfilesharing/lib/Notifications.php +++ b/apps/federatedfilesharing/lib/Notifications.php @@ -29,6 +29,7 @@ use OCP\AppFramework\Http; use OCP\BackgroundJob\IJobList; use OCP\Http\Client\IClientService; +use OCP\IConfig; class Notifications { const RESPONSE_FORMAT = 'json'; // default response format for ocs calls @@ -45,22 +46,28 @@ class Notifications { /** @var IJobList */ private $jobList; + /** @var IConfig */ + private $config; + /** * @param AddressHandler $addressHandler * @param IClientService $httpClientService * @param DiscoveryManager $discoveryManager * @param IJobList $jobList + * @param IConfig $config */ public function __construct( AddressHandler $addressHandler, IClientService $httpClientService, DiscoveryManager $discoveryManager, - IJobList $jobList + IJobList $jobList, + IConfig $config ) { $this->addressHandler = $addressHandler; $this->httpClientService = $httpClientService; $this->discoveryManager = $discoveryManager; $this->jobList = $jobList; + $this->config = $config; } /** @@ -122,8 +129,7 @@ public function sendRemoteShare($token, $shareWith, $name, $remote_id, $owner, $ * @param string $shareWith * @param int $permission * @return bool - * @throws \OC\HintException - * @throws \OC\ServerNotAvailableException + * @throws \Exception */ public function requestReShare($token, $id, $shareId, $remote, $shareWith, $permission) { @@ -222,6 +228,7 @@ public function sendDeclineShare($remote, $remoteId, $token) { * @param array $data * @param int $try * @return boolean + * @throws \Exception */ public function sendUpdateToRemote($remote, $remoteId, $token, $action, $data = [], $try = 0) { @@ -303,6 +310,10 @@ protected function tryHttpPostToShareEndpoint($remoteDomain, $urlSuffix, array $ if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { throw $e; } + $allowHttpFallback = $this->config->getSystemValue('sharing.federation.allowHttpFallback', false) === true; + if (!$allowHttpFallback) { + throw $e; + } $try++; $protocol = 'http://'; } diff --git a/apps/federatedfilesharing/tests/NotificationsTest.php b/apps/federatedfilesharing/tests/NotificationsTest.php index 76323601de26..8289b173201f 100644 --- a/apps/federatedfilesharing/tests/NotificationsTest.php +++ b/apps/federatedfilesharing/tests/NotificationsTest.php @@ -29,6 +29,8 @@ use OCA\FederatedFileSharing\Notifications; use OCP\BackgroundJob\IJobList; use OCP\Http\Client\IClientService; +use OCP\IConfig; +use OCA\FederatedFileSharing\BackgroundJob\RetryJob; class NotificationsTest extends \Test\TestCase { @@ -44,14 +46,18 @@ class NotificationsTest extends \Test\TestCase { /** @var IJobList | \PHPUnit_Framework_MockObject_MockObject */ private $jobList; + /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */ + private $config; + public function setUp() { parent::setUp(); - $this->jobList = $this->createMock('OCP\BackgroundJob\IJobList'); - $this->discoveryManager = $this->getMockBuilder('OCA\FederatedFileSharing\DiscoveryManager') + $this->jobList = $this->createMock(IJobList::class); + $this->config = $this->createMock(IConfig::class); + $this->discoveryManager = $this->getMockBuilder(DiscoveryManager::class) ->disableOriginalConstructor()->getMock(); - $this->httpClientService = $this->createMock('OCP\Http\Client\IClientService'); - $this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler') + $this->httpClientService = $this->createMock(IClientService::class); + $this->addressHandler = $this->getMockBuilder(AddressHandler::class) ->disableOriginalConstructor()->getMock(); } @@ -68,16 +74,18 @@ private function getInstance(array $mockedMethods = []) { $this->addressHandler, $this->httpClientService, $this->discoveryManager, - $this->jobList + $this->jobList, + $this->config ); } else { - $instance = $this->getMockBuilder('OCA\FederatedFileSharing\Notifications') + $instance = $this->getMockBuilder(Notifications::class) ->setConstructorArgs( [ $this->addressHandler, $this->httpClientService, $this->discoveryManager, - $this->jobList + $this->jobList, + $this->config ] )->setMethods($mockedMethods)->getMock(); } @@ -113,7 +121,7 @@ public function testSendUpdateToRemote($try, $httpRequestResult, $expected) { if ($try === 0 && $expected === false) { $this->jobList->expects($this->once())->method('add') ->with( - 'OCA\FederatedFileSharing\BackgroundJob\RetryJob', + RetryJob::class, [ 'remote' => $remote, 'remoteId' => $id, diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php index 98c394e38d9b..30fe4de8a9b7 100644 --- a/lib/private/Share20/ProviderFactory.php +++ b/lib/private/Share20/ProviderFactory.php @@ -102,7 +102,8 @@ protected function federatedShareProvider() { $addressHandler, $this->serverContainer->getHTTPClientService(), $discoveryManager, - $this->serverContainer->getJobList() + $this->serverContainer->getJobList(), + $this->serverContainer->getConfig() ); $tokenHandler = new TokenHandler( $this->serverContainer->getSecureRandom() diff --git a/ocs/routes.php b/ocs/routes.php index d1f9c9ae4e72..5fddf3ef82bf 100644 --- a/ocs/routes.php +++ b/ocs/routes.php @@ -92,7 +92,8 @@ $addressHandler, \OC::$server->getHTTPClientService(), new \OCA\FederatedFileSharing\DiscoveryManager(\OC::$server->getMemCacheFactory(), \OC::$server->getHTTPClientService()), - \OC::$server->getJobList() + \OC::$server->getJobList(), + \OC::$server->getConfig() ); $s2s = new OCA\FederatedFileSharing\RequestHandler( $federatedSharingApp->getFederatedShareProvider(),