ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
CustomIconTempUploadPathTest Class Reference
+ Inheritance diagram for CustomIconTempUploadPathTest:
+ Collaboration diagram for CustomIconTempUploadPathTest:

Public Member Functions

 testTrustedTempUploadFileIsResolved ()
 
 testParentDirectorySegmentsInUserInputAreRejected ()
 
 testAbsentTempUploadFileIsRejected ()
 
 testInvalidTemporaryFileNameIsRejected (string $malicious_input)
 

Static Public Member Functions

static invalidTemporaryFileNameProvider ()
 

Private Member Functions

 vfsStreamIsAvailable ()
 
 skipIfVfsStreamNotAvailable ()
 
 buildTestingObject (string $temp_file_name, string $ilias_data_dir)
 

Detailed Description

Definition at line 26 of file CustomIconTempUploadPathTest.php.

Member Function Documentation

◆ buildTestingObject()

CustomIconTempUploadPathTest::buildTestingObject ( string  $temp_file_name,
string  $ilias_data_dir 
)
private

Definition at line 42 of file CustomIconTempUploadPathTest.php.

46 return new class (
47 $temp_file_name,
48 $ilias_data_dir
49 ) extends CustomIconTempUploadPath {
50 #[\Override]
51 protected function getRealPath(
52 string $path
53 ): string|false {
54 $normalized = str_replace('\\', '/', $path);
55 if (is_dir($path)) {
56 return rtrim($normalized, '/');
57 }
58
59 if (is_file($path)) {
60 return $normalized;
61 }
62
63 return false;
64 }
65 };
66 }
Resolves a user-supplied temp file identifier to an absolute path that is guaranteed to refer to a re...
$path
Definition: ltiservices.php:30

◆ invalidTemporaryFileNameProvider()

static CustomIconTempUploadPathTest::invalidTemporaryFileNameProvider ( )
static
Returns
Generator<string, array{0: string}>

Definition at line 153 of file CustomIconTempUploadPathTest.php.

153 : Generator
154 {
155 yield 'parent directory segment' => ['..'];
156 yield 'current directory segment' => ['.'];
157 }

◆ skipIfVfsStreamNotAvailable()

CustomIconTempUploadPathTest::skipIfVfsStreamNotAvailable ( )
private

Definition at line 33 of file CustomIconTempUploadPathTest.php.

33 : void
34 {
35 if (!$this->vfsStreamIsAvailable()) {
36 $this->markTestSkipped(
37 'vfsStream (https://github.com/bovigo/vfsStream) is required for virtual filesystem tests.'
38 );
39 }
40 }

References vfsStreamIsAvailable().

+ Here is the call graph for this function:

◆ testAbsentTempUploadFileIsRejected()

CustomIconTempUploadPathTest::testAbsentTempUploadFileIsRejected ( )

Definition at line 115 of file CustomIconTempUploadPathTest.php.

115 : void
116 {
118
119 vfs\vfsStream::setup();
120 vfs\vfsStream::create([
121 'data' => [
122 'temp' => [],
123 ],
124 ]);
125
126 $data_dir = vfs\vfsStream::url('root/data');
127
128 $this->expectException(InvalidArgumentException::class);
129 $this->expectExceptionMessage('Temporary upload file not found.');
130
131 $this->buildTestingObject(
132 'missing.svg',
134 );
135 }
buildTestingObject(string $temp_file_name, string $ilias_data_dir)

References $data_dir.

◆ testInvalidTemporaryFileNameIsRejected()

CustomIconTempUploadPathTest::testInvalidTemporaryFileNameIsRejected ( string  $malicious_input)

Definition at line 138 of file CustomIconTempUploadPathTest.php.

140 : void {
141 $this->expectException(InvalidArgumentException::class);
142 $this->expectExceptionMessage('Invalid temporary upload file name.');
143
144 $this->buildTestingObject(
145 $malicious_input,
146 '/does/not/matter'
147 );
148 }

◆ testParentDirectorySegmentsInUserInputAreRejected()

CustomIconTempUploadPathTest::testParentDirectorySegmentsInUserInputAreRejected ( )

Definition at line 92 of file CustomIconTempUploadPathTest.php.

92 : void
93 {
95
96 vfs\vfsStream::setup();
97 vfs\vfsStream::create([
98 'data' => [
99 'secret.txt' => 'sensitive',
100 'temp' => [],
101 ],
102 ]);
103
104 $data_dir = vfs\vfsStream::url('root/data');
105
106 $this->expectException(InvalidArgumentException::class);
107 $this->expectExceptionMessage('Temporary upload file not found.');
108
109 $this->buildTestingObject(
110 '../secret.txt',
112 );
113 }

References $data_dir.

◆ testTrustedTempUploadFileIsResolved()

CustomIconTempUploadPathTest::testTrustedTempUploadFileIsResolved ( )

Definition at line 68 of file CustomIconTempUploadPathTest.php.

68 : void
69 {
71
72 vfs\vfsStream::setup();
73 vfs\vfsStream::create([
74 'data' => [
75 'temp' => [
76 'icon_upload.svg' => '<svg xmlns="http://www.w3.org/2000/svg"/>',
77 ],
78 ],
79 ]);
80
81 $data_dir = vfs\vfsStream::url('root/data');
82 $expected_file = vfs\vfsStream::url('root/data/temp/icon_upload.svg');
83
85 'icon_upload.svg',
87 );
88
89 self::assertSame($expected_file, $path->getAbsolutePath());
90 }

References $data_dir, and $path.

◆ vfsStreamIsAvailable()

CustomIconTempUploadPathTest::vfsStreamIsAvailable ( )
private

Definition at line 28 of file CustomIconTempUploadPathTest.php.

28 : bool
29 {
30 return class_exists(vfs\vfsStreamWrapper::class);
31 }

Referenced by skipIfVfsStreamNotAvailable().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: