ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
BlacklistFileHeaderPreProcessorTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5 require_once('./libs/composer/vendor/autoload.php');
6 
11 
23 {
24 
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 
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 }
const REJECTED
Upload got rejected by a processor.
$result
$stream
PHP stream implementation.
static ofString($string)
Creates a new stream with an initial value.
Definition: Streams.php:30