]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix SFTP storage id to be compatible with older ids
authorVincent Petry <pvince81@owncloud.com>
Wed, 15 Apr 2015 14:21:41 +0000 (16:21 +0200)
committerVincent Petry <pvince81@owncloud.com>
Wed, 15 Apr 2015 14:25:47 +0000 (16:25 +0200)
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
apps/files_external/tests/backends/sftp.php

index 392479c2f797e1c6733defca55df6ac7681a750b..c457a87a6c70e5f86ceea4d4b86954d14f41aecc 100644 (file)
@@ -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;
        }
 
        /**
index e619fd7e13dc02e73e3e0d9d66368ad3db6f2310..ae800326e584e208d1b5897d696a59a58dcbf738 100644 (file)
@@ -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/',
+                       ],
+               ];
+       }
 }