1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
include_once __DIR__ . '/../lib/xmlrpc.inc'; |
4
|
|
|
|
5
|
|
|
include_once __DIR__ . '/parse_args.php'; |
6
|
|
|
|
7
|
|
|
include_once __DIR__ . '/PolyfillTestCase.php'; |
8
|
|
|
|
9
|
|
|
use PHPUnit\Runner\BaseTestRunner; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Tests involving the Client class. |
13
|
|
|
* So far: only tests requests sent to non-existing servers |
14
|
|
|
*/ |
15
|
|
|
class ClientTest extends PhpXmlRpc_PolyfillTestCase |
16
|
|
|
{ |
17
|
|
|
/** @var xmlrpc_client $client */ |
18
|
|
|
public $client = null; |
19
|
|
|
public $args = array(); |
20
|
|
|
|
21
|
|
|
public function set_up() |
22
|
|
|
{ |
23
|
|
|
$this->args = argParser::getArgs(); |
24
|
|
|
|
25
|
|
|
$this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['HTTPSERVER'], 80); |
26
|
|
|
$this->client->setDebug($this->args['DEBUG']); |
27
|
|
|
|
28
|
|
|
if ($this->args['DEBUG'] == 1) |
29
|
|
|
ob_start(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function tear_down() |
33
|
|
|
{ |
34
|
|
|
if ($this->args['DEBUG'] != 1) |
35
|
|
|
return; |
36
|
|
|
$out = ob_get_clean(); |
37
|
|
|
$status = $this->getStatus(); |
38
|
|
|
if ($status == BaseTestRunner::STATUS_ERROR |
39
|
|
|
|| $status == BaseTestRunner::STATUS_FAILURE) { |
40
|
|
|
echo $out; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function test404() |
45
|
|
|
{ |
46
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
47
|
|
|
new xmlrpcval('hello', 'string'), |
48
|
|
|
)); |
49
|
|
|
$r = $this->client->send($m, 5); |
50
|
|
|
$this->assertEquals(5, $r->faultCode()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testSrvNotFound() |
54
|
|
|
{ |
55
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
56
|
|
|
new xmlrpcval('hello', 'string'), |
57
|
|
|
)); |
58
|
|
|
$this->client->server .= 'XXX'; |
59
|
|
|
$dnsinfo = @dns_get_record($this->client->server); |
60
|
|
|
if ($dnsinfo) { |
61
|
|
|
$this->markTestSkipped('Seems like there is a catchall DNS in effect: host ' . $this->client->server . ' found'); |
62
|
|
|
} else { |
63
|
|
|
$r = $this->client->send($m, 5); |
64
|
|
|
// make sure there's no freaking catchall DNS in effect |
65
|
|
|
$this->assertEquals(5, $r->faultCode()); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testTimedOutSendPayloadSocket() |
70
|
|
|
{ |
71
|
|
|
$m = new xmlrpcmsg('examples.timedout'); |
72
|
|
|
$this->client->server .= 'XXX'; |
73
|
|
|
|
74
|
|
|
// now test a successful connection |
75
|
|
|
$server = explode(':', $this->args['HTTPSERVER']); |
76
|
|
|
if (count($server) > 1) { |
77
|
|
|
$this->client->port = $server[1]; |
78
|
|
|
} |
79
|
|
|
$this->client->server = $server[0]; |
80
|
|
|
$this->client->path = $this->args['HTTPURI']; |
81
|
|
|
|
82
|
|
|
$r = $this->client->send($m, 5); |
83
|
|
|
$this->assertEquals(19, $r->faultCode()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testTimedOutSendPayloadCURL() |
87
|
|
|
{ |
88
|
|
|
if (!function_exists('curl_init')) { |
89
|
|
|
$this->markTestSkipped('CURL missing: cannot test curl keepalive errors'); |
90
|
|
|
|
91
|
|
|
return; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$m = new xmlrpcmsg('examples.timedout'); |
95
|
|
|
$this->client->server .= 'XXX'; |
96
|
|
|
|
97
|
|
|
// now test a successful connection |
98
|
|
|
$server = explode(':', $this->args['HTTPSERVER']); |
99
|
|
|
if (count($server) > 1) { |
100
|
|
|
$this->client->port = $server[1]; |
101
|
|
|
} |
102
|
|
|
$this->client->server = $server[0]; |
103
|
|
|
$this->client->path = $this->args['HTTPURI']; |
104
|
|
|
|
105
|
|
|
$r = $this->client->send($m, 5, 'http11'); |
106
|
|
|
$this->assertContains('CURL error: Operation timed out', $r->faultString()); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function testCurlKAErr() |
110
|
|
|
{ |
111
|
|
|
if (!function_exists('curl_init')) { |
112
|
|
|
$this->markTestSkipped('CURL missing: cannot test curl keepalive errors'); |
113
|
|
|
|
114
|
|
|
return; |
115
|
|
|
} |
116
|
|
|
$m = new xmlrpcmsg('examples.stringecho', array( |
117
|
|
|
new xmlrpcval('hello', 'string'), |
118
|
|
|
)); |
119
|
|
|
// test 2 calls w. keepalive: 1st time connection ko, second time ok |
120
|
|
|
$this->client->server .= 'XXX'; |
121
|
|
|
$this->client->keepalive = true; |
122
|
|
|
$r = $this->client->send($m, 5, 'http11'); |
123
|
|
|
// in case we have a "universal dns resolver" getting in the way, we might get a 302 instead of a 404 |
124
|
|
|
$this->assertTrue($r->faultCode() === 8 || $r->faultCode() == 5); |
125
|
|
|
|
126
|
|
|
// now test a successful connection |
127
|
|
|
$server = explode(':', $this->args['HTTPSERVER']); |
128
|
|
|
if (count($server) > 1) { |
129
|
|
|
$this->client->port = $server[1]; |
130
|
|
|
} |
131
|
|
|
$this->client->server = $server[0]; |
132
|
|
|
$this->client->path = $this->args['HTTPURI']; |
133
|
|
|
|
134
|
|
|
$r = $this->client->send($m, 5, 'http11'); |
135
|
|
|
$this->assertEquals(0, $r->faultCode()); |
136
|
|
|
$ro = $r->value(); |
137
|
|
|
is_object($ro) && $this->assertEquals('hello', $ro->scalarVal()); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|