summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-02-18 17:44:13 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-03-09 10:38:37 +0100
commit4bac595068c813c56d8d5e580e560527ba80194d (patch)
treee7584ca8ff57a9b037388d428e47f390bc1a7fcc /tests
parent348fe105b13717757bee4150caa9d3546d6a7666 (diff)
downloadnextcloud-server-4bac595068c813c56d8d5e580e560527ba80194d.tar.gz
nextcloud-server-4bac595068c813c56d8d5e580e560527ba80194d.zip
adding storage specific filename verification - refs #13640
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/connector/sabre/exception/invalidpathtest.php41
-rw-r--r--tests/lib/files/pathverificationtest.php226
2 files changed, 267 insertions, 0 deletions
diff --git a/tests/lib/connector/sabre/exception/invalidpathtest.php b/tests/lib/connector/sabre/exception/invalidpathtest.php
new file mode 100644
index 00000000000..ee3da8c3886
--- /dev/null
+++ b/tests/lib/connector/sabre/exception/invalidpathtest.php
@@ -0,0 +1,41 @@
+<?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.
+ */
+class Test_OC_Connector_Sabre_Exception_InvalidPath 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 OC_Connector_Sabre_Exception_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/files/pathverificationtest.php b/tests/lib/files/pathverificationtest.php
new file mode 100644
index 00000000000..fafc98cc3cc
--- /dev/null
+++ b/tests/lib/files/pathverificationtest.php
@@ -0,0 +1,226 @@
+<?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\InvalidPathException
+ * @expectedExceptionMessage File name contains at least one invalid characters
+ */
+ 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\InvalidPathException
+ * @expectedExceptionMessage File name contains at least one invalid characters
+ */
+ 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\InvalidPathException
+ * @expectedExceptionMessage File name is a reserved word
+ */
+ 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']
+ ];
+ }
+
+}