From: Arnaud Le Blanc Date: Thu, 28 May 2009 13:26:52 +0000 (+0000) Subject: MFH: New tests X-Git-Tag: php-5.2.10RC2~68 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7055f3bae54be99cc8f6c8158117c24b2ad41264;p=php MFH: New tests --- diff --git a/ext/standard/tests/http/bug38802.phpt b/ext/standard/tests/http/bug38802.phpt new file mode 100644 index 0000000000..91fd1cce9d --- /dev/null +++ b/ext/standard/tests/http/bug38802.phpt @@ -0,0 +1,172 @@ +--TEST-- +Bug #38802 (ignore_errors and max_redirects) +--SKIPIF-- + +--FILE-- + $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.", + ); + + $pid = http_server("tcp://127.0.0.1:12342", $responses, $output); + + $fd = fopen('http://127.0.0.1:12342/foo/bar', '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)); + } + + fseek($output, 0, SEEK_SET); + var_dump(stream_get_contents($output)); + + http_server_kill($pid); +} + +echo "-- Test: follow all redirections --\n"; + +do_test(array(), 4); + +echo "-- Test: fail after 2 redirections --\n"; + +do_test(array('max_redirects' => 2), 2); + +echo "-- Test: fail at first redirection --\n"; + +do_test(array('max_redirects' => 0), 1); + +echo "-- Test: fail at first redirection (2) --\n"; + +do_test(array('max_redirects' => 1), 1); + +echo "-- Test: return at first redirection --\n"; + +do_test(array('max_redirects' => 0, 'ignore_errors' => 1), 1); + +echo "-- Test: return at first redirection (2) --\n"; + +do_test(array('max_redirects' => 1, 'ignore_errors' => 1), 1); + +echo "-- Test: return at second redirection --\n"; + +do_test(array('max_redirects' => 2, 'ignore_errors' => 1), 2); + +?> +--EXPECTF-- +-- Test: follow all redirections -- +resource(%d) of type (stream) +array(7) { + [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(5) "done." +string(195) "GET /foo/bar HTTP/1.0 +Host: 127.0.0.1:12342 + +GET /foo/bar2 HTTP/1.0 +Host: 127.0.0.1:12342 + +GET /foo/bar3 HTTP/1.0 +Host: 127.0.0.1:12342 + +GET /foo/bar4 HTTP/1.0 +Host: 127.0.0.1:12342 + +" +-- 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 +bool(false) +string(97) "GET /foo/bar HTTP/1.0 +Host: 127.0.0.1:12342 + +GET /foo/bar2 HTTP/1.0 +Host: 127.0.0.1:12342 + +" +-- 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 +bool(false) +string(48) "GET /foo/bar HTTP/1.0 +Host: 127.0.0.1:12342 + +" +-- 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 +bool(false) +string(48) "GET /foo/bar HTTP/1.0 +Host: 127.0.0.1:12342 + +" +-- Test: return at first redirection -- +resource(%d) of type (stream) +array(2) { + [0]=> + string(30) "HTTP/1.0 302 Moved Temporarily" + [1]=> + string(41) "Location: http://127.0.0.1:12342/foo/bar2" +} +string(1) "1" +string(48) "GET /foo/bar HTTP/1.0 +Host: 127.0.0.1:12342 + +" +-- Test: return at first redirection (2) -- +resource(%d) of type (stream) +array(2) { + [0]=> + string(30) "HTTP/1.0 302 Moved Temporarily" + [1]=> + string(41) "Location: http://127.0.0.1:12342/foo/bar2" +} +string(1) "1" +string(48) "GET /foo/bar HTTP/1.0 +Host: 127.0.0.1:12342 + +" +-- Test: return at second redirection -- +resource(%d) of type (stream) +array(4) { + [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(0) "" +string(97) "GET /foo/bar HTTP/1.0 +Host: 127.0.0.1:12342 + +GET /foo/bar2 HTTP/1.0 +Host: 127.0.0.1:12342 + +" diff --git a/ext/standard/tests/http/ignore_errors.phpt b/ext/standard/tests/http/ignore_errors.phpt new file mode 100644 index 0000000000..c7e1acbfe7 --- /dev/null +++ b/ext/standard/tests/http/ignore_errors.phpt @@ -0,0 +1,124 @@ +--TEST-- +http:// and ignore_errors +--SKIPIF-- + +--FILE-- + $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", + ); + + $pid = http_server("tcp://127.0.0.1:12342", $responses, $output); + + foreach($responses as $r) { + + $fd = fopen('http://127.0.0.1:12342/foo/bar', '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)); + } + + fseek($output, 0, SEEK_SET); + var_dump(stream_get_contents($output)); + fseek($output, 0, SEEK_SET); + } + + http_server_kill($pid); +} + +echo "-- Test: requests without ignore_errors --\n"; + +do_test(array()); + +echo "-- Test: requests with ignore_errors --\n"; + +do_test(array('ignore_errors' => true)); + +echo "-- Test: requests with ignore_errors (2) --\n"; + +do_test(array('ignore_errors' => 1)); + +?> +--EXPECTF-- +-- Test: requests without ignore_errors -- +resource(%d) of type (stream) +array(2) { + [0]=> + string(15) "HTTP/1.0 200 Ok" + [1]=> + string(10) "X-Foo: bar" +} +string(1) "1" +string(48) "GET /foo/bar HTTP/1.0 +Host: 127.0.0.1:12342 + +" + +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 +bool(false) +string(48) "GET /foo/bar HTTP/1.0 +Host: 127.0.0.1:12342 + +" +-- Test: requests with ignore_errors -- +resource(%d) of type (stream) +array(2) { + [0]=> + string(15) "HTTP/1.0 200 Ok" + [1]=> + string(10) "X-Foo: bar" +} +string(1) "1" +string(48) "GET /foo/bar HTTP/1.0 +Host: 127.0.0.1:12342 + +" +resource(%d) of type (stream) +array(2) { + [0]=> + string(22) "HTTP/1.0 404 Not found" + [1]=> + string(10) "X-bar: baz" +} +string(1) "2" +string(48) "GET /foo/bar HTTP/1.0 +Host: 127.0.0.1:12342 + +" +-- Test: requests with ignore_errors (2) -- +resource(%d) of type (stream) +array(2) { + [0]=> + string(15) "HTTP/1.0 200 Ok" + [1]=> + string(10) "X-Foo: bar" +} +string(1) "1" +string(48) "GET /foo/bar HTTP/1.0 +Host: 127.0.0.1:12342 + +" +resource(%d) of type (stream) +array(2) { + [0]=> + string(22) "HTTP/1.0 404 Not found" + [1]=> + string(10) "X-bar: baz" +} +string(1) "2" +string(48) "GET /foo/bar HTTP/1.0 +Host: 127.0.0.1:12342 + +" diff --git a/ext/standard/tests/http/server.inc b/ext/standard/tests/http/server.inc new file mode 100644 index 0000000000..b9ade0e9f0 --- /dev/null +++ b/ext/standard/tests/http/server.inc @@ -0,0 +1,92 @@ + 0) { + stream_copy_to_stream($sock, $output, $content_length); + } + + // send response + + $fd = fopen($file, 'rb'); + stream_copy_to_stream($fd, $sock); + + fclose($sock); + } + + exit(0); +} + +function http_server_kill($pid) { + posix_kill($pid, SIGTERM); + pcntl_waitpid($pid, $status); +} + +?>