|
|
@@ -27,6 +27,42 @@ |
|
|
|
namespace OCA\DAV\Tests\Unit\Connector\Sabre; |
|
|
|
|
|
|
|
use OCP\Files\ForbiddenException; |
|
|
|
use OC\Files\FileInfo; |
|
|
|
use OCA\DAV\Connector\Sabre\Directory; |
|
|
|
|
|
|
|
class TestDoubleFileView extends \OC\Files\View { |
|
|
|
|
|
|
|
private $updatables; |
|
|
|
private $deletables; |
|
|
|
private $canRename; |
|
|
|
|
|
|
|
public function __construct($updatables, $deletables, $canRename = true) { |
|
|
|
$this->updatables = $updatables; |
|
|
|
$this->deletables = $deletables; |
|
|
|
$this->canRename = $canRename; |
|
|
|
} |
|
|
|
|
|
|
|
public function isUpdatable($path) { |
|
|
|
return $this->updatables[$path]; |
|
|
|
} |
|
|
|
|
|
|
|
public function isCreatable($path) { |
|
|
|
return $this->updatables[$path]; |
|
|
|
} |
|
|
|
|
|
|
|
public function isDeletable($path) { |
|
|
|
return $this->deletables[$path]; |
|
|
|
} |
|
|
|
|
|
|
|
public function rename($path1, $path2) { |
|
|
|
return $this->canRename; |
|
|
|
} |
|
|
|
|
|
|
|
public function getRelativePath($path) { |
|
|
|
return $path; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @group DB |
|
|
@@ -58,7 +94,7 @@ class DirectoryTest extends \Test\TestCase { |
|
|
|
->method('getPath') |
|
|
|
->will($this->returnValue($path)); |
|
|
|
|
|
|
|
return new \OCA\DAV\Connector\Sabre\Directory($this->view, $this->info); |
|
|
|
return new Directory($this->view, $this->info); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -172,7 +208,7 @@ class DirectoryTest extends \Test\TestCase { |
|
|
|
->method('getRelativePath') |
|
|
|
->will($this->returnValue('')); |
|
|
|
|
|
|
|
$dir = new \OCA\DAV\Connector\Sabre\Directory($this->view, $this->info); |
|
|
|
$dir = new Directory($this->view, $this->info); |
|
|
|
$nodes = $dir->getChildren(); |
|
|
|
|
|
|
|
$this->assertEquals(2, count($nodes)); |
|
|
@@ -182,6 +218,30 @@ class DirectoryTest extends \Test\TestCase { |
|
|
|
$dir->getChildren(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @expectedException \Sabre\DAV\Exception\Forbidden |
|
|
|
*/ |
|
|
|
public function testGetChildrenNoPermission() { |
|
|
|
$this->info->expects($this->any()) |
|
|
|
->method('isReadable') |
|
|
|
->will($this->returnValue(false)); |
|
|
|
|
|
|
|
$dir = new Directory($this->view, $this->info); |
|
|
|
$dir->getChildren(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @expectedException \Sabre\DAV\Exception\NotFound |
|
|
|
*/ |
|
|
|
public function testGetChildNoPermission() { |
|
|
|
$this->info->expects($this->any()) |
|
|
|
->method('isReadable') |
|
|
|
->will($this->returnValue(false)); |
|
|
|
|
|
|
|
$dir = new Directory($this->view, $this->info); |
|
|
|
$dir->getChild('test'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @expectedException \Sabre\DAV\Exception\ServiceUnavailable |
|
|
|
*/ |
|
|
@@ -190,7 +250,7 @@ class DirectoryTest extends \Test\TestCase { |
|
|
|
->method('getFileInfo') |
|
|
|
->willThrowException(new \OCP\Files\StorageNotAvailableException()); |
|
|
|
|
|
|
|
$dir = new \OCA\DAV\Connector\Sabre\Directory($this->view, $this->info); |
|
|
|
$dir = new Directory($this->view, $this->info); |
|
|
|
$dir->getChild('.'); |
|
|
|
} |
|
|
|
|
|
|
@@ -204,7 +264,7 @@ class DirectoryTest extends \Test\TestCase { |
|
|
|
$this->view->expects($this->never()) |
|
|
|
->method('getFileInfo'); |
|
|
|
|
|
|
|
$dir = new \OCA\DAV\Connector\Sabre\Directory($this->view, $this->info); |
|
|
|
$dir = new Directory($this->view, $this->info); |
|
|
|
$dir->getChild('.'); |
|
|
|
} |
|
|
|
|
|
|
@@ -235,7 +295,7 @@ class DirectoryTest extends \Test\TestCase { |
|
|
|
->method('getStorage') |
|
|
|
->will($this->returnValue($storage)); |
|
|
|
|
|
|
|
$dir = new \OCA\DAV\Connector\Sabre\Directory($this->view, $this->info); |
|
|
|
$dir = new Directory($this->view, $this->info); |
|
|
|
$this->assertEquals([200, -3], $dir->getQuotaInfo()); //200 used, unlimited |
|
|
|
} |
|
|
|
|
|
|
@@ -267,7 +327,105 @@ class DirectoryTest extends \Test\TestCase { |
|
|
|
->method('getStorage') |
|
|
|
->will($this->returnValue($storage)); |
|
|
|
|
|
|
|
$dir = new \OCA\DAV\Connector\Sabre\Directory($this->view, $this->info); |
|
|
|
$dir = new Directory($this->view, $this->info); |
|
|
|
$this->assertEquals([200, 800], $dir->getQuotaInfo()); //200 used, 800 free |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @dataProvider moveFailedProvider |
|
|
|
* @expectedException \Sabre\DAV\Exception\Forbidden |
|
|
|
*/ |
|
|
|
public function testMoveFailed($source, $destination, $updatables, $deletables) { |
|
|
|
$this->moveTest($source, $destination, $updatables, $deletables); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @dataProvider moveSuccessProvider |
|
|
|
*/ |
|
|
|
public function testMoveSuccess($source, $destination, $updatables, $deletables) { |
|
|
|
$this->moveTest($source, $destination, $updatables, $deletables); |
|
|
|
$this->assertTrue(true); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @dataProvider moveFailedInvalidCharsProvider |
|
|
|
* @expectedException \OCA\DAV\Connector\Sabre\Exception\InvalidPath |
|
|
|
*/ |
|
|
|
public function testMoveFailedInvalidChars($source, $destination, $updatables, $deletables) { |
|
|
|
$this->moveTest($source, $destination, $updatables, $deletables); |
|
|
|
} |
|
|
|
|
|
|
|
public function moveFailedInvalidCharsProvider() { |
|
|
|
return [ |
|
|
|
['a/b', 'a/*', ['a' => true, 'a/b' => true, 'a/c*' => false], []], |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function moveFailedProvider() { |
|
|
|
return [ |
|
|
|
['a/b', 'a/c', ['a' => false, 'a/b' => false, 'a/c' => false], []], |
|
|
|
['a/b', 'b/b', ['a' => false, 'a/b' => false, 'b' => false, 'b/b' => false], []], |
|
|
|
['a/b', 'b/b', ['a' => false, 'a/b' => true, 'b' => false, 'b/b' => false], []], |
|
|
|
['a/b', 'b/b', ['a' => true, 'a/b' => true, 'b' => false, 'b/b' => false], []], |
|
|
|
['a/b', 'b/b', ['a' => true, 'a/b' => true, 'b' => true, 'b/b' => false], ['a/b' => false]], |
|
|
|
['a/b', 'a/c', ['a' => false, 'a/b' => true, 'a/c' => false], []], |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function moveSuccessProvider() { |
|
|
|
return [ |
|
|
|
['a/b', 'b/b', ['a' => true, 'a/b' => true, 'b' => true, 'b/b' => false], ['a/b' => true]], |
|
|
|
// older files with special chars can still be renamed to valid names |
|
|
|
['a/b*', 'b/b', ['a' => true, 'a/b*' => true, 'b' => true, 'b/b' => false], ['a/b*' => true]], |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param $source |
|
|
|
* @param $destination |
|
|
|
* @param $updatables |
|
|
|
*/ |
|
|
|
private function moveTest($source, $destination, $updatables, $deletables) { |
|
|
|
$view = new TestDoubleFileView($updatables, $deletables); |
|
|
|
|
|
|
|
$sourceInfo = new FileInfo($source, null, null, [], null); |
|
|
|
$targetInfo = new FileInfo(dirname($destination), null, null, [], null); |
|
|
|
|
|
|
|
$sourceNode = new Directory($view, $sourceInfo); |
|
|
|
$targetNode = $this->getMockBuilder(Directory::class) |
|
|
|
->setMethods(['childExists']) |
|
|
|
->setConstructorArgs([$view, $targetInfo]) |
|
|
|
->getMock(); |
|
|
|
$targetNode->expects($this->any())->method('childExists') |
|
|
|
->with(basename($destination)) |
|
|
|
->willReturn(false); |
|
|
|
$this->assertTrue($targetNode->moveInto(basename($destination), $source, $sourceNode)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @expectedException \Sabre\DAV\Exception\Forbidden |
|
|
|
* @expectedExceptionMessage Could not copy directory b, target exists |
|
|
|
*/ |
|
|
|
public function testFailingMove() { |
|
|
|
$source = 'a/b'; |
|
|
|
$destination = 'c/b'; |
|
|
|
$updatables = ['a' => true, 'a/b' => true, 'b' => true, 'c/b' => false]; |
|
|
|
$deletables = ['a/b' => true]; |
|
|
|
|
|
|
|
$view = new TestDoubleFileView($updatables, $deletables); |
|
|
|
|
|
|
|
$sourceInfo = new FileInfo($source, null, null, [], null); |
|
|
|
$targetInfo = new FileInfo(dirname($destination), null, null, [], null); |
|
|
|
|
|
|
|
$sourceNode = new Directory($view, $sourceInfo); |
|
|
|
$targetNode = $this->getMockBuilder(Directory::class) |
|
|
|
->setMethods(['childExists']) |
|
|
|
->setConstructorArgs([$view, $targetInfo]) |
|
|
|
->getMock(); |
|
|
|
$targetNode->expects($this->once())->method('childExists') |
|
|
|
->with(basename($destination)) |
|
|
|
->willReturn(true); |
|
|
|
|
|
|
|
$targetNode->moveInto(basename($destination), $source, $sourceNode); |
|
|
|
} |
|
|
|
} |