xref: /PHP-5.6/ext/soap/tests/bug73037.phpt (revision 256b150a)
1--TEST--
2Bug #73037 SoapServer reports Bad Request when gzipped, var 0
3--SKIPIF--
4<?php
5	require_once('skipif.inc');
6	if (!extension_loaded("zlib")) {
7		echo "skip zlib is required for this test";
8	}
9
10	if (!file_exists(dirname(__FILE__) . "/../../../sapi/cli/tests/php_cli_server.inc")) {
11		echo "skip sapi/cli/tests/php_cli_server.inc required but not found";
12	}
13?>
14--FILE--
15<?php
16
17include dirname(__FILE__) . "/../../../sapi/cli/tests/php_cli_server.inc";
18
19function get_data($max)
20{
21	$piece = "<CD>
22		<TITLE>Empire Burlesque</TITLE>
23		<ARTIST>Bob Dylan</ARTIST>
24		<COUNTRY>USA</COUNTRY>
25		<COMPANY>Columbia</COMPANY>
26		<PRICE>10.90</PRICE>
27		<YEAR>1985</YEAR>
28	</CD>";
29
30	$begin = '<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><CATALOG>';
31	$end = '</CATALOG></soapenv:Body></soapenv:Envelope>';
32
33	$min = strlen($begin) + strlen($piece) + strlen($end);
34	$max = $max < $min ? $min : $max;
35
36	$data = $begin;
37	$data .= $piece;
38	while (strlen($data) + strlen($end) < $max) {
39		/* Randomize a bit, taking gzip in account. */
40		$tmp = str_replace(
41			array(
42				"Empire Burlesque",
43				"Bob Dylan",
44			),
45			array(
46				md5(uniqid()),
47				sha1(uniqid()),
48			),
49			$piece
50		);
51
52		if (strlen($begin) + strlen($tmp) + strlen($end) > $max) {
53			break;
54		}
55
56		$data .= $tmp;
57	}
58	$data .= $end;
59
60	return $data;
61}
62
63$router = "bug73037_server.php";
64$args = substr(PHP_OS, 0, 3) == 'WIN' ? "-d extension_dir=" . ini_get("extension_dir") . " -d extension=php_soap.dll" : "";
65$code = <<<'PHP'
66$s = new SoapServer(NULL, array('uri' => 'http://here'));
67$s->setObject(new stdclass());
68$s->handle();
69PHP;
70
71php_cli_server_start($code, $router, $args);
72
73foreach (array(1024-1, 1024*8-3, 1024*9+1, 1024*16-1, 1024*32-5, 1024*64+3, 1024*128-7) as $k => $i) {
74	echo "Iteration $k\n\n";
75
76	/* with and without compression */
77	foreach (array(false, true) as $b) {
78		$data = get_data($i);
79		if ($b) {
80			$data = gzencode($data);
81		}
82		$len = strlen($data);
83
84		//echo "len=$len\n";
85
86		$hdrs = <<<HDRS
87POST /bug73037_server.php HTTP/1.1
88Content-Type: application/soap+xml; charset=UTF-8
89Accept: application/soap+xml, application/dime, multipart/related, text/*
90SOAPAction: "urn:adressen#adressen#SetAda"
91Expect: 100-continue
92Content-Length: ${len}
93HDRS;
94		if ($b) {
95			$hdrs .="\nContent-Encoding: gzip";
96		}
97		//echo "Headers sent:\n$hdrs\n\n";
98		$fp = fsockopen(PHP_CLI_SERVER_HOSTNAME, PHP_CLI_SERVER_PORT, $errno, $errstr, 5);
99		if (!$fp) {
100		  die("connect failed");
101		}
102
103		if(fwrite($fp, "$hdrs\n\n$data")) {
104			$out = "";
105			while (!feof($fp)) {
106				$out .= fread($fp, 1024);
107			}
108
109			$pos = strpos($out, "<env:Text>");
110			if (false === $pos) {
111				echo $out;
112				goto cleanup;
113			}
114			$pos0 = $pos + strlen("<env:Text>");
115			$pos = strpos($out, "</env:Text>");
116			if (false === $pos) {
117				echo $out;
118				goto cleanup;
119			}
120			$len = $pos - $pos0;
121			echo substr($out, $pos0, $len);
122		}
123
124cleanup:
125		fclose($fp);
126
127		echo "\n\n";
128		}
129}
130
131?>
132==DONE==
133--CLEAN--
134<?php
135unlink(dirname(__FILE__) . DIRECTORY_SEPARATOR . "bug73037_server.php");
136?>
137--EXPECT--
138Iteration 0
139
140Function 'CATALOG' doesn't exist
141
142Function 'CATALOG' doesn't exist
143
144Iteration 1
145
146Function 'CATALOG' doesn't exist
147
148Function 'CATALOG' doesn't exist
149
150Iteration 2
151
152Function 'CATALOG' doesn't exist
153
154Function 'CATALOG' doesn't exist
155
156Iteration 3
157
158Function 'CATALOG' doesn't exist
159
160Function 'CATALOG' doesn't exist
161
162Iteration 4
163
164Function 'CATALOG' doesn't exist
165
166Function 'CATALOG' doesn't exist
167
168Iteration 5
169
170Function 'CATALOG' doesn't exist
171
172Function 'CATALOG' doesn't exist
173
174Iteration 6
175
176Function 'CATALOG' doesn't exist
177
178Function 'CATALOG' doesn't exist
179
180==DONE==
181