xref: /php-src/ext/soap/tests/bugs/bug55639.phpt (revision 911dc5b4)
1--TEST--
2Bug #55639 (Digest authentication dont work)
3--INI--
4soap.wsdl_cache_enabled=0
5--EXTENSIONS--
6soap
7--SKIPIF--
8<?php
9if (!file_exists(__DIR__ . "/../../../../sapi/cli/tests/php_cli_server.inc")) {
10    echo "skip sapi/cli/tests/php_cli_server.inc required but not found";
11}
12?>
13--FILE--
14<?php
15
16include __DIR__ . "/../../../../sapi/cli/tests/php_cli_server.inc";
17
18$args = ["-d", "extension_dir=" . ini_get("extension_dir"), "-d", "extension=" . (substr(PHP_OS, 0, 3) == "WIN" ? "php_" : "") . "soap." . PHP_SHLIB_SUFFIX];
19if (php_ini_loaded_file()) {
20  // Necessary such that it works from a development directory in which case extension_dir might not be the real extension dir
21  $args[] = "-c";
22  $args[] = php_ini_loaded_file();
23}
24
25$code = <<<'PHP'
26/* Receive */
27header('HTTP/1.0 401 Unauthorized');
28header('WWW-Authenticate: Digest realm="realm", qop="auth,auth-int", nonce="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", opaque="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"');
29file_get_contents("php://input");
30PHP;
31
32php_cli_server_start($code, null, $args);
33
34$client = new soapclient(NULL, [
35  'location' => 'http://' . PHP_CLI_SERVER_ADDRESS,
36  'uri' => 'misc-uri',
37  'authentication' => SOAP_AUTHENTICATION_DIGEST,
38  'realm' => 'myrealm',
39  'login' => 'user',
40  'password' => 'pass',
41  'trace' => true,
42]);
43
44try {
45    $client->__soapCall("foo", []);
46} catch (Throwable $e) {
47    echo $e->getMessage(), "\n";
48}
49
50$headers = $client->__getLastRequestHeaders();
51var_dump($headers);
52
53?>
54--EXPECTF--
55Unauthorized
56string(%d) "POST / HTTP/1.1
57Host: %s
58Connection: Keep-Alive
59User-Agent: %s
60Content-Type: text/xml; charset=utf-8
61SOAPAction: "misc-uri#foo"
62Content-Length: %d
63Authorization: Digest username="user", realm="realm", nonce="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", uri="/", qop=auth, nc=00000001, cnonce="%s", response="%s", opaque="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
64
65"
66