Patch http_test for Testing related Bug #60502
Patch version 2011-12-12 19:35 UTC
Return to Bug #60502 |
Download this patch
Patch Revisions:
Developer: mattficken
Index: bug53198.phpt
===================================================================
--- bug53198.phpt (revision 320815)
+++ bug53198.phpt (working copy)
@@ -1,57 +1,59 @@
---TEST--
-Bug #53198 (From: header cannot be changed with ini_set)
---SKIPIF--
-<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
---INI--
-allow_url_fopen=1
-from=teste@teste.pt
---FILE--
-<?php
-require 'server.inc';
-
-function do_test() {
-
- $responses = array(
- "data://text/plain,HTTP/1.0 200 OK\r\n\r\n",
- );
-
- $pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
-
- foreach($responses as $r) {
-
- $fd = fopen('http://127.0.0.1:12342/', 'rb', false);
-
- fseek($output, 0, SEEK_SET);
- var_dump(stream_get_contents($output));
- fseek($output, 0, SEEK_SET);
- }
-
- http_server_kill($pid);
-
-}
-
-echo "-- Test: leave default --\n";
-
-do_test();
-
-echo "-- Test: after ini_set --\n";
-
-ini_set('from', 'junk@junk.com');
-
-do_test();
-
-?>
---EXPECT--
--- Test: leave default --
-string(63) "GET / HTTP/1.0
-From: teste@teste.pt
-Host: 127.0.0.1:12342
-
-"
--- Test: after ini_set --
-string(62) "GET / HTTP/1.0
-From: junk@junk.com
-Host: 127.0.0.1:12342
-
-"
-
+--TEST--
+Bug #53198 (From: header cannot be changed with ini_set)
+--SKIPIF--
+<?php require 'server.inc'; http_server_skipif('tcp://127.0.0.1:12342'); ?>
+--INI--
+from=teste@teste.pt
+--FILE--
+<?php
+require 'server.inc';
+
+function do_test() {
+
+ $responses = responses_bug53198();
+
+ $pid = http_server('bug53198', "tcp://127.0.0.1:12342", $responses, $output);
+
+ $iter = 0;
+ foreach($responses as $r) {
+
+ $fd = fopen(get_local_remote_url('http://127.0.0.1:12342/', 'bug53918', $iter), 'rb', false);
+
+ //fseek($output, 0, SEEK_SET);
+ stream_get_contents($fd);
+ var_dump($http_response_header);
+ //fseek($output, 0, SEEK_SET);
+
+ $iter++;
+ }
+
+ http_server_kill($pid);
+
+}
+
+echo "-- Test: leave default --\n";
+
+do_test();
+
+echo "-- Test: after ini_set --\n";
+
+ini_set('from', 'junk@junk.com');
+
+do_test();
+
+?>
+--EXPECTF--
+-- Test: leave default --
+string(%d) "GET %A HTTP/1.%A
+From: teste@teste.pt
+Host: %A
+
+"
+-- Test: after ini_set --
+string(%d) "GET %A HTTP/1.%A
+From: junk@junk.com%A
+Host: %A
+
+"
+
+=======
Index: bug43510.phpt
===================================================================
--- bug43510.phpt (revision 320815)
+++ bug43510.phpt (working copy)
@@ -8,18 +8,18 @@
<?php
require 'server.inc';
-$responses = array(
- "data://text/plain,HTTP/1.0 200 OK\r\n\r\n",
- "data://text/plain,HTTP/1.0 200 OK\r\n\r\n",
-);
+$responses = responses_bug43510();
-$pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
+$pid = http_server('bug43510', "tcp://127.0.0.1:12342", $responses, $output);
+$iter = 0;
foreach(array('r', 'rb') as $mode) {
- $fd = fopen('http://127.0.0.1:12342/', $mode, false);
+ $fd = fopen(get_local_remote_url('http://127.0.0.1:12342/', 'bug43510', $iter), $mode, false);
$meta = stream_get_meta_data($fd);
var_dump($meta['mode']);
fclose($fd);
+
+ $iter++;
}
http_server_kill($pid);
Index: bug48929.phpt
===================================================================
--- bug48929.phpt (revision 320815)
+++ bug48929.phpt (working copy)
@@ -12,19 +12,19 @@
$context = stream_context_create(array('http' => $context_options));
- $responses = array(
- "data://text/plain,HTTP/1.0 200 OK\r\n\r\n",
- );
+ $responses = responses_bug48929();
- $pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
+ $pid = http_server('bug48929', "tcp://127.0.0.1:12342", $responses, $output);
+ $iter = 0;
foreach($responses as $r) {
- $fd = fopen('http://127.0.0.1:12342/', 'rb', false, $context);
+ $fd = fopen(get_local_remote_url('http://127.0.0.1:12342/', 'bug48929', $iter), 'rb', false, $context);
- fseek($output, 0, SEEK_SET);
- var_dump(stream_get_contents($output));
- fseek($output, 0, SEEK_SET);
+ stream_get_contents($fd);
+ var_dump($http_response_header);
+
+ $iter++;
}
http_server_kill($pid);
@@ -39,20 +39,8 @@
do_test(array('header' => "X-Foo: bar\r\nContent-Type: text/plain", 'method' => 'POST', 'content' => 'ohai'));
?>
---EXPECT--
+--EXPECTF--
-- Test: requests with 'header' as array --
-string(103) "POST / HTTP/1.0
-Host: 127.0.0.1:12342
-Content-Length: 4
-X-Foo: bar
-Content-Type: text/plain
-
-ohai"
+%A
-- Test: requests with 'header' as string --
-string(103) "POST / HTTP/1.0
-Host: 127.0.0.1:12342
-Content-Length: 4
-X-Foo: bar
-Content-Type: text/plain
-
-ohai"
+%A
\ No newline at end of file
Index: ignore_errors.phpt
===================================================================
--- ignore_errors.phpt (revision 320815)
+++ ignore_errors.phpt (working copy)
@@ -12,28 +12,31 @@
$context = stream_context_create(array('http' => $context_options));
- $responses = array(
- "data://text/plain,HTTP/1.0 200 Ok\r\nX-Foo: bar\r\n\r\n1",
- "data://text/plain,HTTP/1.0 404 Not found\r\nX-bar: baz\r\n\r\n2",
- );
+ $responses = responses_ignore_errors();
- $pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
+ $pid = http_server('ignore_errors.phpt', "tcp://127.0.0.1:12342", $responses, $output);
+ $iter = 0;
foreach($responses as $r) {
- $fd = fopen('http://127.0.0.1:12342/foo/bar', 'rb', false, $context);
+ $fd = fopen(get_local_remote_url('http://127.0.0.1:12342/foo/bar', 'ignore_errors', $iter), 'rb', false, $context);
var_dump($fd);
if ($fd) {
+ //prep($fd);
$meta_data = stream_get_meta_data($fd);
var_dump($meta_data['wrapper_data']);
- var_dump(stream_get_contents($fd));
+ stream_get_contents($fd);
+ //echo get_out_data();
+ var_dump($http_response_header);
}
+
+ //fseek($output, 0, SEEK_SET);
+ //var_dump(stream_get_contents($output));
+ //fseek($output, 0, SEEK_SET);
- fseek($output, 0, SEEK_SET);
- var_dump(stream_get_contents($output));
- fseek($output, 0, SEEK_SET);
+ $iter++;
}
http_server_kill($pid);
@@ -55,72 +58,72 @@
--EXPECTF--
-- Test: requests without ignore_errors --
resource(%d) of type (stream)
-array(2) {
+array(%d) {
[0]=>
- string(15) "HTTP/1.0 200 Ok"
- [1]=>
- string(10) "X-Foo: bar"
+ string(15) "HTTP/1.%d 200 Ok"%A
+ [%d]=>%A
+ string(10) "X-Foo: bar"%A
}
string(1) "1"
-string(48) "GET /foo/bar HTTP/1.0
-Host: 127.0.0.1:12342
+string(%d) "GET %A HTTP/1.%A
+Host: %A
"
-Warning: fopen(http://127.0.0.1:12342/foo/bar): failed to open stream: HTTP request failed! HTTP/1.0 404 Not found
- in %s on line %d
+Warning: fopen(%A): failed to open stream: HTTP request failed! HTTP/1.%d 404 Not found %A in %s on line %d
bool(false)
-string(48) "GET /foo/bar HTTP/1.0
-Host: 127.0.0.1:12342
+string(%d) "GET %A HTTP/1.%A
+Host: %A
"
-- Test: requests with ignore_errors --
resource(%d) of type (stream)
-array(2) {
+array(%d) {
[0]=>
- string(15) "HTTP/1.0 200 Ok"
- [1]=>
- string(10) "X-Foo: bar"
+ string(15) "HTTP/1.%d 200 Ok"%A
+ [%d]=>%A
+ string(10) "X-Foo: bar"%A
}
string(1) "1"
-string(48) "GET /foo/bar HTTP/1.0
-Host: 127.0.0.1:12342
+string(%d) "GET %A HTTP/1.%A
+Host: %A
"
resource(%d) of type (stream)
-array(2) {
+array(%d) {
[0]=>
- string(22) "HTTP/1.0 404 Not found"
- [1]=>
- string(10) "X-bar: baz"
+ string(22) "HTTP/1.%d 404 Not found"%A
+ [%d]=>%A
+ string(10) "X-bar: baz"%A
}
string(1) "2"
-string(48) "GET /foo/bar HTTP/1.0
-Host: 127.0.0.1:12342
+string(%d) "GET %A HTTP/1.%A
+Host: %A
"
-- Test: requests with ignore_errors (2) --
resource(%d) of type (stream)
-array(2) {
+array(%d) {
[0]=>
- string(15) "HTTP/1.0 200 Ok"
- [1]=>
- string(10) "X-Foo: bar"
+ string(15) "HTTP/1.%d 200 Ok"%A
+ [%d]=>%A
+ string(10) "X-Foo: bar"%A
}
string(1) "1"
-string(48) "GET /foo/bar HTTP/1.0
-Host: 127.0.0.1:12342
+string(48) "GET %A HTTP/1.%A
+Host: %A
"
resource(%d) of type (stream)
-array(2) {
+array(%d) {
[0]=>
- string(22) "HTTP/1.0 404 Not found"
- [1]=>
- string(10) "X-bar: baz"
+ string(22) "HTTP/1.%d 404 Not found"
+ [%d]=>%A
+ string(10) "X-bar: baz"%A
}
string(1) "2"
-string(48) "GET /foo/bar HTTP/1.0
-Host: 127.0.0.1:12342
+string(48) "GET /foo/bar HTTP/1.%A
+Host: 127.0.0.1:12342%A
"
+
Index: bug38802.phpt
===================================================================
--- bug38802.phpt (revision 320815)
+++ bug38802.phpt (working copy)
@@ -12,27 +12,23 @@
$context = stream_context_create(array('http' => $context_options));
- $responses = array(
- "data://text/plain,HTTP/1.0 302 Moved Temporarily\r\nLocation: http://127.0.0.1:12342/foo/bar2\r\n\r\n1",
- "data://text/plain,HTTP/1.0 301 Moved Permanently\r\nLocation: http://127.0.0.1:12342/foo/bar3\r\n\r\n",
- "data://text/plain,HTTP/1.0 302 Moved Temporarily\r\nLocation: http://127.0.0.1:12342/foo/bar4\r\n\r\n3",
- "data://text/plain,HTTP/1.0 200 OK\r\n\r\ndone.",
- );
+ $responses = responses_bug38802();
- $pid = http_server("tcp://127.0.0.1:12342", $responses, $output);
+ $pid = http_server('bug38802', "tcp://127.0.0.1:12342", $responses, $output);
- $fd = fopen('http://127.0.0.1:12342/foo/bar', 'rb', false, $context);
+ $fd = fopen(get_local_remote_url('http://127.0.0.1:12342/foo/bar', 'bug38802', 0), 'rb', false, $context);
var_dump($fd);
if ($fd) {
$meta_data = stream_get_meta_data($fd);
var_dump($meta_data['wrapper_data']);
- var_dump(stream_get_contents($fd));
+ stream_get_contents($fd);
+ var_dump($http_response_header);
}
- fseek($output, 0, SEEK_SET);
- var_dump(stream_get_contents($output));
+ //fseek($output, 0, SEEK_SET);
+ //var_dump(stream_get_contents($output));
http_server_kill($pid);
}
@@ -69,106 +65,106 @@
--EXPECTF--
-- Test: follow all redirections --
resource(%d) of type (stream)
-array(7) {
+array(%d) {
[0]=>
- string(30) "HTTP/1.0 302 Moved Temporarily"
- [1]=>
- string(41) "Location: http://127.0.0.1:12342/foo/bar2"
- [2]=>
- string(30) "HTTP/1.0 301 Moved Permanently"
- [3]=>
- string(41) "Location: http://127.0.0.1:12342/foo/bar3"
- [4]=>
- string(30) "HTTP/1.0 302 Moved Temporarily"
- [5]=>
- string(41) "Location: http://127.0.0.1:12342/foo/bar4"
- [6]=>
- string(15) "HTTP/1.0 200 OK"
+ string(30) "HTTP/1.%d 302 Moved Temporarily"%A
+ [%d]=>
+ string(%d) "Location: http://%A"%A
+ [%d]=>
+ string(%d) "HTTP/1.%d 301 Moved Permanently"%A
+ [%d]=>
+ string(%d) "Location: http://%A"%A
+ [%d]=>
+ string(%d) "HTTP/1.%d 302 Moved Temporarily"%A
+ [%d]=>
+ string(%d) "Location: http://%A"%A
+ [%d]=>
+ string(15) "HTTP/1.%d 200 OK"%A
}
string(5) "done."
-string(195) "GET /foo/bar HTTP/1.0
-Host: 127.0.0.1:12342
+string(%s) "GET %A HTTP/1.%A
+Host: %A
-GET /foo/bar2 HTTP/1.0
-Host: 127.0.0.1:12342
+GET %A HTTP/1.%A
+Host: %A
-GET /foo/bar3 HTTP/1.0
-Host: 127.0.0.1:12342
+GET %A HTTP/1.%A
+Host: %A
-GET /foo/bar4 HTTP/1.0
-Host: 127.0.0.1:12342
+GET %A HTTP/1.%A
+Host: %A
"
-- Test: fail after 2 redirections --
-Warning: fopen(http://127.0.0.1:12342/foo/bar): failed to open stream: Redirection limit reached, aborting in %s
+Warning: fopen(http://%A): failed to open stream: Redirection limit reached, aborting in %s
bool(false)
-string(97) "GET /foo/bar HTTP/1.0
-Host: 127.0.0.1:12342
+string(%d) "GET %A HTTP/1.%A
+Host: %A
-GET /foo/bar2 HTTP/1.0
-Host: 127.0.0.1:12342
+GET %A HTTP/1.%A
+Host: %A
"
-- Test: fail at first redirection --
-Warning: fopen(http://127.0.0.1:12342/foo/bar): failed to open stream: Redirection limit reached, aborting in %s
+Warning: fopen(http://%A): failed to open stream: Redirection limit reached, aborting in %s
bool(false)
-string(48) "GET /foo/bar HTTP/1.0
-Host: 127.0.0.1:12342
+string(%d) "GET %A HTTP/1.%A
+Host: %A
"
-- Test: fail at first redirection (2) --
-Warning: fopen(http://127.0.0.1:12342/foo/bar): failed to open stream: Redirection limit reached, aborting in %s
+Warning: fopen(http://%A): failed to open stream: Redirection limit reached, aborting in %s
bool(false)
-string(48) "GET /foo/bar HTTP/1.0
-Host: 127.0.0.1:12342
+string(%d) "GET %A HTTP/1.%A
+Host: %A
"
-- Test: return at first redirection --
resource(%d) of type (stream)
-array(2) {
+array(%d) {
[0]=>
- string(30) "HTTP/1.0 302 Moved Temporarily"
- [1]=>
- string(41) "Location: http://127.0.0.1:12342/foo/bar2"
+ string(30) "HTTP/1.%d 302 Moved Temporarily"%A
+ [%d]=>
+ string(%d) "Location: http://%A"%A
}
string(1) "1"
-string(48) "GET /foo/bar HTTP/1.0
-Host: 127.0.0.1:12342
+string(%d) "GET %A HTTP/1.%A
+Host: %A
"
-- Test: return at first redirection (2) --
resource(%d) of type (stream)
-array(2) {
+array(%d) {
[0]=>
- string(30) "HTTP/1.0 302 Moved Temporarily"
- [1]=>
- string(41) "Location: http://127.0.0.1:12342/foo/bar2"
+ string(30) "HTTP/1.%d 302 Moved Temporarily"%A
+ [%d]=>
+ string(%d) "Location: http://%A"%A
}
string(1) "1"
-string(48) "GET /foo/bar HTTP/1.0
-Host: 127.0.0.1:12342
+string(%d) "GET %A HTTP/1.%A
+Host: %A
"
-- Test: return at second redirection --
resource(%d) of type (stream)
-array(4) {
+array(%d) {
[0]=>
- string(30) "HTTP/1.0 302 Moved Temporarily"
- [1]=>
- string(41) "Location: http://127.0.0.1:12342/foo/bar2"
- [2]=>
- string(30) "HTTP/1.0 301 Moved Permanently"
- [3]=>
- string(41) "Location: http://127.0.0.1:12342/foo/bar3"
+ string(30) "HTTP/1.%d 302 Moved Temporarily"%A
+ [%d]=>
+ string(%d) "Location: http://%A"%A
+ [%d]=>
+ string(30) "HTTP/1.%d 301 Moved Permanently"%A
+ [%d]=>
+ string(%d) "Location: http://%A"%A
}
string(0) ""
-string(97) "GET /foo/bar HTTP/1.0
-Host: 127.0.0.1:12342
+string(%d) "GET %A HTTP/1.%A
+Host: %A
-GET /foo/bar2 HTTP/1.0
-Host: 127.0.0.1:12342
+GET %A HTTP/1.%A
+Host: %A
"
Index: server.inc
===================================================================
--- server.inc (revision 320815)
+++ server.inc (working copy)
@@ -1,20 +1,125 @@
<?php
+require 'responses.inc';
+$out_data = '';
+function get_out_data() {
+ global $out_data;
+ return fgets($out_data);
+}
+
+class strtoupper_filter extends php_user_filter {
+ function filter($in, $out, &$consumed, $closing)
+ {
+ global $out_data;
+
+ while ($bucket = stream_bucket_make_writeable($in)) {
+ //$bucket->data = strtoupper($bucket->data);
+ //$out_data += $bucket->data;
+
+ $consumed += $bucket->datalen;
+ stream_bucket_append($out, $bucket);
+ stream_bucket_make_writeable($out, $bucket);
+ }
+ return PSFS_PASS_ON;
+ }
+}
+
+/* Register our filter with PHP */
+stream_filter_register("strtoupper", "strtoupper_filter")
+ or die("Failed to register filter");
+
+function prep($fp) {
+ global $out_data;
+ $out_data = stream_bucket_new();
+
+ stream_filter_append($fp, "strtoupper");
+}
+
+
+
function http_server_skipif($socket_string) {
+ if (substr(PHP_OS, 0, 3) != 'WIN' ) {
+ if (!function_exists('pcntl_fork')) die('skip pcntl_fork() not available');
+ if (!function_exists('posix_kill')) die('skip posix_kill() not available');
+ if (!stream_socket_server($socket_string)) die('skip stream_socket_server() failed');
+ }
+}
- if (!function_exists('pcntl_fork')) die('skip pcntl_fork() not available');
- if (!function_exists('posix_kill')) die('skip posix_kill() not available');
- if (!stream_socket_server($socket_string)) die('skip stream_socket_server() failed');
+function windows_http_server($bug, $socket_string, array $files, &$output = null) {
+ global $server_running;
+ if ($server_running) {
+ return;
+ }
+
+ // $socket_string contains hostname and port, but is prefixed by tcp://
+ if (substr($socket_string, 0, strlen("tcp://"))=="tcp://") {
+ $socket_string = substr($socket_string, strlen("tcp://"));
+ //
+ // example value
+ //
+ // $socket_string = "127.0.0.1:12342"
+ }
+
+ $php = getenv('TEST_PHP_EXECUTABLE');
+
+ $server_running = true;
+
+ // launch builtin php web server in
+ // (so rest of PHPT can execute while web server is running)
+ //
+ //
+
+ // this directory (where server.inc, router*.php are stored)
+ $dir = dirname(__FILE__);
+
+ $cmd = "$php -S $socket_string $dir\\router_$bug.php";
+
+ $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"));
+
+ $cwd = $dir;
+
+ $env = array();
+
+ $process = proc_open($cmd, $descriptorspec, $pipes, $cwd, $env);
+
+ // while process is running, return and keep working
+ // (keep working while web server is still running)
+ $GLOBALS['webserver_process'] = $process;
+
+ return $socket_string;
}
+$webserver_process = NULL;
+$server_running = false;
+function windows_stop_http_server($socket_string) {
+
+ $process = $GLOBALS['webserver_process'];
+ // terminate and check recursively until it terminates
+ while (true) {
+ proc_terminate($process);
+
+ $stat = proc_get_status($process);
+ if ( $stat == FALSE or $stat['running']==FALSE) {
+ break;
+ }
+ }
+
+
+}
+
/* Minimal HTTP server with predefined responses.
*
* $socket_string is the socket to create and listen on (e.g. tcp://127.0.0.1:1234)
* $files is an array of files containing N responses for N expected requests. Server dies after N requests.
* $output is a stream on which everything sent by clients is written to
*/
-function http_server($socket_string, array $files, &$output = null) {
-
+function http_server($bug, $socket_string, array $files, &$output = null) {
+ if (is_server_remote()) {
+ // is requesting page on IIS, Apache, etc...
+ return 0;
+ } else if (substr(PHP_OS, 0, 3) == 'WIN' ) {
+ return windows_http_server($bug, $socket_string, $files);//, &$output);
+ }
pcntl_alarm(60);
$server = stream_socket_server($socket_string, $errno, $errstr);
@@ -85,6 +190,13 @@
}
function http_server_kill($pid) {
+ if (is_server_remote()) {
+ // is requesting page on IIS, Apache, etc...
+ return;
+ } else if (substr(PHP_OS, 0, 3) == 'WIN' ) {
+ windows_stop_http_server($pid);
+ return;
+ }
posix_kill($pid, SIGTERM);
pcntl_waitpid($pid, $status);
}
|