ILIAS
release_5-3 Revision v5.3.23-19-g915713cf615
◀ ilDoc Overview
WhitelistFileHeaderPreProcessorTest.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
WhitelistFileHeaderPreProcessorTest
extends
TestCase
23
{
24
29
public
function
testProcessWhichShouldSucceed
()
30
{
31
$fileHeaderStart = hex2bin(
'FFD8FF'
);
//jpg header start
32
$trailer = hex2bin(
'FFD9'
);
//jpg trailer
33
$subject =
new
WhitelistFileHeaderPreProcessor
($fileHeaderStart);
34
$stream
=
Streams::ofString
(
"$fileHeaderStart bla bla bla $trailer"
);
35
$stream
->rewind();
36
37
$result
= $subject->process(
$stream
,
new
Metadata
(
'hello.jpg'
,
$stream
->getSize(),
'image/jpg'
));
38
39
$this->assertSame(
ProcessingStatus::OK
,
$result
->getCode());
40
$this->assertSame(
'File header complies with whitelist.'
,
$result
->getMessage());
41
}
42
47
public
function
testProcessWithHeaderMismatchWhichShouldGetRejected
()
48
{
49
$fileHeaderWhitelist = hex2bin(
'FFD8FF'
);
//jpg header start
50
$fileHeaderStart = hex2bin(
'FFD8FB'
);
//jpg header start
51
$trailer = hex2bin(
'FFD9'
);
//jpg trailer
52
$subject =
new
WhitelistFileHeaderPreProcessor
($fileHeaderWhitelist);
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 don\'t complies with whitelist.'
,
$result
->getMessage());
60
}
61
}
ILIAS\FileUpload\Processor\WhitelistFileHeaderPreProcessorTest
Class WhitelistFileHeaderPreProcessorTest.
Definition:
WhitelistFileHeaderPreProcessorTest.php:22
ILIAS\FileUpload\DTO\ProcessingStatus\REJECTED
const REJECTED
Upload got rejected by a processor.
Definition:
ProcessingStatus.php:30
$result
$result
Definition:
CleanUpTest.php:463
GuzzleHttp\Psr7\$stream
$stream
PHP stream implementation.
Definition:
MessageTrait.php:21
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:29
ILIAS\FileUpload\Processor\WhitelistFileHeaderPreProcessorTest\testProcessWithHeaderMismatchWhichShouldGetRejected
testProcessWithHeaderMismatchWhichShouldGetRejected()
Definition:
WhitelistFileHeaderPreProcessorTest.php:47
ILIAS\FileUpload\Processor\WhitelistFileHeaderPreProcessor
Class WhitelistFileHeaderPreProcessor.
Definition:
WhitelistFileHeaderPreProcessor.php:20
Metadata
ILIAS\FileUpload\Processor\WhitelistFileHeaderPreProcessorTest\testProcessWhichShouldSucceed
testProcessWhichShouldSucceed()
Definition:
WhitelistFileHeaderPreProcessorTest.php:29
Streams
TestCase
ILIAS\FileUpload\DTO\ProcessingStatus\OK
const OK
Upload is ok.
Definition:
ProcessingStatus.php:26
tests
FileUpload
Processor
WhitelistFileHeaderPreProcessorTest.php
Generated on Tue Jan 28 2025 19:01:46 for ILIAS by
1.8.13 (using
Doxyfile
)