xref: /PHP-8.2/ext/phar/tests/phar_mount.phpt (revision 74859783)
1--TEST--
2Phar: Phar::mount
3--EXTENSIONS--
4phar
5--INI--
6phar.readonly=0
7--FILE--
8<?php
9$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
10$pname = 'phar://' . $fname;
11$fname2 = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.tar';
12
13$a = new Phar($fname);
14$a['index.php'] = '<?php
15Phar::mount("testit", "' . addslashes(__FILE__) . '");
16try {
17Phar::mount("testit", "' . addslashes(__FILE__) . '");
18} catch (Exception $e) {
19echo $e->getMessage() . "\n";
20}
21try {
22Phar::mount("' . addslashes($pname) . '/testit1", "' . addslashes(__FILE__) . '");
23} catch (Exception $e) {
24echo $e->getMessage() . "\n";
25}
26?>';
27$a->setStub('<?php
28set_include_path("phar://" . __FILE__);
29include "index.php";
30__HALT_COMPILER();');
31Phar::mount($pname . '/testit1', __FILE__);
32include $fname;
33// test copying of a phar with mounted entries
34$b = $a->convertToExecutable(Phar::TAR);
35$b->setStub('<?php
36set_include_path("phar://" . __FILE__);
37include "index.php";
38__HALT_COMPILER();');
39try {
40include $fname2;
41} catch (Exception $e) {
42echo $e->getMessage(),"\n";
43}
44try {
45Phar::mount($pname . '/oops', '/home/oops/../../etc/passwd:');
46} catch (Exception $e) {
47echo $e->getMessage(),"\n";
48}
49Phar::mount($pname . '/testit2', $pname . '/testit1');
50echo substr($a['testit2']->getContent(),0, 50),"\n";
51?>
52--CLEAN--
53<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
54<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.tar'); ?>
55--EXPECTF--
56Mounting of testit to %sphar_mount.php within phar %sphar_mount.phar.php failed
57Can only mount internal paths within a phar archive, use a relative path instead of "phar://%sphar_mount.phar.php/testit1"
58Mounting of testit to %sphar_mount.php within phar %sphar_mount.phar.tar failed
59Mounting of /oops to /home/oops/../../etc/passwd: within phar %sphar_mount.phar.php failed
60<?php
61$fname = dirname(__FILE__) . '/' . basename(
62