19declare(strict_types=1);
23use PHPUnit\Framework\TestCase;
24use PHPUnit\Framework\Attributes\DataProvider;
30 return class_exists(vfs\vfsStreamWrapper::class);
36 $this->markTestSkipped(
37 'vfsStream (https://github.com/bovigo/vfsStream) is required for virtual filesystem tests.'
43 string $temp_file_name,
44 string $ilias_data_dir
51 protected function getRealPath(
54 $normalized = str_replace(
'\\',
'/',
$path);
56 return rtrim($normalized,
'/');
70 $this->skipIfVfsStreamNotAvailable();
72 vfs\vfsStream::setup();
73 vfs\vfsStream::create([
76 'icon_upload.svg' =>
'<svg xmlns="http://www.w3.org/2000/svg"/>',
81 $data_dir = vfs\vfsStream::url(
'root/data');
82 $expected_file = vfs\vfsStream::url(
'root/data/temp/icon_upload.svg');
84 $path = $this->buildTestingObject(
89 self::assertSame($expected_file,
$path->getAbsolutePath());
94 $this->skipIfVfsStreamNotAvailable();
96 vfs\vfsStream::setup();
97 vfs\vfsStream::create([
99 'secret.txt' =>
'sensitive',
104 $data_dir = vfs\vfsStream::url(
'root/data');
106 $this->expectException(InvalidArgumentException::class);
107 $this->expectExceptionMessage(
'Temporary upload file not found.');
109 $this->buildTestingObject(
117 $this->skipIfVfsStreamNotAvailable();
119 vfs\vfsStream::setup();
120 vfs\vfsStream::create([
126 $data_dir = vfs\vfsStream::url(
'root/data');
128 $this->expectException(InvalidArgumentException::class);
129 $this->expectExceptionMessage(
'Temporary upload file not found.');
131 $this->buildTestingObject(
137 #[DataProvider('invalidTemporaryFileNameProvider')]
139 string $malicious_input
141 $this->expectException(InvalidArgumentException::class);
142 $this->expectExceptionMessage(
'Invalid temporary upload file name.');
144 $this->buildTestingObject(
155 yield
'parent directory segment' => [
'..'];
156 yield
'current directory segment' => [
'.'];
testInvalidTemporaryFileNameIsRejected(string $malicious_input)
static invalidTemporaryFileNameProvider()
skipIfVfsStreamNotAvailable()
testTrustedTempUploadFileIsResolved()
buildTestingObject(string $temp_file_name, string $ilias_data_dir)
testAbsentTempUploadFileIsRejected()
testParentDirectorySegmentsInUserInputAreRejected()
Resolves a user-supplied temp file identifier to an absolute path that is guaranteed to refer to a re...
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...