ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
WhitelistFileHeaderPreProcessorTest.php
Go to the documentation of this file.
1<?php
2
20
21use PHPUnit\Framework\Attributes\BackupGlobals;
22use PHPUnit\Framework\Attributes\BackupStaticProperties;
23use PHPUnit\Framework\Attributes\PreserveGlobalState;
24use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
25use PHPUnit\Framework\Attributes\Test;
26use PHPUnit\Framework\Attributes\Small;
27
28require_once('./vendor/composer/vendor/autoload.php');
29
33use PHPUnit\Framework\TestCase;
34
40#[BackupGlobals(false)]
41#[BackupStaticProperties(false)]
42#[PreserveGlobalState(false)]
43#[RunTestsInSeparateProcesses]
45{
46 #[Test]
47
48 public function testProcessWhichShouldSucceed(): void
49 {
50 $fileHeaderStart = hex2bin('FFD8FF'); //jpg header start
51 $trailer = hex2bin('FFD9'); //jpg trailer
52 $subject = new WhitelistFileHeaderPreProcessor($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::OK, $result->getCode());
59 $this->assertSame('File header complies with whitelist.', $result->getMessage());
60 }
61
62 #[Test]
63
65 {
66 $fileHeaderWhitelist = hex2bin('FFD8FF'); //jpg header start
67 $fileHeaderStart = hex2bin('FFD8FB'); //jpg header start
68 $trailer = hex2bin('FFD9'); //jpg trailer
69 $subject = new WhitelistFileHeaderPreProcessor($fileHeaderWhitelist);
70 $stream = Streams::ofString("$fileHeaderStart bla bla bla $trailer");
71 $stream->rewind();
72
73 $result = $subject->process($stream, new Metadata('hello.jpg', $stream->getSize(), 'image/jpg'));
74
75 $this->assertSame(ProcessingStatus::REJECTED, $result->getCode());
76 $this->assertSame('File header don\'t complies with whitelist.', $result->getMessage());
77 }
78}
Stream factory which enables the user to create streams without the knowledge of the concrete class.
Definition: Streams.php:32
static ofString(string $string)
Creates a new stream with an initial value.
Definition: Streams.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...