phar_mount.phpt 1.9 KB

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