namespace OCA\DAV\Upload;
+use OCA\DAV\Connector\Sabre\Directory;
use Sabre\DAV\Exception\BadRequest;
+use Sabre\DAV\Exception\NotFound;
+use Sabre\DAV\INode;
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
/**
* @param string $sourcePath source path
* @param string $destination destination path
+ * @return bool|void
+ * @throws BadRequest
+ * @throws NotFound
*/
public function beforeMove($sourcePath, $destination) {
$this->sourceNode = $this->server->tree->getNodeForPath($sourcePath);
return;
}
+ try {
+ /** @var INode $destinationNode */
+ $destinationNode = $this->server->tree->getNodeForPath($destination);
+ if ($destinationNode instanceof Directory) {
+ throw new BadRequest("The given destination $destination is a directory.");
+ }
+ } catch (NotFound $e) {
+ // If the destination does not exist yet it's not a directory either ;)
+ }
+
$this->verifySize();
return $this->performMove($sourcePath, $destination);
}
use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Upload\ChunkingPlugin;
use OCA\DAV\Upload\FutureFile;
+use Sabre\DAV\Exception\NotFound;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
use Test\TestCase;
$this->assertNull($this->plugin->beforeMove('source', 'target'));
}
+ public function testBeforeMoveDestinationIsDirectory() {
+ $this->expectException(\Sabre\DAV\Exception\BadRequest::class);
+ $this->expectExceptionMessage('The given destination target is a directory.');
+
+ $sourceNode = $this->createMock(FutureFile::class);
+ $targetNode = $this->createMock(Directory::class);
+
+ $this->tree->expects($this->at(0))
+ ->method('getNodeForPath')
+ ->with('source')
+ ->willReturn($sourceNode);
+ $this->tree->expects($this->at(1))
+ ->method('getNodeForPath')
+ ->with('target')
+ ->willReturn($targetNode);
+ $this->response->expects($this->never())
+ ->method('setStatus');
+
+ $this->assertNull($this->plugin->beforeMove('source', 'target'));
+ }
+
public function testBeforeMoveFutureFileSkipNonExisting() {
$sourceNode = $this->createMock(FutureFile::class);
$sourceNode->expects($this->once())
->method('getSize')
->willReturn(4);
- $this->tree->expects($this->any())
+ $this->tree->expects($this->at(0))
->method('getNodeForPath')
->with('source')
->willReturn($sourceNode);
+ $this->tree->expects($this->at(1))
+ ->method('getNodeForPath')
+ ->with('target')
+ ->willThrowException(new NotFound());
$this->tree->expects($this->any())
->method('nodeExists')
->with('target')
->method('getSize')
->willReturn(4);
- $this->tree->expects($this->any())
+ $this->tree->expects($this->at(0))
->method('getNodeForPath')
->with('source')
->willReturn($sourceNode);
+ $this->tree->expects($this->at(1))
+ ->method('getNodeForPath')
+ ->with('target')
+ ->willThrowException(new NotFound());
$this->tree->expects($this->any())
->method('nodeExists')
->with('target')
$this->assertFalse($this->plugin->beforeMove('source', 'target'));
}
-
+
public function testBeforeMoveSizeIsWrong() {
$this->expectException(\Sabre\DAV\Exception\BadRequest::class);
$this->expectExceptionMessage('Chunks on server do not sum up to 4 but to 3 bytes');
->method('getSize')
->willReturn(3);
- $this->tree->expects($this->any())
+ $this->tree->expects($this->at(0))
->method('getNodeForPath')
->with('source')
->willReturn($sourceNode);
+ $this->tree->expects($this->at(1))
+ ->method('getNodeForPath')
+ ->with('target')
+ ->willThrowException(new NotFound());
$this->request->expects($this->once())
->method('getHeader')
->with('OC-Total-Length')