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.5KB

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