xref: /PHP-8.0/ext/phar/tests/zip/require_hash.phpt (revision 90081c53)
1--TEST--
2Phar: zip-based phar, require_hash=1, no signature
3--SKIPIF--
4<?php
5if (!extension_loaded('phar')) die('skip');
6if (!extension_loaded('zip')) die('skip');
7?>
8--INI--
9phar.readonly=1
10phar.require_hash=0
11--FILE--
12<?php
13ini_set('phar.require_hash', 1);
14include __DIR__ . '/files/zipmaker.php.inc';
15$fname = __DIR__ . '/require_hash.phar.zip';
16$alias = 'phar://' . $fname;
17$fname2 = __DIR__ . '/require_hash.zip';
18
19$zip = new zipmaker($fname);
20$zip->init();
21$zip->addFile('zip_001.php', '<?php var_dump(__FILE__);');
22$zip->addFile('internal/file/here', "hi there!\n");
23$zip->addFile('.phar/stub.php', "__HALT_COMPILER();");
24$zip->close();
25
26try {
27	$phar = new Phar($fname);
28	var_dump($phar->getStub());
29} catch (Exception $e) {
30	echo $e->getMessage()."\n";
31}
32ini_set('phar.require_hash', 0);
33try {
34	$phar = new PharData($fname2);
35	$phar['file'] = 'hi';
36	var_dump($phar->getSignature());
37	$phar->setSignatureAlgorithm(Phar::MD5);
38	var_dump($phar->getSignature());
39} catch (Exception $e) {
40	echo $e->getMessage()."\n";
41}
42
43?>
44===DONE===
45--CLEAN--
46<?php
47@unlink(__DIR__ . '/require_hash.phar.zip');
48@unlink(__DIR__ . '/require_hash.zip');
49?>
50--EXPECTF--
51phar error: signature is missing in zip-based phar "%srequire_hash.phar.zip"
52bool(false)
53array(2) {
54  ["hash"]=>
55  string(32) "%s"
56  ["hash_type"]=>
57  string(3) "MD5"
58}
59===DONE===
60