ILIAS  release_7 Revision v7.30-3-g800a261c036
WhitelistFileHeaderPreProcessorTest.php
Go to the documentation of this file.
1<?php
2
4
5require_once('./libs/composer/vendor/autoload.php');
6
10use PHPUnit\Framework\TestCase;
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}
$result
An exception for terminatinating execution or to throw for unit testing.
const REJECTED
Upload got rejected by a processor.
Class Streams Stream factory which enables the user to create streams without the knowledge of the co...
Definition: Streams.php:17
static ofString($string)
Creates a new stream with an initial value.
Definition: Streams.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...