fix(dav): Verify target path in `setName` instead of source path

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
pull/46538/head
Ferdinand Thiessen 10 months ago
parent f4ede27cdb
commit 322b3946d9
No known key found for this signature in database
GPG Key ID: 45FAE7268762B400
  1. 13
      apps/dav/lib/Connector/Sabre/Node.php
  2. 4
      apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
  3. 4
      tests/lib/Files/FilenameValidatorTest.php

@ -122,11 +122,11 @@ abstract class Node implements \Sabre\DAV\INode {
[$parentPath,] = \Sabre\Uri\split($this->path);
[, $newName] = \Sabre\Uri\split($name);
$newPath = $parentPath . '/' . $newName;
// verify path of the target
$this->verifyPath();
$this->verifyPath($newPath);
$newPath = $parentPath . '/' . $newName;
if (!$this->fileView->rename($this->path, $newPath)) {
throw new \Sabre\DAV\Exception('Failed to rename '. $this->path . ' to ' . $newPath);
@ -355,10 +355,13 @@ abstract class Node implements \Sabre\DAV\INode {
return $this->info->getOwner();
}
protected function verifyPath() {
protected function verifyPath(?string $path = null): void {
try {
$fileName = basename($this->info->getPath());
$this->fileView->verifyPath($this->path, $fileName);
$path = $path ?? $this->info->getPath();
$this->fileView->verifyPath(
dirname($path),
basename($path),
);
} catch (\OCP\Files\InvalidPathException $ex) {
throw new InvalidPath($ex->getMessage());
}

@ -397,7 +397,7 @@ class DirectoryTest extends \Test\TestCase {
public function moveFailedInvalidCharsProvider() {
return [
['a/b', 'a/*', ['a' => true, 'a/b' => true, 'a/c*' => false], []],
['a/valid', "a/i\nvalid", ['a' => true, 'a/valid' => true, 'a/c*' => false], []],
];
}
@ -463,7 +463,7 @@ class DirectoryTest extends \Test\TestCase {
$sourceNode = new Directory($view, $sourceInfo);
$targetNode = $this->getMockBuilder(Directory::class)
->setMethods(['childExists'])
->onlyMethods(['childExists'])
->setConstructorArgs([$view, $targetInfo])
->getMock();
$targetNode->expects($this->once())->method('childExists')

@ -128,7 +128,7 @@ class FilenameValidatorTest extends TestCase {
'a: b.txt', ['.htaccess'], [], [], [], null
],
'forbidden name in the middle is ok' => [
'a.htaccess.txt', ['.htaccess'], [], [], null
'a.htaccess.txt', ['.htaccess'], [], [], [], null
],
'valid name with some more parameters' => [
'a: b.txt', ['.htaccess'], [], ['exe'], ['~'], null
@ -169,7 +169,7 @@ class FilenameValidatorTest extends TestCase {
'..', [], [], [], [], InvalidDirectoryException::class
],
'weird but valid tripple dot name' => [
'...', [], [], [], null // is valid
'...', [], [], [], [], null // is valid
],
'too long filename "."' => [
str_repeat('a', 251), [], [], [], [], FileNameTooLongException::class

Loading…
Cancel
Save