Merge pull request #15644 from owncloud/sftp-defaultport-storageid

Fix SFTP storage id to be compatible with older ids
This commit is contained in:
Morris Jobke 2015-04-15 17:40:18 +02:00
commit 512558c827
2 changed files with 66 additions and 1 deletions

View 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;
}
/**

View 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());
}
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/',
],
];
}
}