diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-03-10 11:02:47 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-03-10 11:02:47 +0100 |
commit | 6dc59019af78f580f2854a98e5f1d59649d510db (patch) | |
tree | 6d1e957d7249445c5bbb87b57c5ca4a85af6bf5f /tests | |
parent | 214fa44400be2b3f68566f54feff389f20f3a445 (diff) | |
parent | 3623f14e73046a51953872fe49853bc200ac736d (diff) | |
download | nextcloud-server-6dc59019af78f580f2854a98e5f1d59649d510db.tar.gz nextcloud-server-6dc59019af78f580f2854a98e5f1d59649d510db.zip |
Merge pull request #14346 from owncloud/storage-based-path-validation
adding storage specific filename verification
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/connector/sabre/directory.php | 2 | ||||
-rw-r--r-- | tests/lib/connector/sabre/exception/invalidpathtest.php | 44 | ||||
-rw-r--r-- | tests/lib/connector/sabre/file.php | 19 | ||||
-rw-r--r-- | tests/lib/connector/sabre/node.php | 3 | ||||
-rw-r--r-- | tests/lib/connector/sabre/objecttree.php | 22 | ||||
-rw-r--r-- | tests/lib/files/pathverificationtest.php | 223 |
6 files changed, 292 insertions, 21 deletions
diff --git a/tests/lib/connector/sabre/directory.php b/tests/lib/connector/sabre/directory.php index e7fbd1d27b6..2550f2bcef1 100644 --- a/tests/lib/connector/sabre/directory.php +++ b/tests/lib/connector/sabre/directory.php @@ -8,7 +8,9 @@ */ class Test_OC_Connector_Sabre_Directory extends \Test\TestCase { + /** @var OC\Files\View | PHPUnit_Framework_MockObject_MockObject */ private $view; + /** @var OC\Files\FileInfo | PHPUnit_Framework_MockObject_MockObject */ private $info; protected function setUp() { diff --git a/tests/lib/connector/sabre/exception/invalidpathtest.php b/tests/lib/connector/sabre/exception/invalidpathtest.php new file mode 100644 index 00000000000..d2d58887d62 --- /dev/null +++ b/tests/lib/connector/sabre/exception/invalidpathtest.php @@ -0,0 +1,44 @@ +<?php + +namespace Test\Connector\Sabre\Exception; + +use OC\Connector\Sabre\Exception\InvalidPath; + +/** + * Copyright (c) 2015 Thomas Müller <deepdiver@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +class InvalidPathTest extends \Test\TestCase { + + public function testSerialization() { + + // create xml doc + $DOM = new \DOMDocument('1.0','utf-8'); + $DOM->formatOutput = true; + $error = $DOM->createElementNS('DAV:','d:error'); + $error->setAttribute('xmlns:s', \Sabre\DAV\Server::NS_SABREDAV); + $DOM->appendChild($error); + + // serialize the exception + $message = "1234567890"; + $retry = false; + $expectedXml = <<<EOD +<?xml version="1.0" encoding="utf-8"?> +<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:o="http://owncloud.org/ns"> + <o:retry xmlns:o="o:">false</o:retry> + <o:reason xmlns:o="o:">1234567890</o:reason> +</d:error> + +EOD; + + $ex = new InvalidPath($message, $retry); + $server = $this->getMock('Sabre\DAV\Server'); + $ex->serialize($server, $error); + + // assert + $xml = $DOM->saveXML(); + $this->assertEquals($expectedXml, $xml); + } +} diff --git a/tests/lib/connector/sabre/file.php b/tests/lib/connector/sabre/file.php index 2ef5fd794be..f2812e390ac 100644 --- a/tests/lib/connector/sabre/file.php +++ b/tests/lib/connector/sabre/file.php @@ -6,7 +6,12 @@ * See the COPYING-README file. */ -class Test_OC_Connector_Sabre_File extends \Test\TestCase { +namespace Test\Connector\Sabre; + + +use OC_Connector_Sabre_File; + +class File extends \Test\TestCase { /** * @expectedException \Sabre\DAV\Exception @@ -93,7 +98,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase { } /** - * @expectedException \Sabre\DAV\Exception\BadRequest + * @expectedException \OC\Connector\Sabre\Exception\InvalidPath */ public function testSimplePutInvalidChars() { // setup @@ -104,9 +109,9 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase { $view->expects($this->any()) ->method('getRelativePath') - ->will($this->returnValue('/super*star.txt')); + ->will($this->returnValue('/*')); - $info = new \OC\Files\FileInfo('/super*star.txt', null, null, array( + $info = new \OC\Files\FileInfo('/*', null, null, array( 'permissions' => \OCP\Constants::PERMISSION_ALL ), null); $file = new \OC\Connector\Sabre\File($view, $info); @@ -117,7 +122,7 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase { /** * Test setting name with setName() with invalid chars - * @expectedException \Sabre\DAV\Exception\BadRequest + * @expectedException \OC\Connector\Sabre\Exception\InvalidPath */ public function testSetNameInvalidChars() { // setup @@ -125,9 +130,9 @@ class Test_OC_Connector_Sabre_File extends \Test\TestCase { $view->expects($this->any()) ->method('getRelativePath') - ->will($this->returnValue('/super*star.txt')); + ->will($this->returnValue('/*')); - $info = new \OC\Files\FileInfo('/super*star.txt', null, null, array( + $info = new \OC\Files\FileInfo('/*', null, null, array( 'permissions' => \OCP\Constants::PERMISSION_ALL ), null); $file = new \OC\Connector\Sabre\File($view, $info); diff --git a/tests/lib/connector/sabre/node.php b/tests/lib/connector/sabre/node.php index e1ae05b2170..3b3a6107813 100644 --- a/tests/lib/connector/sabre/node.php +++ b/tests/lib/connector/sabre/node.php @@ -9,9 +9,6 @@ namespace Test\Connector\Sabre; -use OC\Files\FileInfo; -use OC\Files\View; - class Node extends \Test\TestCase { public function davPermissionsProvider() { return array( diff --git a/tests/lib/connector/sabre/objecttree.php b/tests/lib/connector/sabre/objecttree.php index 0709aa89c63..d2702027b0d 100644 --- a/tests/lib/connector/sabre/objecttree.php +++ b/tests/lib/connector/sabre/objecttree.php @@ -47,29 +47,29 @@ class ObjectTree extends \Test\TestCase { * @dataProvider moveFailedProvider * @expectedException \Sabre\DAV\Exception\Forbidden */ - public function testMoveFailed($source, $dest, $updatables, $deletables) { - $this->moveTest($source, $dest, $updatables, $deletables); + public function testMoveFailed($source, $destination, $updatables, $deletables) { + $this->moveTest($source, $destination, $updatables, $deletables); } /** * @dataProvider moveSuccessProvider */ - public function testMoveSuccess($source, $dest, $updatables, $deletables) { - $this->moveTest($source, $dest, $updatables, $deletables); + public function testMoveSuccess($source, $destination, $updatables, $deletables) { + $this->moveTest($source, $destination, $updatables, $deletables); $this->assertTrue(true); } /** * @dataProvider moveFailedInvalidCharsProvider - * @expectedException \Sabre\DAV\Exception\BadRequest + * @expectedException \OC\Connector\Sabre\Exception\InvalidPath */ - public function testMoveFailedInvalidChars($source, $dest, $updatables, $deletables) { - $this->moveTest($source, $dest, $updatables, $deletables); + public function testMoveFailedInvalidChars($source, $destination, $updatables, $deletables) { + $this->moveTest($source, $destination, $updatables, $deletables); } function moveFailedInvalidCharsProvider() { return array( - array('a/b', 'a/c*', array('a' => false, 'a/b' => true, 'a/c*' => false), array()), + array('a/b', 'a/*', array('a' => false, 'a/b' => true, 'a/c*' => false), array()), ); } @@ -94,10 +94,10 @@ class ObjectTree extends \Test\TestCase { /** * @param $source - * @param $dest + * @param $destination * @param $updatables */ - private function moveTest($source, $dest, $updatables, $deletables) { + private function moveTest($source, $destination, $updatables, $deletables) { $view = new TestDoubleFileView($updatables, $deletables); $info = new FileInfo('', null, null, array(), null); @@ -115,7 +115,7 @@ class ObjectTree extends \Test\TestCase { /** @var $objectTree \OC\Connector\Sabre\ObjectTree */ $mountManager = \OC\Files\Filesystem::getMountManager(); $objectTree->init($rootDir, $view, $mountManager); - $objectTree->move($source, $dest); + $objectTree->move($source, $destination); } /** diff --git a/tests/lib/files/pathverificationtest.php b/tests/lib/files/pathverificationtest.php new file mode 100644 index 00000000000..1a802a48f57 --- /dev/null +++ b/tests/lib/files/pathverificationtest.php @@ -0,0 +1,223 @@ +<?php +/** + * Copyright (c) 2015 Thomas Müller <deepdiver@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. */ + +namespace Test\Files; + +use OC\Files\Storage\Local; +use OC\Files\View; + +class PathVerification extends \Test\TestCase { + + /** + * @var \OC\Files\View + */ + private $view; + + protected function setUp() { + parent::setUp(); + $this->view = new View(); + } + + /** + * @dataProvider providesEmptyFiles + * @expectedException \OCP\Files\InvalidPathException + * @expectedExceptionMessage Empty filename is not allowed + */ + public function testPathVerificationEmptyFileName($fileName) { + $this->view->verifyPath('', $fileName); + } + + public function providesEmptyFiles() { + return [ + [''], + [' '], + ]; + } + + /** + * @dataProvider providesDotFiles + * @expectedException \OCP\Files\InvalidPathException + * @expectedExceptionMessage Dot files are not allowed + */ + public function testPathVerificationDotFiles($fileName) { + $this->view->verifyPath('', $fileName); + } + + public function providesDotFiles() { + return [ + ['.'], + ['..'], + [' .'], + [' ..'], + ['. '], + ['.. '], + [' . '], + [' .. '], + ]; + } + + /** + * @dataProvider providesAstralPlane + * @expectedException \OCP\Files\InvalidPathException + * @expectedExceptionMessage 4-byte characters are not supported in file names + */ + public function testPathVerificationAstralPlane($fileName) { + $this->view->verifyPath('', $fileName); + } + + public function providesAstralPlane() { + return [ + // this is the monkey emoji - http://en.wikipedia.org/w/index.php?title=%F0%9F%90%B5&redirect=no + ['🐵'], + ]; + } + + /** + * @dataProvider providesInvalidCharsWindows + * @expectedException \OCP\Files\InvalidCharacterInPathException + */ + public function testPathVerificationInvalidCharsWindows($fileName) { + $storage = new Local(['datadir' => '']); + + $fileName = " 123{$fileName}456 "; + \Test_Helper::invokePrivate($storage, 'verifyWindowsPath', [$fileName]); + } + + public function providesInvalidCharsWindows() { + return [ + [\chr(0)], + [\chr(1)], + [\chr(2)], + [\chr(3)], + [\chr(4)], + [\chr(5)], + [\chr(6)], + [\chr(7)], + [\chr(8)], + [\chr(9)], + [\chr(10)], + [\chr(11)], + [\chr(12)], + [\chr(13)], + [\chr(14)], + [\chr(15)], + [\chr(16)], + [\chr(17)], + [\chr(18)], + [\chr(19)], + [\chr(20)], + [\chr(21)], + [\chr(22)], + [\chr(23)], + [\chr(24)], + [\chr(25)], + [\chr(26)], + [\chr(27)], + [\chr(28)], + [\chr(29)], + [\chr(30)], + [\chr(31)], + ['<'], + ['>'], + [':'], + ['"'], + ['/'], + ['\\'], + ['|'], + ['?'], + ['*'], + ]; + } + + /** + * @dataProvider providesInvalidCharsPosix + * @expectedException \OCP\Files\InvalidCharacterInPathException + */ + public function testPathVerificationInvalidCharsPosix($fileName) { + $storage = new Local(['datadir' => '']); + + $fileName = " 123{$fileName}456 "; + \Test_Helper::invokePrivate($storage, 'verifyWindowsPath', [$fileName]); + } + + public function providesInvalidCharsPosix() { + return [ + [\chr(0)], + [\chr(1)], + [\chr(2)], + [\chr(3)], + [\chr(4)], + [\chr(5)], + [\chr(6)], + [\chr(7)], + [\chr(8)], + [\chr(9)], + [\chr(10)], + [\chr(11)], + [\chr(12)], + [\chr(13)], + [\chr(14)], + [\chr(15)], + [\chr(16)], + [\chr(17)], + [\chr(18)], + [\chr(19)], + [\chr(20)], + [\chr(21)], + [\chr(22)], + [\chr(23)], + [\chr(24)], + [\chr(25)], + [\chr(26)], + [\chr(27)], + [\chr(28)], + [\chr(29)], + [\chr(30)], + [\chr(31)], + ['/'], + ['\\'], + ]; + } + + /** + * @dataProvider providesReservedNamesWindows + * @expectedException \OCP\Files\ReservedWordException + */ + public function testPathVerificationReservedNamesWindows($fileName) { + $storage = new Local(['datadir' => '']); + + \Test_Helper::invokePrivate($storage, 'verifyWindowsPath', [$fileName]); + } + + public function providesReservedNamesWindows() { + return [ + [' CON '], + ['prn '], + ['AUX'], + ['NUL'], + ['COM1'], + ['COM2'], + ['COM3'], + ['COM4'], + ['COM5'], + ['COM6'], + ['COM7'], + ['COM8'], + ['COM9'], + ['LPT1'], + ['LPT2'], + ['LPT3'], + ['LPT4'], + ['LPT5'], + ['LPT6'], + ['LPT7'], + ['LPT8'], + ['LPT9'] + ]; + } + +} |