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