ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
WhitelistFileHeaderPreProcessorTest.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  $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 
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 }
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