diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-04-15 17:40:18 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-04-15 17:40:18 +0200 |
commit | 512558c8277541c24a20b7e16bc1e94780b47ae1 (patch) | |
tree | 09df8ffc73b4d583827cd96a4ee51e7a99848935 | |
parent | 9e46b7175d0395261c2127c8cec688fc137cc120 (diff) | |
parent | 4a5c3eea42ffdb0823fcdb8dad302edc9495d417 (diff) | |
download | nextcloud-server-512558c8277541c24a20b7e16bc1e94780b47ae1.tar.gz nextcloud-server-512558c8277541c24a20b7e16bc1e94780b47ae1.zip |
Merge pull request #15644 from owncloud/sftp-defaultport-storageid
Fix SFTP storage id to be compatible with older ids
-rw-r--r-- | apps/files_external/lib/sftp.php | 10 | ||||
-rw-r--r-- | apps/files_external/tests/backends/sftp.php | 57 |
2 files changed, 66 insertions, 1 deletions
diff --git a/apps/files_external/lib/sftp.php b/apps/files_external/lib/sftp.php index 392479c2f79..c457a87a6c7 100644 --- a/apps/files_external/lib/sftp.php +++ b/apps/files_external/lib/sftp.php @@ -133,7 +133,15 @@ class SFTP extends \OC\Files\Storage\Common { * {@inheritdoc} */ public function getId(){ - return 'sftp::' . $this->user . '@' . $this->host . ':' . $this->port . '/' . $this->root; + $id = 'sftp::' . $this->user . '@' . $this->host; + if ($this->port !== 22) { + $id .= ':' . $this->port; + } + // note: this will double the root slash, + // we should not change it to keep compatible with + // old storage ids + $id .= '/' . $this->root; + return $id; } /** diff --git a/apps/files_external/tests/backends/sftp.php b/apps/files_external/tests/backends/sftp.php index e619fd7e13d..29461c3abcc 100644 --- a/apps/files_external/tests/backends/sftp.php +++ b/apps/files_external/tests/backends/sftp.php @@ -47,4 +47,61 @@ class SFTP extends Storage { parent::tearDown(); } + + /** + * @dataProvider configProvider + */ + public function testStorageId($config, $expectedStorageId) { + $instance = new \OC\Files\Storage\SFTP($config); + $this->assertEquals($expectedStorageId, $instance->getId()); + } + + public function configProvider() { + return [ + [ + // no root path + [ + 'run' => true, + 'host' => 'somehost', + 'user' => 'someuser', + 'password' => 'somepassword', + 'root' => '', + ], + 'sftp::someuser@somehost//', + ], + [ + // without leading nor trailing slash + [ + 'run' => true, + 'host' => 'somehost', + 'user' => 'someuser', + 'password' => 'somepassword', + 'root' => 'remotedir/subdir', + ], + 'sftp::someuser@somehost//remotedir/subdir/', + ], + [ + // regular path + [ + 'run' => true, + 'host' => 'somehost', + 'user' => 'someuser', + 'password' => 'somepassword', + 'root' => '/remotedir/subdir/', + ], + 'sftp::someuser@somehost//remotedir/subdir/', + ], + [ + // different port + [ + 'run' => true, + 'host' => 'somehost:8822', + 'user' => 'someuser', + 'password' => 'somepassword', + 'root' => 'remotedir/subdir/', + ], + 'sftp::someuser@somehost:8822//remotedir/subdir/', + ], + ]; + } } |