From a6c5d65fd621178c8d3899d5a43295edcc4840a2 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Wed, 15 Apr 2015 16:21:41 +0200 Subject: [PATCH 1/2] Fix SFTP storage id to be compatible with older ids Remove port from SFTP storage id if it is 22. This will prevent recreating a different storage entry due to id mismatch after upgrade. --- apps/files_external/lib/sftp.php | 10 +++- apps/files_external/tests/backends/sftp.php | 57 +++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/apps/files_external/lib/sftp.php b/apps/files_external/lib/sftp.php index 392479c2f7..c457a87a6c 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 e619fd7e13..ae800326e5 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()); + } + + 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/', + ], + ]; + } } From 4a5c3eea42ffdb0823fcdb8dad302edc9495d417 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 15 Apr 2015 17:40:07 +0200 Subject: [PATCH 2/2] Add visibility for method --- apps/files_external/tests/backends/sftp.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/files_external/tests/backends/sftp.php b/apps/files_external/tests/backends/sftp.php index ae800326e5..29461c3abc 100644 --- a/apps/files_external/tests/backends/sftp.php +++ b/apps/files_external/tests/backends/sftp.php @@ -56,7 +56,7 @@ class SFTP extends Storage { $this->assertEquals($expectedStorageId, $instance->getId()); } - function configProvider() { + public function configProvider() { return [ [ // no root path