2015-02-18 16:44:13 +00:00
|
|
|
<?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;
|
2016-10-24 07:44:33 +00:00
|
|
|
use OCP\Files\InvalidPathException;
|
2015-02-18 16:44:13 +00:00
|
|
|
|
2015-11-27 15:26:16 +00:00
|
|
|
/**
|
2016-05-20 13:38:20 +00:00
|
|
|
* Class PathVerificationTest
|
2015-11-27 15:26:16 +00:00
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
|
|
|
* @package Test\Files
|
|
|
|
*/
|
2016-05-19 06:41:01 +00:00
|
|
|
class PathVerificationTest extends \Test\TestCase {
|
2015-02-18 16:44:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \OC\Files\View
|
|
|
|
*/
|
|
|
|
private $view;
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->view = new View();
|
|
|
|
}
|
|
|
|
|
2015-03-10 12:08:22 +00:00
|
|
|
/**
|
|
|
|
* @expectedException \OCP\Files\InvalidPathException
|
|
|
|
* @expectedExceptionMessage File name is too long
|
|
|
|
*/
|
|
|
|
public function testPathVerificationFileNameTooLong() {
|
|
|
|
$fileName = str_repeat('a', 500);
|
|
|
|
$this->view->verifyPath('', $fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-18 16:44:13 +00:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
public function testPathVerificationAstralPlane($fileName) {
|
2016-10-24 07:44:33 +00:00
|
|
|
$connection = \OC::$server->getDatabaseConnection();
|
|
|
|
|
|
|
|
if (!$connection->supports4ByteText()) {
|
|
|
|
$this->expectException(InvalidPathException::class);
|
2016-11-09 09:58:11 +00:00
|
|
|
$this->expectExceptionMessage('File name contains at least one invalid character');
|
2018-01-25 10:23:12 +00:00
|
|
|
} else {
|
|
|
|
$this->addToAssertionCount(1);
|
2016-10-24 07:44:33 +00:00
|
|
|
}
|
|
|
|
|
2015-02-18 16:44:13 +00:00
|
|
|
$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
|
|
|
|
['🐵'],
|
2015-07-30 09:22:14 +00:00
|
|
|
['🐵.txt'],
|
|
|
|
['txt.💩'],
|
2015-07-30 09:25:05 +00:00
|
|
|
['💩🐵.txt'],
|
|
|
|
['💩🐵'],
|
2015-02-18 16:44:13 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider providesInvalidCharsPosix
|
2015-03-04 13:03:47 +00:00
|
|
|
* @expectedException \OCP\Files\InvalidCharacterInPathException
|
2015-02-18 16:44:13 +00:00
|
|
|
*/
|
|
|
|
public function testPathVerificationInvalidCharsPosix($fileName) {
|
|
|
|
$storage = new Local(['datadir' => '']);
|
|
|
|
|
|
|
|
$fileName = " 123{$fileName}456 ";
|
2016-07-11 08:59:27 +00:00
|
|
|
self::invokePrivate($storage, 'verifyPosixPath', [$fileName]);
|
2015-02-18 16:44:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)],
|
|
|
|
['/'],
|
|
|
|
['\\'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2015-03-17 17:16:28 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider providesValidPosixPaths
|
|
|
|
*/
|
|
|
|
public function testPathVerificationValidPaths($fileName) {
|
|
|
|
$storage = new Local(['datadir' => '']);
|
|
|
|
|
2015-06-03 10:03:02 +00:00
|
|
|
self::invokePrivate($storage, 'verifyPosixPath', [$fileName]);
|
2015-03-17 17:16:28 +00:00
|
|
|
// nothing thrown
|
2018-01-25 10:23:12 +00:00
|
|
|
$this->addToAssertionCount(1);
|
2015-03-17 17:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function providesValidPosixPaths() {
|
|
|
|
return [
|
|
|
|
['simple'],
|
|
|
|
['simple.txt'],
|
|
|
|
['\''],
|
|
|
|
['`'],
|
|
|
|
['%'],
|
|
|
|
['()'],
|
|
|
|
['[]'],
|
|
|
|
['!'],
|
|
|
|
['$'],
|
|
|
|
['_'],
|
|
|
|
];
|
|
|
|
}
|
2015-02-18 16:44:13 +00:00
|
|
|
}
|