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.

sftp.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * @author hkjolhede <hkjolhede@gmail.com>
  4. * @author Joas Schilling <nickvergessen@owncloud.com>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin Appelman <icewind@owncloud.com>
  7. * @author Vincent Petry <pvince81@owncloud.com>
  8. *
  9. * @copyright Copyright (c) 2015, ownCloud, Inc.
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace Test\Files\Storage;
  26. class SFTP extends Storage {
  27. private $config;
  28. protected function setUp() {
  29. parent::setUp();
  30. $id = $this->getUniqueID();
  31. $this->config = include('files_external/tests/config.sftp.php');
  32. if (!is_array($this->config) or !$this->config['run']) {
  33. $this->markTestSkipped('SFTP backend not configured');
  34. }
  35. $this->config['root'] .= '/' . $id; //make sure we have an new empty folder to work in
  36. $this->instance = new \OC\Files\Storage\SFTP($this->config);
  37. $this->instance->mkdir('/');
  38. }
  39. protected function tearDown() {
  40. if ($this->instance) {
  41. $this->instance->rmdir('/');
  42. }
  43. parent::tearDown();
  44. }
  45. /**
  46. * @dataProvider configProvider
  47. */
  48. public function testStorageId($config, $expectedStorageId) {
  49. $instance = new \OC\Files\Storage\SFTP($config);
  50. $this->assertEquals($expectedStorageId, $instance->getId());
  51. }
  52. public function configProvider() {
  53. return [
  54. [
  55. // no root path
  56. [
  57. 'run' => true,
  58. 'host' => 'somehost',
  59. 'user' => 'someuser',
  60. 'password' => 'somepassword',
  61. 'root' => '',
  62. ],
  63. 'sftp::someuser@somehost//',
  64. ],
  65. [
  66. // without leading nor trailing slash
  67. [
  68. 'run' => true,
  69. 'host' => 'somehost',
  70. 'user' => 'someuser',
  71. 'password' => 'somepassword',
  72. 'root' => 'remotedir/subdir',
  73. ],
  74. 'sftp::someuser@somehost//remotedir/subdir/',
  75. ],
  76. [
  77. // regular path
  78. [
  79. 'run' => true,
  80. 'host' => 'somehost',
  81. 'user' => 'someuser',
  82. 'password' => 'somepassword',
  83. 'root' => '/remotedir/subdir/',
  84. ],
  85. 'sftp::someuser@somehost//remotedir/subdir/',
  86. ],
  87. [
  88. // different port
  89. [
  90. 'run' => true,
  91. 'host' => 'somehost:8822',
  92. 'user' => 'someuser',
  93. 'password' => 'somepassword',
  94. 'root' => 'remotedir/subdir/',
  95. ],
  96. 'sftp::someuser@somehost:8822//remotedir/subdir/',
  97. ],
  98. ];
  99. }
  100. }