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