]> granicus.if.org Git - php/commitdiff
- Fix test, add a couple of new ones
authorSteph Fox <sfox@php.net>
Thu, 15 May 2008 12:37:45 +0000 (12:37 +0000)
committerSteph Fox <sfox@php.net>
Thu, 15 May 2008 12:37:45 +0000 (12:37 +0000)
@Greg: it seems we covered it already ;)

ext/phar/tests/phar_extract2.phpt [new file with mode: 0644]
ext/phar/tests/phar_offset_check.phpt [new file with mode: 0644]
ext/phar/tests/tar/phar_convert_phar3.phpt

diff --git a/ext/phar/tests/phar_extract2.phpt b/ext/phar/tests/phar_extract2.phpt
new file mode 100644 (file)
index 0000000..bb7f5bc
--- /dev/null
@@ -0,0 +1,80 @@
+--TEST--
+Phar: Phar::extractTo() - .phar safety
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--INI--
+phar.readonly=0
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/tempmanifest2.phar.php';
+$pname = 'phar://' . $fname;
+
+$phar = new Phar($fname);
+$phar->setDefaultStub();
+$phar->setAlias('fred');
+$phar['file1.txt'] = 'hi';
+$phar['file2.txt'] = 'hi2';
+$phar['subdir/ectory/file.txt'] = 'hi3';
+$phar->mount($pname . '/mount', __FILE__);
+$phar->addEmptyDir('one/level');
+
+$phar->extractTo(dirname(__FILE__) . '/extract', 'mount');
+$phar->extractTo(dirname(__FILE__) . '/extract');
+$out = array();
+
+foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__FILE__) . '/extract'), RecursiveIteratorIterator::CHILD_FIRST) as $path => $file) {
+       $extracted[] = $path;
+}
+
+sort($extracted);
+
+foreach ($extracted as $out) {
+       echo "$out\n";
+}
+
+$variations = array('phar', '.phar', '/phar', '/.phar', '.phar/stub.php', '.phar/alias.txt', '/stub.php', '/alias.txt', 'stub.php', 'alias.txt');
+
+foreach ($variations as $var) {
+       try {
+               $phar->extractTo(dirname(__FILE__) . '/extract1', $var);
+       } catch (Exception $e) {
+               echo $e->getMessage()."\n";
+       }
+}
+
+?>
+===DONE===
+--CLEAN--
+<?php
+@unlink(dirname(__FILE__) . '/tempmanifest2.phar.php');
+$dir = dirname(__FILE__) . '/extract/';
+@unlink($dir . 'file1.txt');
+@unlink($dir . 'file2.txt');
+@unlink($dir . 'subdir/ectory/file.txt');
+@rmdir($dir . 'subdir/ectory');
+@rmdir($dir . 'subdir');
+@rmdir($dir . 'one/level');
+@rmdir($dir . 'one');
+@rmdir($dir);
+$dir = dirname(__FILE__) . '/extract1/';
+@rmdir($dir);
+?>
+--EXPECTF--
+%sextract%cfile1.txt
+%sextract\file2.txt
+%sextract\one
+%sextract\subdir
+%sextract\subdir\ectory
+%sextract\subdir\ectory\file.txt
+Phar Error: attempted to extract non-existent file "phar" from phar "%stempmanifest2.phar.php"
+Phar Error: attempted to extract non-existent file ".phar" from phar "%stempmanifest2.phar.php"
+Phar Error: attempted to extract non-existent file "/phar" from phar "%stempmanifest2.phar.php"
+Phar Error: attempted to extract non-existent file "/.phar" from phar "%stempmanifest2.phar.php"
+Phar Error: attempted to extract non-existent file ".phar/stub.php" from phar "%stempmanifest2.phar.php"
+Phar Error: attempted to extract non-existent file ".phar/alias.txt" from phar "%stempmanifest2.phar.php"
+Phar Error: attempted to extract non-existent file "/stub.php" from phar "%stempmanifest2.phar.php"
+Phar Error: attempted to extract non-existent file "/alias.txt" from phar "%stempmanifest2.phar.php"
+Phar Error: attempted to extract non-existent file "stub.php" from phar "%stempmanifest2.phar.php"
+Phar Error: attempted to extract non-existent file "alias.txt" from phar "%stempmanifest2.phar.php"
+===DONE===
diff --git a/ext/phar/tests/phar_offset_check.phpt b/ext/phar/tests/phar_offset_check.phpt
new file mode 100644 (file)
index 0000000..279b359
--- /dev/null
@@ -0,0 +1,76 @@
+--TEST--
+Phar: disallow stub and alias setting via offset*() methods
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
+--INI--
+phar.readonly=0
+phar.require_hash=1
+--FILE--
+<?php
+
+$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
+$pname = 'phar://'.$fname;
+
+$phar = new Phar($fname);
+$phar->setDefaultStub();
+$phar->setAlias('susan');
+$phar['a.txt'] = "first file\n";
+$phar['b.txt'] = "second file\n";
+
+try {
+       $phar->offsetGet('.phar/stub.php');
+} catch (Exception $e) {
+       echo $e->getMessage()."\n";
+}
+
+try {
+       $phar->offsetGet('.phar/alias.txt');
+} catch (Exception $e) {
+       echo $e->getMessage()."\n";
+}
+
+try {
+       $phar->offsetSet('.phar/stub.php', '<?php __HALT_COMPILER(); ?>');
+} catch (Exception $e) {
+       echo $e->getMessage()."\n";
+}
+
+var_dump(strlen($phar->getStub()));
+
+try {
+       $phar->offsetUnset('.phar/stub.php');
+} catch (Exception $e) {
+       echo $e->getMessage()."\n";
+}
+
+var_dump(strlen($phar->getStub()));
+
+try {
+       $phar->offsetSet('.phar/alias.txt', 'dolly');
+} catch (Exception $e) {
+       echo $e->getMessage()."\n";
+}
+
+var_dump($phar->getAlias());
+
+try {
+       $phar->offsetUnset('.phar/alias.txt');
+} catch (Exception $e) {
+       echo $e->getMessage()."\n";
+}
+
+var_dump($phar->getAlias());
+
+?>
+===DONE===
+--CLEAN--
+<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
+--EXPECT--
+Entry .phar/stub.php does not exist
+Entry .phar/alias.txt does not exist
+int(6661)
+int(6661)
+string(5) "susan"
+string(5) "susan"
+===DONE===
index f4768194d1c2e030043049bc0eb4529250e21690..a90a497ee753c18ed8208ff5a00371a86431a6b4 100644 (file)
@@ -49,14 +49,14 @@ __HALT_COMPILER();
 ?>
 --EXPECT--
 bool(false)
-int(6651)
+int(6659)
 bool(true)
 string(60) "<?php // tar-based phar archive stub file
 __HALT_COMPILER();"
 bool(true)
 int(8192)
-int(6651)
+int(6659)
 bool(true)
 bool(true)
-int(6651)
+int(6659)
 ===DONE===