SftpTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author hkjolhede <hkjolhede@gmail.com>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Robin McCorkell <robin@mccorkell.me.uk>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. * @author Vincent Petry <pvince81@owncloud.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_External\Tests\Storage;
  29. use \OCA\Files_External\Lib\Storage\SFTP;
  30. /**
  31. * Class SftpTest
  32. *
  33. * @group DB
  34. *
  35. * @package OCA\Files_External\Tests\Storage
  36. */
  37. class SftpTest extends \Test\Files\Storage\Storage {
  38. /**
  39. * @var SFTP instance
  40. */
  41. protected $instance;
  42. private $config;
  43. protected function setUp() {
  44. parent::setUp();
  45. $id = $this->getUniqueID();
  46. $this->config = include('files_external/tests/config.sftp.php');
  47. if (!is_array($this->config) or !$this->config['run']) {
  48. $this->markTestSkipped('SFTP backend not configured');
  49. }
  50. $this->config['root'] .= '/' . $id; //make sure we have an new empty folder to work in
  51. $this->instance = new SFTP($this->config);
  52. $this->instance->mkdir('/');
  53. }
  54. protected function tearDown() {
  55. if ($this->instance) {
  56. $this->instance->rmdir('/');
  57. }
  58. parent::tearDown();
  59. }
  60. /**
  61. * @dataProvider configProvider
  62. */
  63. public function testStorageId($config, $expectedStorageId) {
  64. $instance = new SFTP($config);
  65. $this->assertEquals($expectedStorageId, $instance->getId());
  66. }
  67. public function configProvider() {
  68. return [
  69. [
  70. // no root path
  71. [
  72. 'run' => true,
  73. 'host' => 'somehost',
  74. 'user' => 'someuser',
  75. 'password' => 'somepassword',
  76. 'root' => '',
  77. ],
  78. 'sftp::someuser@somehost//',
  79. ],
  80. [
  81. // without leading nor trailing slash
  82. [
  83. 'run' => true,
  84. 'host' => 'somehost',
  85. 'user' => 'someuser',
  86. 'password' => 'somepassword',
  87. 'root' => 'remotedir/subdir',
  88. ],
  89. 'sftp::someuser@somehost//remotedir/subdir/',
  90. ],
  91. [
  92. // regular path
  93. [
  94. 'run' => true,
  95. 'host' => 'somehost',
  96. 'user' => 'someuser',
  97. 'password' => 'somepassword',
  98. 'root' => '/remotedir/subdir/',
  99. ],
  100. 'sftp::someuser@somehost//remotedir/subdir/',
  101. ],
  102. [
  103. // different port
  104. [
  105. 'run' => true,
  106. 'host' => 'somehost:8822',
  107. 'user' => 'someuser',
  108. 'password' => 'somepassword',
  109. 'root' => 'remotedir/subdir/',
  110. ],
  111. 'sftp::someuser@somehost:8822//remotedir/subdir/',
  112. ],
  113. [
  114. // ipv6 with port
  115. [
  116. 'run' => true,
  117. 'host' => 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329',
  118. 'user' => 'someuser',
  119. 'password' => 'somepassword',
  120. 'root' => 'remotedir/subdir/',
  121. ],
  122. 'sftp::someuser@FE80:0000:0000:0000:0202:B3FF:FE1E:8329//remotedir/subdir/',
  123. ],
  124. [
  125. // ipv6 without port
  126. [
  127. 'run' => true,
  128. 'host' => 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329:8822',
  129. 'user' => 'someuser',
  130. 'password' => 'somepassword',
  131. 'root' => 'remotedir/subdir/',
  132. ],
  133. 'sftp::someuser@FE80:0000:0000:0000:0202:B3FF:FE1E:8329:8822//remotedir/subdir/',
  134. ],
  135. [
  136. // collapsed ipv6 with port
  137. [
  138. 'run' => true,
  139. 'host' => 'FE80::0202:B3FF:FE1E:8329:8822',
  140. 'user' => 'someuser',
  141. 'password' => 'somepassword',
  142. 'root' => 'remotedir/subdir/',
  143. ],
  144. 'sftp::someuser@FE80::0202:B3FF:FE1E:8329:8822//remotedir/subdir/',
  145. ],
  146. ];
  147. }
  148. }