ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
WhitelistFileHeaderPreProcessorTest.php
Go to the documentation of this file.
1 <?php
2 
4 
5 require_once('./libs/composer/vendor/autoload.php');
6 
11 
23 {
29  {
30  $fileHeaderStart = hex2bin('FFD8FF'); //jpg header start
31  $trailer = hex2bin('FFD9'); //jpg trailer
32  $subject = new WhitelistFileHeaderPreProcessor($fileHeaderStart);
33  $stream = Streams::ofString("$fileHeaderStart bla bla bla $trailer");
34  $stream->rewind();
35 
36  $result = $subject->process($stream, new Metadata('hello.jpg', $stream->getSize(), 'image/jpg'));
37 
38  $this->assertSame(ProcessingStatus::OK, $result->getCode());
39  $this->assertSame('File header complies with whitelist.', $result->getMessage());
40  }
41 
47  {
48  $fileHeaderWhitelist = hex2bin('FFD8FF'); //jpg header start
49  $fileHeaderStart = hex2bin('FFD8FB'); //jpg header start
50  $trailer = hex2bin('FFD9'); //jpg trailer
51  $subject = new WhitelistFileHeaderPreProcessor($fileHeaderWhitelist);
52  $stream = Streams::ofString("$fileHeaderStart bla bla bla $trailer");
53  $stream->rewind();
54 
55  $result = $subject->process($stream, new Metadata('hello.jpg', $stream->getSize(), 'image/jpg'));
56 
57  $this->assertSame(ProcessingStatus::REJECTED, $result->getCode());
58  $this->assertSame('File header don\'t complies with whitelist.', $result->getMessage());
59  }
60 }
const REJECTED
Upload got rejected by a processor.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:43