ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilServicesFileServicesTest Class Reference
+ Inheritance diagram for ilServicesFileServicesTest:
+ Collaboration diagram for ilServicesFileServicesTest:

Public Member Functions

 testSanitizing ()
 
 testBlacklistedUpload ()
 
 testBlacklistedUploadWithPermission ()
 
 testRenamingNonWhitelistedFile ()
 
 testActualWhitelist ()
 
 testDisabledASCIISetting ()
 
 testNoASCIISetting ()
 
 testFileNamePolicyOnDownloading ()
 

Private Attributes

ILIAS DI Container $dic_backup
 

Detailed Description

Definition at line 27 of file ilServicesFileServicesTest.php.

Member Function Documentation

◆ testActualWhitelist()

ilServicesFileServicesTest::testActualWhitelist ( )

Definition at line 107 of file ilServicesFileServicesTest.php.

References ILIAS\LTI\ToolProvider\$settings.

107  : void
108  {
109  $db_mock = $this->createMock(ilDBInterface::class);
110  $settings_mock = $this->createMock(ilSetting::class);
111  $ini_mock = $this->createMock(ilIniFile::class);
112 
113  $ref = new stdClass();
114  $ref->ref_id = 32;
115  $db_mock->expects($this->once())
116  ->method('fetchObject')
117  ->willReturn($ref);
118 
119  $default_whitelist = include "./Services/FileServices/defaults/default_whitelist.php";
120 
121  // Blacklist
122  $settings_mock->expects($this->exactly(3))
123  ->method('get')
124  ->withConsecutive(
125  ['suffix_custom_expl_black'],
126  ['suffix_repl_additional'],
127  ['suffix_custom_white_list']
128  )
129  ->willReturnOnConsecutiveCalls(
130  'bl001,bl002', // blacklisted
131  'docx,doc', // remove from whitelist
132  'wl001,wl002' // add whitelist
133  );
134 
135  $settings = new ilFileServicesSettings($settings_mock, $ini_mock, $db_mock);
136  $this->assertEquals(['bl001', 'bl002'], $settings->getBlackListedSuffixes());
137  $this->assertEquals(['bl001', 'bl002'], $settings->getProhibited());
138  $this->assertEquals($default_whitelist, $settings->getDefaultWhitelist());
139  $this->assertEquals(['docx', 'doc'], $settings->getWhiteListNegative());
140  $this->assertEquals(['wl001', 'wl002'], $settings->getWhiteListPositive());
141 
142  $whitelist = array_merge(
143  array_diff($default_whitelist, ['docx', 'doc']),
144  ['wl001', 'wl002', '']
145  );
146  $diff = array_diff($whitelist, $settings->getWhiteListedSuffixes());
147 
148  $this->assertEquals([], $diff);
149  $this->assertEquals(0, count($diff));
150  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ testBlacklistedUpload()

ilServicesFileServicesTest::testBlacklistedUpload ( )

Definition at line 44 of file ilServicesFileServicesTest.php.

References ILIAS\LTI\ToolProvider\$settings.

44  : void
45  {
46  $settings = $this->createMock(ilFileServicesSettings::class);
47  $settings->expects($this->once())
48  ->method('getBlackListedSuffixes')
49  ->willReturn(['pdf']);
50 
51  $settings->expects($this->once())
52  ->method('isByPassAllowedForCurrentUser')
53  ->willReturn(false);
54 
55  $stream = $this->createMock(FileStream::class);
56  $meta = new Metadata('filename.pdf', 42, 'application/pdf');
57 
58  $processor = new ilFileServicesPreProcessor(
59  $settings,
60  'the reason'
61  );
62  // is ok since user has permission
63  $status = $processor->process($stream, $meta);
64  $this->assertEquals(ProcessingStatus::REJECTED, $status->getCode());
65  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200

◆ testBlacklistedUploadWithPermission()

ilServicesFileServicesTest::testBlacklistedUploadWithPermission ( )

Definition at line 67 of file ilServicesFileServicesTest.php.

References ILIAS\LTI\ToolProvider\$settings.

67  : void
68  {
69  $settings = $this->createMock(ilFileServicesSettings::class);
70  $settings->expects($this->once())
71  ->method('getBlackListedSuffixes')
72  ->willReturn(['pdf']);
73 
74  $settings->expects($this->once())
75  ->method('isByPassAllowedForCurrentUser')
76  ->willReturn(true);
77 
78  $stream = $this->createMock(FileStream::class);
79  $meta = new Metadata('filename.pdf', 42, 'application/pdf');
80 
81  $processor = new ilFileServicesPreProcessor(
82  $settings,
83  'the reason'
84  );
85  // is ok since user has permission
86  $status = $processor->process($stream, $meta);
87  $this->assertEquals(ProcessingStatus::OK, $status->getCode());
88  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200

◆ testDisabledASCIISetting()

ilServicesFileServicesTest::testDisabledASCIISetting ( )

Definition at line 152 of file ilServicesFileServicesTest.php.

References ILIAS\LTI\ToolProvider\$settings.

152  : void
153  {
154  $db_mock = $this->createMock(ilDBInterface::class);
155  $settings_mock = $this->createMock(ilSetting::class);
156  $ini_mock = $this->createMock(ilIniFile::class);
157 
158  $ini_mock->expects($this->once())
159  ->method('readVariable')
160  ->with('file_access', 'disable_ascii')
161  ->willReturn('1');
162 
163  $settings = new ilFileServicesSettings($settings_mock, $ini_mock, $db_mock);
164  $this->assertFalse($settings->isASCIIConvertionEnabled());
165  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ testFileNamePolicyOnDownloading()

ilServicesFileServicesTest::testFileNamePolicyOnDownloading ( )

Definition at line 182 of file ilServicesFileServicesTest.php.

References ILIAS\LTI\ToolProvider\$settings.

182  : void
183  {
184  $settings = $this->createMock(ilFileServicesSettings::class);
185 
186  $settings->expects($this->atLeastOnce())
187  ->method('getBlackListedSuffixes')
188  ->willReturn(['mp3']);
189 
190  $settings->expects($this->atLeastOnce())
191  ->method('getWhiteListedSuffixes')
192  ->willReturn(['pdf', 'png', 'mp3']);
193 
194  $settings->expects($this->atLeastOnce())
195  ->method('isASCIIConvertionEnabled')
196  ->willReturn(true);
197 
198  $policy = new ilFileServicesPolicy($settings);
199  $this->assertEquals('testmp3.sec', $policy->prepareFileNameForConsumer('test.mp3'));
200  $this->assertEquals('test.png', $policy->prepareFileNameForConsumer('test.png'));
201  $this->assertEquals('test.pdf', $policy->prepareFileNameForConsumer('test.pdf'));
202  $this->assertEquals('aeaeaeaeaeaeaeaeae.pdf', $policy->prepareFileNameForConsumer('äääääääää.pdf'));
203  $this->assertEquals('oeoeoeoeoeoeoeoeoe.pdf', $policy->prepareFileNameForConsumer('ööööööööö.pdf'));
204  $this->assertEquals('ueueueueueueueueue.pdf', $policy->prepareFileNameForConsumer('üüüüüüüüü.pdf'));
205  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
Class ilFileServicesPolicy.

◆ testNoASCIISetting()

ilServicesFileServicesTest::testNoASCIISetting ( )

Definition at line 167 of file ilServicesFileServicesTest.php.

References ILIAS\LTI\ToolProvider\$settings.

167  : void
168  {
169  $db_mock = $this->createMock(ilDBInterface::class);
170  $settings_mock = $this->createMock(ilSetting::class);
171  $ini_mock = $this->createMock(ilIniFile::class);
172 
173  $ini_mock->expects($this->once())
174  ->method('readVariable')
175  ->with('file_access', 'disable_ascii')
176  ->willReturn('');
177 
178  $settings = new ilFileServicesSettings($settings_mock, $ini_mock, $db_mock);
179  $this->assertTrue($settings->isASCIIConvertionEnabled());
180  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ testRenamingNonWhitelistedFile()

ilServicesFileServicesTest::testRenamingNonWhitelistedFile ( )

Definition at line 90 of file ilServicesFileServicesTest.php.

References ILIAS\LTI\ToolProvider\$settings.

90  : void
91  {
92  $settings = $this->createMock(ilFileServicesSettings::class);
93  $settings->expects($this->once())
94  ->method('getWhiteListedSuffixes')
95  ->willReturn(['pdf', 'png', 'jpg']);
96 
98 
99  $sane_filename = 'bellerophon.pdf';
100  $this->assertEquals($sane_filename, $sanitizer->sanitize($sane_filename));
101 
102  $insane_filename = 'bellerophon.docx';
103  $this->assertNotEquals($insane_filename, $sanitizer->sanitize($insane_filename));
104  $this->assertEquals('bellerophondocx.sec', $sanitizer->sanitize($insane_filename));
105  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
Class ilFileServicesFilenameSanitizer.

◆ testSanitizing()

ilServicesFileServicesTest::testSanitizing ( )

Definition at line 31 of file ilServicesFileServicesTest.php.

References ILIAS\LTI\ToolProvider\$settings.

31  : void
32  {
33  $settings = $this->createMock(ilFileServicesSettings::class);
34  $settings->expects($this->once())
35  ->method('getWhiteListedSuffixes')
36  ->willReturn(['pdf', 'jpg']);
37 
39  $this->assertTrue($sanitizer->isClean('/lib/test.pdf'));
40  $this->assertFalse($sanitizer->isClean('/lib/test.xml'));
41  $this->assertEquals('/lib/testxml.sec', $sanitizer->sanitize('/lib/test.xml'));
42  }
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
Class ilFileServicesFilenameSanitizer.

Field Documentation

◆ $dic_backup

ILIAS DI Container ilServicesFileServicesTest::$dic_backup
private

Definition at line 29 of file ilServicesFileServicesTest.php.


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