summaryrefslogtreecommitdiffstats
path: root/apps/federatedfilesharing/tests
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2017-03-10 15:37:21 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2017-04-11 15:04:01 +0200
commit449011dae7ea0ec7eb8d6c78e89709982020e709 (patch)
treee102862917001ace40e23d7126973612cf7f2ac6 /apps/federatedfilesharing/tests
parent0dea31d48bbd0361cca4d67b9de05a9f9ad3a198 (diff)
downloadnextcloud-server-449011dae7ea0ec7eb8d6c78e89709982020e709.tar.gz
nextcloud-server-449011dae7ea0ec7eb8d6c78e89709982020e709.zip
remove discovery manager in favour of the OCSDiscoveryService
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'apps/federatedfilesharing/tests')
-rw-r--r--apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php6
-rw-r--r--apps/federatedfilesharing/tests/DiscoveryManagerTest.php217
-rw-r--r--apps/federatedfilesharing/tests/NotificationsTest.php13
3 files changed, 7 insertions, 229 deletions
diff --git a/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php b/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php
index 233395dec9f..c695fb140e5 100644
--- a/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php
+++ b/apps/federatedfilesharing/tests/Controller/RequestHandlerControllerTest.php
@@ -270,17 +270,13 @@ class RequestHandlerControllerTest extends TestCase {
->method('newClient')
->willReturn($client);
- $discoveryManager = new DiscoveryManager(
- \OC::$server->getMemCacheFactory(),
- $httpClientService
- );
$manager = new \OCA\Files_Sharing\External\Manager(
\OC::$server->getDatabaseConnection(),
Filesystem::getMountManager(),
Filesystem::getLoader(),
$httpClientService,
\OC::$server->getNotificationManager(),
- $discoveryManager,
+ \OC::$server->getOCSDiscoveryService(),
$toDelete
);
diff --git a/apps/federatedfilesharing/tests/DiscoveryManagerTest.php b/apps/federatedfilesharing/tests/DiscoveryManagerTest.php
deleted file mode 100644
index 77e24aad54b..00000000000
--- a/apps/federatedfilesharing/tests/DiscoveryManagerTest.php
+++ /dev/null
@@ -1,217 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Björn Schießle <bjoern@schiessle.org>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Vincent Petry <pvince81@owncloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OCA\FederatedFileSharing\Tests;
-
-use OCA\FederatedFileSharing\DiscoveryManager;
-use OCP\Http\Client\IClient;
-use OCP\Http\Client\IClientService;
-use OCP\ICache;
-use OCP\ICacheFactory;
-
-class DiscoveryManagerTest extends \Test\TestCase {
- /** @var ICache */
- private $cache;
- /** @var IClient */
- private $client;
- /** @var DiscoveryManager */
- private $discoveryManager;
-
- public function setUp() {
- parent::setUp();
- $this->cache = $this->getMockBuilder('\OCP\ICache')
- ->getMock();
- /** @var ICacheFactory $cacheFactory */
- $cacheFactory = $this->getMockBuilder('\OCP\ICacheFactory')
- ->disableOriginalConstructor()->getMock();
- $cacheFactory
- ->expects($this->once())
- ->method('create')
- ->with('ocs-discovery')
- ->willReturn($this->cache);
-
- $this->client = $this->getMockBuilder('\OCP\Http\Client\IClient')
- ->disableOriginalConstructor()->getMock();
- /** @var IClientService $clientService */
- $clientService = $this->getMockBuilder('\OCP\Http\Client\IClientService')
- ->disableOriginalConstructor()->getMock();
- $clientService
- ->expects($this->once())
- ->method('newClient')
- ->willReturn($this->client);
-
- $this->discoveryManager = new DiscoveryManager(
- $cacheFactory,
- $clientService
- );
- }
-
- public function testWithMalformedFormattedEndpointCached() {
- $response = $this->getMockBuilder('\OCP\Http\Client\IResponse')
- ->getMock();
- $response
- ->expects($this->once())
- ->method('getStatusCode')
- ->willReturn(200);
- $response
- ->expects($this->once())
- ->method('getBody')
- ->willReturn('CertainlyNotJson');
- $this->client
- ->expects($this->once())
- ->method('get')
- ->with('https://myhost.com/ocs-provider/', [
- 'timeout' => 10,
- 'connect_timeout' => 10,
- ])
- ->willReturn($response);
- $this->cache
- ->expects($this->at(0))
- ->method('get')
- ->with('https://myhost.com')
- ->willReturn(null);
- $this->cache
- ->expects($this->at(1))
- ->method('set')
- ->with('https://myhost.com', '{"webdav":"\/public.php\/webdav","share":"\/ocs\/v1.php\/cloud\/shares"}');
- $this->cache
- ->expects($this->at(2))
- ->method('get')
- ->with('https://myhost.com')
- ->willReturn('{"webdav":"\/public.php\/webdav","share":"\/ocs\/v1.php\/cloud\/shares"}');
-
- $this->assertSame('/public.php/webdav', $this->discoveryManager->getWebDavEndpoint('https://myhost.com'));
- $this->assertSame('/ocs/v1.php/cloud/shares', $this->discoveryManager->getShareEndpoint('https://myhost.com'));
- }
-
- public function testGetWebDavEndpointWithValidFormattedEndpointAndNotCached() {
- $response = $this->getMockBuilder('\OCP\Http\Client\IResponse')
- ->getMock();
- $response
- ->expects($this->once())
- ->method('getStatusCode')
- ->willReturn(200);
- $response
- ->expects($this->once())
- ->method('getBody')
- ->willReturn('{"version":2,"services":{"PRIVATE_DATA":{"version":1,"endpoints":{"store":"\/ocs\/v2.php\/privatedata\/setattribute","read":"\/ocs\/v2.php\/privatedata\/getattribute","delete":"\/ocs\/v2.php\/privatedata\/deleteattribute"}},"SHARING":{"version":1,"endpoints":{"share":"\/ocs\/v2.php\/apps\/files_sharing\/api\/v1\/shares"}},"FEDERATED_SHARING":{"version":1,"endpoints":{"share":"\/ocs\/v2.php\/cloud\/shares","webdav":"\/public.php\/MyCustomEndpoint\/"}},"ACTIVITY":{"version":1,"endpoints":{"list":"\/ocs\/v2.php\/cloud\/activity"}},"PROVISIONING":{"version":1,"endpoints":{"user":"\/ocs\/v2.php\/cloud\/users","groups":"\/ocs\/v2.php\/cloud\/groups","apps":"\/ocs\/v2.php\/cloud\/apps"}}}}');
- $this->client
- ->expects($this->once())
- ->method('get')
- ->with('https://myhost.com/ocs-provider/', [
- 'timeout' => 10,
- 'connect_timeout' => 10,
- ])
- ->willReturn($response);
-
- $expectedResult = '/public.php/MyCustomEndpoint/';
- $this->assertSame($expectedResult, $this->discoveryManager->getWebDavEndpoint('https://myhost.com'));
- }
-
- public function testGetWebDavEndpointWithValidFormattedEndpointWithoutDataAndNotCached() {
- $response = $this->getMockBuilder('\OCP\Http\Client\IResponse')
- ->getMock();
- $response
- ->expects($this->once())
- ->method('getStatusCode')
- ->willReturn(200);
- $response
- ->expects($this->once())
- ->method('getBody')
- ->willReturn('{"version":2,"PRIVATE_DATA":{"version":1,"endpoints":{"store":"\/ocs\/v2.php\/privatedata\/setattribute","read":"\/ocs\/v2.php\/privatedata\/getattribute","delete":"\/ocs\/v2.php\/privatedata\/deleteattribute"}},"SHARING":{"version":1,"endpoints":{"share":"\/ocs\/v2.php\/apps\/files_sharing\/api\/v1\/shares"}},"FEDERATED_SHARING":{"version":1,"endpoints":{"share":"\/ocs\/v2.php\/cloud\/shares","webdav":"\/public.php\/MyCustomEndpoint\/"}},"ACTIVITY":{"version":1,"endpoints":{"list":"\/ocs\/v2.php\/cloud\/activity"}},"PROVISIONING":{"version":1,"endpoints":{"user":"\/ocs\/v2.php\/cloud\/users","groups":"\/ocs\/v2.php\/cloud\/groups","apps":"\/ocs\/v2.php\/cloud\/apps"}}}');
- $this->client
- ->expects($this->once())
- ->method('get')
- ->with('https://myhost.com/ocs-provider/', [
- 'timeout' => 10,
- 'connect_timeout' => 10,
- ])
- ->willReturn($response);
-
- $expectedResult = '/public.php/webdav';
- $this->assertSame($expectedResult, $this->discoveryManager->getWebDavEndpoint('https://myhost.com'));
- }
-
- public function testGetShareEndpointWithValidFormattedEndpointAndNotCached() {
- $response = $this->getMockBuilder('\OCP\Http\Client\IResponse')
- ->getMock();
- $response
- ->expects($this->once())
- ->method('getStatusCode')
- ->willReturn(200);
- $response
- ->expects($this->once())
- ->method('getBody')
- ->willReturn('{"version":2,"services":{"PRIVATE_DATA":{"version":1,"endpoints":{"store":"\/ocs\/v2.php\/privatedata\/setattribute","read":"\/ocs\/v2.php\/privatedata\/getattribute","delete":"\/ocs\/v2.php\/privatedata\/deleteattribute"}},"SHARING":{"version":1,"endpoints":{"share":"\/ocs\/v2.php\/apps\/files_sharing\/api\/v1\/shares"}},"FEDERATED_SHARING":{"version":1,"endpoints":{"share":"\/ocs\/v2.php\/cloud\/MyCustomShareEndpoint","webdav":"\/public.php\/MyCustomEndpoint\/"}},"ACTIVITY":{"version":1,"endpoints":{"list":"\/ocs\/v2.php\/cloud\/activity"}},"PROVISIONING":{"version":1,"endpoints":{"user":"\/ocs\/v2.php\/cloud\/users","groups":"\/ocs\/v2.php\/cloud\/groups","apps":"\/ocs\/v2.php\/cloud\/apps"}}}}');
- $this->client
- ->expects($this->once())
- ->method('get')
- ->with('https://myhost.com/ocs-provider/', [
- 'timeout' => 10,
- 'connect_timeout' => 10,
- ])
- ->willReturn($response);
-
- $expectedResult = '/ocs/v2.php/cloud/MyCustomShareEndpoint';
- $this->assertSame($expectedResult, $this->discoveryManager->getShareEndpoint('https://myhost.com'));
- }
-
- public function testWithMaliciousEndpointCached() {
- $response = $this->getMockBuilder('\OCP\Http\Client\IResponse')
- ->getMock();
- $response
- ->expects($this->once())
- ->method('getStatusCode')
- ->willReturn(200);
- $response
- ->expects($this->once())
- ->method('getBody')
- ->willReturn('{"version":2,"services":{"PRIVATE_DATA":{"version":1,"endpoints":{"store":"\/ocs\/v2.php\/privatedata\/setattribute","read":"\/ocs\/v2.php\/privatedata\/getattribute","delete":"\/ocs\/v2.php\/privatedata\/deleteattribute"}},"SHARING":{"version":1,"endpoints":{"share":"\/ocs\/v2.php\/apps\/files_sharing\/api\/v1\/shares"}},"FEDERATED_SHARING":{"version":1,"endpoints":{"share":"\/ocs\/v2.php\/cl@oud\/MyCustomShareEndpoint","webdav":"\/public.php\/MyC:ustomEndpoint\/"}},"ACTIVITY":{"version":1,"endpoints":{"list":"\/ocs\/v2.php\/cloud\/activity"}},"PROVISIONING":{"version":1,"endpoints":{"user":"\/ocs\/v2.php\/cloud\/users","groups":"\/ocs\/v2.php\/cloud\/groups","apps":"\/ocs\/v2.php\/cloud\/apps"}}}}');
- $this->client
- ->expects($this->once())
- ->method('get')
- ->with('https://myhost.com/ocs-provider/', [
- 'timeout' => 10,
- 'connect_timeout' => 10,
- ])
- ->willReturn($response);
- $this->cache
- ->expects($this->at(0))
- ->method('get')
- ->with('https://myhost.com')
- ->willReturn(null);
- $this->cache
- ->expects($this->at(1))
- ->method('set')
- ->with('https://myhost.com', '{"webdav":"\/public.php\/webdav","share":"\/ocs\/v1.php\/cloud\/shares"}');
- $this->cache
- ->expects($this->at(2))
- ->method('get')
- ->with('https://myhost.com')
- ->willReturn('{"webdav":"\/public.php\/webdav","share":"\/ocs\/v1.php\/cloud\/shares"}');
-
- $this->assertSame('/public.php/webdav', $this->discoveryManager->getWebDavEndpoint('https://myhost.com'));
- $this->assertSame('/ocs/v1.php/cloud/shares', $this->discoveryManager->getShareEndpoint('https://myhost.com'));
- }
-}
diff --git a/apps/federatedfilesharing/tests/NotificationsTest.php b/apps/federatedfilesharing/tests/NotificationsTest.php
index a5f5c6bc078..4f70d5f3950 100644
--- a/apps/federatedfilesharing/tests/NotificationsTest.php
+++ b/apps/federatedfilesharing/tests/NotificationsTest.php
@@ -25,10 +25,10 @@ namespace OCA\FederatedFileSharing\Tests;
use OCA\FederatedFileSharing\AddressHandler;
-use OCA\FederatedFileSharing\DiscoveryManager;
use OCA\FederatedFileSharing\Notifications;
use OCP\BackgroundJob\IJobList;
use OCP\Http\Client\IClientService;
+use OCP\OCS\IDiscoveryService;
class NotificationsTest extends \Test\TestCase {
@@ -38,8 +38,8 @@ class NotificationsTest extends \Test\TestCase {
/** @var IClientService | \PHPUnit_Framework_MockObject_MockObject*/
private $httpClientService;
- /** @var DiscoveryManager | \PHPUnit_Framework_MockObject_MockObject */
- private $discoveryManager;
+ /** @var IDiscoveryService | \PHPUnit_Framework_MockObject_MockObject */
+ private $discoveryService;
/** @var IJobList | \PHPUnit_Framework_MockObject_MockObject */
private $jobList;
@@ -48,8 +48,7 @@ class NotificationsTest extends \Test\TestCase {
parent::setUp();
$this->jobList = $this->getMockBuilder('OCP\BackgroundJob\IJobList')->getMock();
- $this->discoveryManager = $this->getMockBuilder('OCA\FederatedFileSharing\DiscoveryManager')
- ->disableOriginalConstructor()->getMock();
+ $this->discoveryService = $this->getMockBuilder(IDiscoveryService::class)->getMock();
$this->httpClientService = $this->getMockBuilder('OCP\Http\Client\IClientService')->getMock();
$this->addressHandler = $this->getMockBuilder('OCA\FederatedFileSharing\AddressHandler')
->disableOriginalConstructor()->getMock();
@@ -67,7 +66,7 @@ class NotificationsTest extends \Test\TestCase {
$instance = new Notifications(
$this->addressHandler,
$this->httpClientService,
- $this->discoveryManager,
+ $this->discoveryService,
$this->jobList
);
} else {
@@ -76,7 +75,7 @@ class NotificationsTest extends \Test\TestCase {
[
$this->addressHandler,
$this->httpClientService,
- $this->discoveryManager,
+ $this->discoveryService,
$this->jobList
]
)->setMethods($mockedMethods)->getMock();