Skip to content

Commit

Permalink
[master] Respect sharing.federation.allowHttpFallback in FederatedSha…
Browse files Browse the repository at this point in the history
…reProvider
  • Loading branch information
DeepDiver1975 committed Apr 19, 2018
1 parent 23eea00 commit fb439b7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
3 changes: 2 additions & 1 deletion apps/federatedfilesharing/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public function __construct(Notifications $notifications = null) {
$addressHandler,
\OC::$server->getHTTPClientService(),
$discoveryManager,
\OC::$server->getJobList()
\OC::$server->getJobList(),
\OC::$server->getConfig()
);
}

Expand Down
17 changes: 14 additions & 3 deletions apps/federatedfilesharing/lib/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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://';
}
Expand Down
24 changes: 16 additions & 8 deletions apps/federatedfilesharing/tests/NotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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();

}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Share20/ProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion ocs/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit fb439b7

Please sign in to comment.