-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathNoPharTest.php
More file actions
64 lines (57 loc) · 1.92 KB
/
NoPharTest.php
File metadata and controls
64 lines (57 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Reader;
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\IReader;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class NoPharTest extends TestCase
{
/**
* @param class-string<IReader> $reader
*/
#[DataProvider('providerReaders')]
public function testNoPhar(string $reader): void
{
$this->expectException(SpreadsheetException::class);
$this->expectExceptionMessage('Disallowed stream wrapper');
$reader = new $reader();
$reader->load('phar://anyoldname');
}
/**
* @param class-string<IReader> $reader
*/
#[DataProvider('providerReaders')]
public function testPhar3Slashes(string $reader): void
{
$invalidProtocol = [
'3 slashes' => 'phar:///anyoldname',
'mixed case' => 'Phar:///anyoldname',
'embedded space' => 'ph ar://anyoldname',
'embedded control character' => "ph\x04ar://anyoldname",
'filter with phar' => 'php://filter/read=convert.base64-encode/resource=phar:///tmp/x.Phar',
];
$reader = new $reader();
foreach ($invalidProtocol as $key => $value) {
try {
$reader->load($value);
self::fail("Should have thrown exception - $key");
} catch (SpreadsheetException $e) {
self::assertStringContainsString('Disallowed stream wrapper', $e->getMessage(), $key);
}
}
}
/**
* @return array<array<class-string<IReader>>>
*/
public static function providerReaders(): array
{
$readers = IOFactory::getReaders();
$array = [];
foreach ($readers as $key => $reader) {
$array[$key] = [$reader];
}
return $array;
}
}