You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ExternalStorageTest.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. * @author Vincent Petry <vincent@nextcloud.com>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. namespace OCA\Files_Sharing\Tests;
  29. use OC\Federation\CloudId;
  30. use OCA\Files_Sharing\External\Manager as ExternalShareManager;
  31. use OCP\Http\Client\IClient;
  32. use OCP\Http\Client\IClientService;
  33. use OCP\Http\Client\IResponse;
  34. /**
  35. * Tests for the external Storage class for remote shares.
  36. *
  37. * @group DB
  38. */
  39. class ExternalStorageTest extends \Test\TestCase {
  40. public function optionsProvider() {
  41. return [
  42. [
  43. 'http://remoteserver:8080/owncloud',
  44. 'http://remoteserver:8080/owncloud/public.php/webdav/',
  45. ],
  46. // extra slash
  47. [
  48. 'http://remoteserver:8080/owncloud/',
  49. 'http://remoteserver:8080/owncloud/public.php/webdav/',
  50. ],
  51. // extra path
  52. [
  53. 'http://remoteserver:8080/myservices/owncloud/',
  54. 'http://remoteserver:8080/myservices/owncloud/public.php/webdav/',
  55. ],
  56. // root path
  57. [
  58. 'http://remoteserver:8080/',
  59. 'http://remoteserver:8080/public.php/webdav/',
  60. ],
  61. // without port
  62. [
  63. 'http://remoteserver/oc.test',
  64. 'http://remoteserver/oc.test/public.php/webdav/',
  65. ],
  66. // https
  67. [
  68. 'https://remoteserver/',
  69. 'https://remoteserver/public.php/webdav/',
  70. ],
  71. ];
  72. }
  73. private function getTestStorage($uri) {
  74. $certificateManager = \OC::$server->getCertificateManager();
  75. $httpClientService = $this->createMock(IClientService::class);
  76. $manager = $this->createMock(ExternalShareManager::class);
  77. $client = $this->createMock(IClient::class);
  78. $response = $this->createMock(IResponse::class);
  79. $client
  80. ->expects($this->any())
  81. ->method('get')
  82. ->willReturn($response);
  83. $client
  84. ->expects($this->any())
  85. ->method('post')
  86. ->willReturn($response);
  87. $httpClientService
  88. ->expects($this->any())
  89. ->method('newClient')
  90. ->willReturn($client);
  91. return new TestSharingExternalStorage(
  92. [
  93. 'cloudId' => new CloudId('testOwner@' . $uri, 'testOwner', $uri),
  94. 'remote' => $uri,
  95. 'owner' => 'testOwner',
  96. 'mountpoint' => 'remoteshare',
  97. 'token' => 'abcdef',
  98. 'password' => '',
  99. 'manager' => $manager,
  100. 'certificateManager' => $certificateManager,
  101. 'HttpClientService' => $httpClientService,
  102. ]
  103. );
  104. }
  105. /**
  106. * @dataProvider optionsProvider
  107. */
  108. public function testStorageMountOptions($inputUri, $baseUri) {
  109. $storage = $this->getTestStorage($inputUri);
  110. $this->assertEquals($baseUri, $storage->getBaseUri());
  111. }
  112. public function testIfTestReturnsTheValue() {
  113. $result = $this->getTestStorage('https://remoteserver')->test();
  114. $this->assertSame(true, $result);
  115. }
  116. }
  117. /**
  118. * Dummy subclass to make it possible to access private members
  119. */
  120. class TestSharingExternalStorage extends \OCA\Files_Sharing\External\Storage {
  121. public function getBaseUri() {
  122. return $this->createBaseUri();
  123. }
  124. public function stat($path) {
  125. if ($path === '') {
  126. return true;
  127. }
  128. return parent::stat($path);
  129. }
  130. }