123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- <?php
- namespace Test\Files;
- use OC\Files\Storage\Local;
- use OC\Files\View;
- use OCP\Files\InvalidPathException;
- class PathVerificationTest extends \Test\TestCase {
-
- private $view;
- protected function setUp(): void {
- parent::setUp();
- $this->view = new View();
- }
- public function testPathVerificationFileNameTooLong(): void {
- $this->expectException(\OCP\Files\InvalidPathException::class);
- $this->expectExceptionMessage('Filename is too long');
- $fileName = str_repeat('a', 500);
- $this->view->verifyPath('', $fileName);
- }
-
- public function testPathVerificationEmptyFileName($fileName): void {
- $this->expectException(\OCP\Files\InvalidPathException::class);
- $this->expectExceptionMessage('Empty filename is not allowed');
- $this->view->verifyPath('', $fileName);
- }
- public function providesEmptyFiles() {
- return [
- [''],
- [' '],
- ];
- }
-
- public function testPathVerificationDotFiles($fileName): void {
- $this->expectException(\OCP\Files\InvalidPathException::class);
- $this->expectExceptionMessage('Dot files are not allowed');
- $this->view->verifyPath('', $fileName);
- }
- public function providesDotFiles() {
- return [
- ['.'],
- ['..'],
- [' .'],
- [' ..'],
- ['. '],
- ['.. '],
- [' . '],
- [' .. '],
- ];
- }
-
- public function testPathVerificationAstralPlane($fileName): void {
- $connection = \OC::$server->getDatabaseConnection();
- if (!$connection->supports4ByteText()) {
- $this->expectException(InvalidPathException::class);
- $this->expectExceptionMessage('File name contains at least one invalid character');
- } else {
- $this->addToAssertionCount(1);
- }
- $this->view->verifyPath('', $fileName);
- }
- public function providesAstralPlane() {
- return [
-
- ['🐵'],
- ['🐵.txt'],
- ['txt.💩'],
- ['💩🐵.txt'],
- ['💩🐵'],
- ];
- }
-
- public function testPathVerificationValidPaths($fileName): void {
- $storage = new Local(['datadir' => '']);
- self::invokePrivate($storage, 'verifyPosixPath', [$fileName]);
-
- $this->addToAssertionCount(1);
- }
- public function providesValidPosixPaths() {
- return [
- ['simple'],
- ['simple.txt'],
- ['\''],
- ['`'],
- ['%'],
- ['()'],
- ['[]'],
- ['!'],
- ['$'],
- ['_'],
- ];
- }
- }
|