1
0

ExternalStorageTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 OCP\Http\Client\IClient;
  31. use OCP\Http\Client\IClientService;
  32. use OCP\Http\Client\IResponse;
  33. /**
  34. * Tests for the external Storage class for remote shares.
  35. *
  36. * @group DB
  37. */
  38. class ExternalStorageTest extends \Test\TestCase {
  39. public function optionsProvider() {
  40. return [
  41. [
  42. 'http://remoteserver:8080/owncloud',
  43. 'http://remoteserver:8080/owncloud/public.php/webdav/',
  44. ],
  45. // extra slash
  46. [
  47. 'http://remoteserver:8080/owncloud/',
  48. 'http://remoteserver:8080/owncloud/public.php/webdav/',
  49. ],
  50. // extra path
  51. [
  52. 'http://remoteserver:8080/myservices/owncloud/',
  53. 'http://remoteserver:8080/myservices/owncloud/public.php/webdav/',
  54. ],
  55. // root path
  56. [
  57. 'http://remoteserver:8080/',
  58. 'http://remoteserver:8080/public.php/webdav/',
  59. ],
  60. // without port
  61. [
  62. 'http://remoteserver/oc.test',
  63. 'http://remoteserver/oc.test/public.php/webdav/',
  64. ],
  65. // https
  66. [
  67. 'https://remoteserver/',
  68. 'https://remoteserver/public.php/webdav/',
  69. ],
  70. ];
  71. }
  72. private function getTestStorage($uri) {
  73. $certificateManager = \OC::$server->getCertificateManager();
  74. $httpClientService = $this->createMock(IClientService::class);
  75. $client = $this->createMock(IClient::class);
  76. $response = $this->createMock(IResponse::class);
  77. $client
  78. ->expects($this->any())
  79. ->method('get')
  80. ->willReturn($response);
  81. $client
  82. ->expects($this->any())
  83. ->method('post')
  84. ->willReturn($response);
  85. $httpClientService
  86. ->expects($this->any())
  87. ->method('newClient')
  88. ->willReturn($client);
  89. return new TestSharingExternalStorage(
  90. [
  91. 'cloudId' => new CloudId('testOwner@' . $uri, 'testOwner', $uri),
  92. 'remote' => $uri,
  93. 'owner' => 'testOwner',
  94. 'mountpoint' => 'remoteshare',
  95. 'token' => 'abcdef',
  96. 'password' => '',
  97. 'manager' => null,
  98. 'certificateManager' => $certificateManager,
  99. 'HttpClientService' => $httpClientService,
  100. ]
  101. );
  102. }
  103. /**
  104. * @dataProvider optionsProvider
  105. */
  106. public function testStorageMountOptions($inputUri, $baseUri) {
  107. $storage = $this->getTestStorage($inputUri);
  108. $this->assertEquals($baseUri, $storage->getBaseUri());
  109. }
  110. public function testIfTestReturnsTheValue() {
  111. $result = $this->getTestStorage('https://remoteserver')->test();
  112. $this->assertSame(true, $result);
  113. }
  114. }
  115. /**
  116. * Dummy subclass to make it possible to access private members
  117. */
  118. class TestSharingExternalStorage extends \OCA\Files_Sharing\External\Storage {
  119. public function getBaseUri() {
  120. return $this->createBaseUri();
  121. }
  122. public function stat($path) {
  123. if ($path === '') {
  124. return true;
  125. }
  126. return parent::stat($path);
  127. }
  128. }