19 declare(strict_types=1);
    41     protected function setUp(): void
    44         $this->dic_backup = is_object($DIC) ? clone 
$DIC : null;
    46         $DIC = new \ILIAS\DI\Container();
    47         $DIC[
'ilDB'] = $this->db_mock = $this->createMock(ilDBInterface::class);
    58         $settings = $this->createMock(ilFileServicesSettings::class);
    60                  ->method(
'getWhiteListedSuffixes')
    61                  ->willReturn([
'pdf', 
'jpg']);
    64         $this->assertTrue($sanitizer->isClean(
'/lib/test.pdf'));
    65         $this->assertFalse($sanitizer->isClean(
'/lib/test.xml'));
    66         $this->assertEquals(
'/lib/testxml.sec', $sanitizer->sanitize(
'/lib/test.xml'));
    71         $settings = $this->createMock(ilFileServicesSettings::class);
    73                  ->method(
'getBlackListedSuffixes')
    74                  ->willReturn([
'pdf']);
    77                  ->method(
'isByPassAllowedForCurrentUser')
    80         $stream = $this->createMock(FileStream::class);
    81         $meta = 
new Metadata(
'filename.pdf', 42, 
'application/pdf');
    88         $status = $processor->process($stream, $meta);
    89         $this->assertEquals(ProcessingStatus::REJECTED, $status->getCode());
    94         $settings = $this->createMock(ilFileServicesSettings::class);
    96                  ->method(
'getBlackListedSuffixes')
    97                  ->willReturn([
'pdf']);
   100                  ->method(
'isByPassAllowedForCurrentUser')
   103         $stream = $this->createMock(FileStream::class);
   104         $meta = 
new Metadata(
'filename.pdf', 42, 
'application/pdf');
   111         $status = $processor->process($stream, $meta);
   112         $this->assertEquals(ProcessingStatus::OK, $status->getCode());
   117         $settings = $this->createMock(ilFileServicesSettings::class);
   119                  ->method(
'getWhiteListedSuffixes')
   120                  ->willReturn([
'pdf', 
'png', 
'jpg']);
   124         $sane_filename = 
'bellerophon.pdf';
   125         $this->assertEquals($sane_filename, $sanitizer->sanitize($sane_filename));
   127         $insane_filename = 
'bellerophon.docx';
   128         $this->assertNotEquals($insane_filename, $sanitizer->sanitize($insane_filename));
   129         $this->assertEquals(
'bellerophondocx.sec', $sanitizer->sanitize($insane_filename));
   134         $settings_mock = $this->createMock(ilSetting::class);
   135         $ini_mock = $this->createMock(ilIniFile::class);
   139         $this->db_mock->expects($this->once())
   140                 ->method(
'fetchObject')
   143         $this->db_mock->expects($this->once())
   144                 ->method(
'fetchAssoc')
   147         $default_whitelist = include __DIR__ . 
"/../../../Services/FileServices/defaults/default_whitelist.php";
   150         $settings_mock->expects($this->exactly(3))
   153                           [
'suffix_custom_expl_black'],
   154                           [
'suffix_repl_additional'],
   155                           [
'suffix_custom_white_list']
   157                       ->willReturnOnConsecutiveCalls(
   164         $this->assertEquals([
'bl001', 
'bl002'], 
$settings->getBlackListedSuffixes());
   165         $this->assertEquals([
'bl001', 
'bl002'], 
$settings->getProhibited());
   166         $this->assertEquals($default_whitelist, 
$settings->getDefaultWhitelist());
   167         $this->assertEquals([
'docx', 
'doc'], 
$settings->getWhiteListNegative());
   168         $this->assertEquals([
'wl001', 
'wl002'], 
$settings->getWhiteListPositive());
   170         $whitelist = array_merge(
   171             array_diff($default_whitelist, [
'docx', 
'doc']),
   172             [
'wl001', 
'wl002', 
'']
   174         $diff = array_diff($whitelist, 
$settings->getWhiteListedSuffixes());
   176         $this->assertEquals([], $diff);
   177         $this->assertEquals(0, count($diff));
   184         $settings = $this->createMock(ilFileServicesSettings::class);
   187                  ->method(
'getBlackListedSuffixes')
   188                  ->willReturn([
'mp3']);
   191                  ->method(
'getWhiteListedSuffixes')
   192                  ->willReturn([
'pdf', 
'png', 
'mp3']);
   195                  ->method(
'isASCIIConvertionEnabled')
   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'));
 
Class ilFileServicesPolicy. 
 
ILIAS DI Container $dic_backup
 
Customizing of pimple-DIC for ILIAS. 
 
// this is necessary to avoid side effects with the DIC  disabled 
 
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
 
Class ilFileServicesFilenameSanitizer. 
 
testRenamingNonWhitelistedFile()
 
testBlacklistedUploadWithPermission()
 
testFileNamePolicyOnDownloading()
 
Class ilFileServicesPolicy.