ILIAS
release_5-4 Revision v5.4.26-12-gabc799a52e6
◀ ilDoc Overview
BlacklistFileHeaderPreProcessorTest.php
Go to the documentation of this file.
1
<?
php
2
3
namespace
ILIAS\FileUpload\Processor
;
4
5
require_once(
'./libs/composer/vendor/autoload.php'
);
6
7
use
ILIAS\Filesystem\Stream\Streams
;
8
use
ILIAS\FileUpload\DTO\Metadata
;
9
use
ILIAS\FileUpload\DTO\ProcessingStatus
;
10
use
PHPUnit\Framework\TestCase
;
11
22
class
BlacklistFileHeaderPreProcessorTest
extends
TestCase
23
{
24
29
public
function
testProcessWhichShouldSucceed
()
30
{
31
$fileHeaderBlacklist = hex2bin(
'FFD8FF'
);
//jpg header start
32
$fileHeaderStart = hex2bin(
'FFD8FB'
);
//jpg header start
33
$trailer = hex2bin(
'FFD9'
);
//jpg trailer
34
$subject =
new
BlacklistFileHeaderPreProcessor
($fileHeaderBlacklist);
35
$stream
=
Streams::ofString
(
"$fileHeaderStart bla bla bla $trailer"
);
36
$stream
->rewind();
37
38
$result
= $subject->process(
$stream
,
new
Metadata
(
'hello.jpg'
,
$stream
->getSize(),
'image/jpg'
));
39
40
$this->assertSame(
ProcessingStatus::OK
,
$result
->getCode());
41
$this->assertSame(
'File header does not match blacklist.'
,
$result
->getMessage());
42
}
43
48
public
function
testProcessWithHeaderMismatchWhichShouldGetRejected
()
49
{
50
$fileHeaderStart = hex2bin(
'FFD8FF'
);
//jpg header start
51
$trailer = hex2bin(
'FFD9'
);
//jpg trailer
52
$subject =
new
BlacklistFileHeaderPreProcessor
($fileHeaderStart);
53
$stream
=
Streams::ofString
(
"$fileHeaderStart bla bla bla $trailer"
);
54
$stream
->rewind();
55
56
$result
= $subject->process(
$stream
,
new
Metadata
(
'hello.jpg'
,
$stream
->getSize(),
'image/jpg'
));
57
58
$this->assertSame(
ProcessingStatus::REJECTED
,
$result
->getCode());
59
$this->assertSame(
'File header matches blacklist.'
,
$result
->getMessage());
60
}
61
}
ILIAS\FileUpload\DTO\ProcessingStatus\REJECTED
const REJECTED
Upload got rejected by a processor.
Definition:
ProcessingStatus.php:30
ILIAS\FileUpload\Processor\BlacklistFileHeaderPreProcessorTest
Class BlacklistFileHeaderPreProcessorTest.
Definition:
BlacklistFileHeaderPreProcessorTest.php:22
$result
$result
Definition:
CleanUpTest.php:463
GuzzleHttp\Psr7\$stream
$stream
PHP stream implementation.
Definition:
MessageTrait.php:21
ILIAS\FileUpload\Processor\BlacklistFileHeaderPreProcessor
Class BlacklistFileHeaderPreProcessor.
Definition:
BlacklistFileHeaderPreProcessor.php:20
ProcessingStatus
ILIAS\FileUpload\Processor
Definition:
BlacklistExtensionPreProcessor.php:3
ILIAS\FileUpload\DTO\Metadata
Class Metadata.
Definition:
Metadata.php:21
ILIAS\Filesystem\Stream\Streams\ofString
static ofString($string)
Creates a new stream with an initial value.
Definition:
Streams.php:30
ILIAS\FileUpload\Processor\BlacklistFileHeaderPreProcessorTest\testProcessWhichShouldSucceed
testProcessWhichShouldSucceed()
Definition:
BlacklistFileHeaderPreProcessorTest.php:29
Metadata
Streams
php
ILIAS\FileUpload\Processor\BlacklistFileHeaderPreProcessorTest\testProcessWithHeaderMismatchWhichShouldGetRejected
testProcessWithHeaderMismatchWhichShouldGetRejected()
Definition:
BlacklistFileHeaderPreProcessorTest.php:48
TestCase
ILIAS\FileUpload\DTO\ProcessingStatus\OK
const OK
Upload is ok.
Definition:
ProcessingStatus.php:26
tests
FileUpload
Processor
BlacklistFileHeaderPreProcessorTest.php
Generated on Thu Jan 16 2025 19:02:38 for ILIAS by
1.8.13 (using
Doxyfile
)