Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DiscoveryServiceTest.php 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Bjoern Schiessle <bjoern@schiessle.org>
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. namespace Test\OCS;
  22. use OC\OCS\DiscoveryService;
  23. use OCP\Http\Client\IClientService;
  24. use OCP\ICacheFactory;
  25. use OCP\OCS\IDiscoveryService;
  26. use Test\TestCase;
  27. class DiscoveryServiceTest extends TestCase {
  28. /** @var \PHPUnit\Framework\MockObject\MockObject | ICacheFactory */
  29. private $cacheFactory;
  30. /** @var \PHPUnit\Framework\MockObject\MockObject | IClientService */
  31. private $clientService;
  32. /** @var IDiscoveryService */
  33. private $discoveryService;
  34. protected function setUp(): void {
  35. parent::setUp();
  36. $this->cacheFactory = $this->getMockBuilder(ICacheFactory::class)->getMock();
  37. $this->clientService = $this->getMockBuilder(IClientService::class)->getMock();
  38. $this->discoveryService = new DiscoveryService(
  39. $this->cacheFactory,
  40. $this->clientService
  41. );
  42. }
  43. /**
  44. * @dataProvider dataTestIsSafeUrl
  45. *
  46. * @param string $url
  47. * @param bool $expected
  48. */
  49. public function testIsSafeUrl($url, $expected) {
  50. $result = $this->invokePrivate($this->discoveryService, 'isSafeUrl', [$url]);
  51. $this->assertSame($expected, $result);
  52. }
  53. public function dataTestIsSafeUrl() {
  54. return [
  55. ['api/ocs/v1.php/foo', true],
  56. ['/api/ocs/v1.php/foo', true],
  57. ['api/ocs/v1.php/foo/', true],
  58. ['api/ocs/v1.php/foo-bar/', true],
  59. ['api/ocs/v1:php/foo', false],
  60. ['api/ocs/<v1.php/foo', false],
  61. ['api/ocs/v1.php>/foo', false],
  62. ];
  63. }
  64. /**
  65. * @dataProvider dataTestGetEndpoints
  66. *
  67. * @param array $decodedServices
  68. * @param string $service
  69. * @param array $expected
  70. */
  71. public function testGetEndpoints($decodedServices, $service, $expected) {
  72. $result = $this->invokePrivate($this->discoveryService, 'getEndpoints', [$decodedServices, $service]);
  73. $this->assertSame($expected, $result);
  74. }
  75. public function dataTestGetEndpoints() {
  76. return [
  77. [['services' => ['myService' => ['endpoints' => []]]], 'myService', []],
  78. [['services' => ['myService' => ['endpoints' => ['foo' => '/bar']]]], 'myService', ['foo' => '/bar']],
  79. [['services' => ['myService' => ['endpoints' => ['foo' => '/bar']]]], 'anotherService', []],
  80. [['services' => ['myService' => ['endpoints' => ['foo' => '/bar</foo']]]], 'myService', []],
  81. ];
  82. }
  83. }