diff options
author | Björn Schießle <bjoern@schiessle.org> | 2017-04-12 16:01:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-12 16:01:07 +0200 |
commit | b90e91144bc8d378f6f52025f04383ae2e7c647b (patch) | |
tree | 616619d3778182ac53e77dc605fc9bded595fc63 /tests/lib | |
parent | 3cf2f6e31bca4b704549e428d7fcbf6c4ecd6c37 (diff) | |
parent | 42f40659f664b4cdcdd5f19cf7300ad740aec6a4 (diff) | |
download | nextcloud-server-b90e91144bc8d378f6f52025f04383ae2e7c647b.tar.gz nextcloud-server-b90e91144bc8d378f6f52025f04383ae2e7c647b.zip |
Merge pull request #3614 from nextcloud/discover-federatedsharing-endpoints
Discover federatedsharing endpoints
Diffstat (limited to 'tests/lib')
-rw-r--r-- | tests/lib/OCS/DiscoveryServiceTest.php | 99 | ||||
-rw-r--r-- | tests/lib/Share/ShareTest.php | 12 |
2 files changed, 105 insertions, 6 deletions
diff --git a/tests/lib/OCS/DiscoveryServiceTest.php b/tests/lib/OCS/DiscoveryServiceTest.php new file mode 100644 index 00000000000..fdcdddb0813 --- /dev/null +++ b/tests/lib/OCS/DiscoveryServiceTest.php @@ -0,0 +1,99 @@ +<?php +/** + * @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * 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 + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + + +namespace Test\OCS; + + +use OC\OCS\DiscoveryService; +use OCP\Http\Client\IClientService; +use OCP\ICacheFactory; +use OCP\OCS\IDiscoveryService; +use Test\TestCase; + +class DiscoveryServiceTest extends TestCase { + + /** @var \PHPUnit_Framework_MockObject_MockObject | ICacheFactory */ + private $cacheFactory; + + /** @var \PHPUnit_Framework_MockObject_MockObject | IClientService */ + private $clientService; + + /** @var IDiscoveryService */ + private $discoveryService; + + public function setUp() { + parent::setUp(); + + $this->cacheFactory = $this->getMockBuilder(ICacheFactory::class)->getMock(); + $this->clientService = $this->getMockBuilder(IClientService::class)->getMock(); + + $this->discoveryService = new DiscoveryService( + $this->cacheFactory, + $this->clientService + ); + } + + /** + * @dataProvider dataTestIsSafeUrl + * + * @param string $url + * @param bool $expected + */ + public function testIsSafeUrl($url, $expected) { + $result = $this->invokePrivate($this->discoveryService, 'isSafeUrl', [$url]); + $this->assertSame($expected, $result); + } + + public function dataTestIsSafeUrl() { + return [ + ['api/ocs/v1.php/foo', true], + ['/api/ocs/v1.php/foo', true], + ['api/ocs/v1.php/foo/', true], + ['api/ocs/v1.php/foo-bar/', true], + ['api/ocs/v1:php/foo', false], + ['api/ocs/<v1.php/foo', false], + ['api/ocs/v1.php>/foo', false], + ]; + } + + /** + * @dataProvider dataTestGetEndpoints + * + * @param array $decodedServices + * @param string $service + * @param array $expected + */ + public function testGetEndpoints($decodedServices, $service, $expected) { + $result = $this->invokePrivate($this->discoveryService, 'getEndpoints', [$decodedServices, $service]); + $this->assertSame($expected, $result); + } + + public function dataTestGetEndpoints() { + return [ + [['services' => ['myService' => ['endpoints' => []]]], 'myService', []], + [['services' => ['myService' => ['endpoints' => ['foo' => '/bar']]]], 'myService', ['foo' => '/bar']], + [['services' => ['myService' => ['endpoints' => ['foo' => '/bar']]]], 'anotherService', []], + [['services' => ['myService' => ['endpoints' => ['foo' => '/bar</foo']]]], 'myService', []], + ]; + } + +} diff --git a/tests/lib/Share/ShareTest.php b/tests/lib/Share/ShareTest.php index 6b0ebd76ed7..40e88d597a4 100644 --- a/tests/lib/Share/ShareTest.php +++ b/tests/lib/Share/ShareTest.php @@ -1064,11 +1064,11 @@ class ShareTest extends \Test\TestCase { $httpHelperMock->expects($this->at(0)) ->method('post') - ->with($this->stringStartsWith('https://' . $urlHost . '/ocs/v1.php/cloud/shares'), $this->anything()) + ->with($this->stringStartsWith('https://' . $urlHost . '/ocs/v2.php/cloud/shares'), $this->anything()) ->willReturn(['success' => false, 'result' => 'Exception']); $httpHelperMock->expects($this->at(1)) ->method('post') - ->with($this->stringStartsWith('http://' . $urlHost . '/ocs/v1.php/cloud/shares'), $this->anything()) + ->with($this->stringStartsWith('http://' . $urlHost . '/ocs/v2.php/cloud/shares'), $this->anything()) ->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]); \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, $shareWith, \OCP\Constants::PERMISSION_READ); @@ -1077,11 +1077,11 @@ class ShareTest extends \Test\TestCase { $httpHelperMock->expects($this->at(0)) ->method('post') - ->with($this->stringStartsWith('https://' . $urlHost . '/ocs/v1.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything()) + ->with($this->stringStartsWith('https://' . $urlHost . '/ocs/v2.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything()) ->willReturn(['success' => false, 'result' => 'Exception']); $httpHelperMock->expects($this->at(1)) ->method('post') - ->with($this->stringStartsWith('http://' . $urlHost . '/ocs/v1.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything()) + ->with($this->stringStartsWith('http://' . $urlHost . '/ocs/v2.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything()) ->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]); \OCP\Share::unshare('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, $shareWith); @@ -1490,7 +1490,7 @@ class ShareTest extends \Test\TestCase { $httpHelperMock->expects($this->at(0)) ->method('post') - ->with($this->stringStartsWith('https://localhost/ocs/v1.php/cloud/shares'), $this->anything()) + ->with($this->stringStartsWith('https://localhost/ocs/v2.php/cloud/shares'), $this->anything()) ->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]); \OCP\Share::shareItem('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, 'foo@localhost', \OCP\Constants::PERMISSION_READ); @@ -1507,7 +1507,7 @@ class ShareTest extends \Test\TestCase { $httpHelperMock->expects($this->at(0)) ->method('post') - ->with($this->stringStartsWith('https://localhost/ocs/v1.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything()) + ->with($this->stringStartsWith('https://localhost/ocs/v2.php/cloud/shares/' . $share['id'] . '/unshare'), $this->anything()) ->willReturn(['success' => true, 'result' => json_encode(['ocs' => ['meta' => ['statuscode' => 100]]])]); \OCP\Share::unshare('test', 'test.txt', \OCP\Share::SHARE_TYPE_REMOTE, 'foo@localhost'); |