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