- function testCountEntities()
- {
- $sendstring = "h'fd>onc>>l>>rw&bpu>q>e<v&gxs<ytjzkami<";
- $f = new xmlrpcmsg('validator1.countTheEntities',array(
- new xmlrpcval($sendstring, 'string')
- ));
- $v = $this->send($f);
- if($v)
- {
- $got = '';
- $expected = '37210';
- $expect_array = array('ctLeftAngleBrackets','ctRightAngleBrackets','ctAmpersands','ctApostrophes','ctQuotes');
- while(list(,$val) = each($expect_array))
- {
- $b = $v->structmem($val);
- $got .= $b->me['int'];
- }
- $this->assertEquals($expected, $got);
- }
- }
-
- function _multicall_msg($method, $params)
- {
- $struct['methodName'] = new xmlrpcval($method, 'string');
- $struct['params'] = new xmlrpcval($params, 'array');
- return new xmlrpcval($struct, 'struct');
- }
-
- function testServerMulticall()
- {
- // We manually construct a system.multicall() call to ensure
- // that the server supports it.
-
- // NB: This test will NOT pass if server does not support system.multicall.
-
- // Based on http://xmlrpc-c.sourceforge.net/hacks/test_multicall.py
- $good1 = $this->_multicall_msg(
- 'system.methodHelp',
- array(php_xmlrpc_encode('system.listMethods')));
- $bad = $this->_multicall_msg(
- 'test.nosuch',
- array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
- $recursive = $this->_multicall_msg(
- 'system.multicall',
- array(new xmlrpcval(array(), 'array')));
- $good2 = $this->_multicall_msg(
- 'system.methodSignature',
- array(php_xmlrpc_encode('system.listMethods')));
- $arg = new xmlrpcval(
- array($good1, $bad, $recursive, $good2),
- 'array'
- );
-
- $f = new xmlrpcmsg('system.multicall', array($arg));
- $v = $this->send($f);
- if($v)
- {
- //$this->assertTrue($r->faultCode() == 0, "fault from system.multicall");
- $this->assertTrue($v->arraysize() == 4, "bad number of return values");
-
- $r1 = $v->arraymem(0);
- $this->assertTrue(
- $r1->kindOf() == 'array' && $r1->arraysize() == 1,
- "did not get array of size 1 from good1"
- );
-
- $r2 = $v->arraymem(1);
- $this->assertTrue(
- $r2->kindOf() == 'struct',
- "no fault from bad"
- );
-
- $r3 = $v->arraymem(2);
- $this->assertTrue(
- $r3->kindOf() == 'struct',
- "recursive system.multicall did not fail"
- );
-
- $r4 = $v->arraymem(3);
- $this->assertTrue(
- $r4->kindOf() == 'array' && $r4->arraysize() == 1,
- "did not get array of size 1 from good2"
- );
- }
- }
-
- function testClientMulticall1()
- {
- // NB: This test will NOT pass if server does not support system.multicall.
-
- $this->client->no_multicall = false;
-
- $good1 = new xmlrpcmsg('system.methodHelp',
- array(php_xmlrpc_encode('system.listMethods')));
- $bad = new xmlrpcmsg('test.nosuch',
- array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
- $recursive = new xmlrpcmsg('system.multicall',
- array(new xmlrpcval(array(), 'array')));
- $good2 = new xmlrpcmsg('system.methodSignature',
- array(php_xmlrpc_encode('system.listMethods'))
- );
-
- $r = $this->send(array($good1, $bad, $recursive, $good2));
- if($r)
- {
- $this->assertTrue(count($r) == 4, "wrong number of return values");
- }
-
- $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
- if(!$r[0]->faultCode())
- {
- $val = $r[0]->value();
- $this->assertTrue(
- $val->kindOf() == 'scalar' && $val->scalartyp() == 'string',
- "good1 did not return string"
- );
- }
- $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
- $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall");
- $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
- if(!$r[3]->faultCode())
- {
- $val = $r[3]->value();
- $this->assertTrue($val->kindOf() == 'array', "good2 did not return array");
- }
- // This is the only assert in this test which should fail
- // if the test server does not support system.multicall.
- $this->assertTrue($this->client->no_multicall == false,
- "server does not support system.multicall"
- );
- }
-
- function testClientMulticall2()
- {
- // NB: This test will NOT pass if server does not support system.multicall.
-
- $this->client->no_multicall = true;
-
- $good1 = new xmlrpcmsg('system.methodHelp',
- array(php_xmlrpc_encode('system.listMethods')));
- $bad = new xmlrpcmsg('test.nosuch',
- array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
- $recursive = new xmlrpcmsg('system.multicall',
- array(new xmlrpcval(array(), 'array')));
- $good2 = new xmlrpcmsg('system.methodSignature',
- array(php_xmlrpc_encode('system.listMethods'))
- );
-
- $r = $this->send(array($good1, $bad, $recursive, $good2));
- if($r)
- {
- $this->assertTrue(count($r) == 4, "wrong number of return values");
- }
-
- $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
- if(!$r[0]->faultCode())
- {
- $val = $r[0]->value();
- $this->assertTrue(
- $val->kindOf() == 'scalar' && $val->scalartyp() == 'string',
- "good1 did not return string");
- }
- $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
- $this->assertTrue($r[2]->faultCode() == 0, "fault from (non recursive) system.multicall");
- $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
- if(!$r[3]->faultCode())
- {
- $val = $r[3]->value();
- $this->assertTrue($val->kindOf() == 'array', "good2 did not return array");
- }
- }
-
- function testClientMulticall3()
- {
- // NB: This test will NOT pass if server does not support system.multicall.
-
- $this->client->return_type = 'phpvals';
- $this->client->no_multicall = false;
-
- $good1 = new xmlrpcmsg('system.methodHelp',
- array(php_xmlrpc_encode('system.listMethods')));
- $bad = new xmlrpcmsg('test.nosuch',
- array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
- $recursive = new xmlrpcmsg('system.multicall',
- array(new xmlrpcval(array(), 'array')));
- $good2 = new xmlrpcmsg('system.methodSignature',
- array(php_xmlrpc_encode('system.listMethods'))
- );
-
- $r = $this->send(array($good1, $bad, $recursive, $good2));
- if($r)
- {
- $this->assertTrue(count($r) == 4, "wrong number of return values");
- }
- $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
- if(!$r[0]->faultCode())
- {
- $val = $r[0]->value();
- $this->assertTrue(
- is_string($val) , "good1 did not return string");
- }
- $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
- $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall");
- $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
- if(!$r[3]->faultCode())
- {
- $val = $r[3]->value();
- $this->assertTrue(is_array($val), "good2 did not return array");
- }
- $this->client->return_type = 'xmlrpcvals';
- }
-
- function testCatchWarnings()
- {
- $f = new xmlrpcmsg('examples.generatePHPWarning', array(
- new xmlrpcval('whatever', 'string')
- ));
- $v = $this->send($f);
- if($v)
- {
- $this->assertEquals($v->scalarval(), true);
- }
- }
-
- function testCatchExceptions()
- {
- global $URI;
- $f = new xmlrpcmsg('examples.raiseException', array(
- new xmlrpcval('whatever', 'string')
- ));
- $v = $this->send($f, $GLOBALS['xmlrpcerr']['server_error']);
- $this->client->path = $URI.'?EXCEPTION_HANDLING=1';
- $v = $this->send($f, 1);
- $this->client->path = $URI.'?EXCEPTION_HANDLING=2';
- $v = $this->send($f, $GLOBALS['xmlrpcerr']['invalid_return']);
- }
-
- function testZeroParams()
- {
- $f = new xmlrpcmsg('system.listMethods');
- $v = $this->send($f);
- }
-
- function testCodeInjectionServerSide()
- {
- $f = new xmlrpcmsg('system.MethodHelp');
- $f->payload = "<?xml version=\"1.0\"?><methodCall><methodName>validator1.echoStructTest</methodName><params><param><value><struct><member><name>','')); echo('gotcha!'); die(); //</name></member></struct></value></param></params></methodCall>";
- $v = $this->send($f);
- //$v = $r->faultCode();
- if ($v)
- {
- $this->assertEquals(0, $v->structsize());
- }
- }
-
- function testAutoRegisteredFunction()
- {
- $f=new xmlrpcmsg('examples.php.getStateName',array(
- new xmlrpcval(23, 'int')
- ));
- $v=$this->send($f);
- if($v)
- {
- $this->assertEquals('Michigan', $v->scalarval());
- }
- else
- {
- $this->fail('Note: server can only auto register functions if running with PHP 5.0.3 and up');
- }
- }
-
- function testAutoRegisteredClass()
- {
- $f=new xmlrpcmsg('examples.php2.getStateName',array(
- new xmlrpcval(23, 'int')
- ));
- $v=$this->send($f);
- if($v)
- {
- $this->assertEquals('Michigan', $v->scalarval());
- $f=new xmlrpcmsg('examples.php3.getStateName',array(
- new xmlrpcval(23, 'int')
- ));
- $v=$this->send($f);
- if($v)
- {
- $this->assertEquals('Michigan', $v->scalarval());
- }
- }
- else
- {
- $this->fail('Note: server can only auto register class methods if running with PHP 5.0.3 and up');
- }
- }
-
- function testAutoRegisteredMethod()
- {
- $func=wrap_xmlrpc_method($this->client, 'examples.getStateName');
- if($func == '')
- {
- $this->fail('Registration of examples.getStateName failed');
- }
- else
- {
- $v=$func(23);
- $this->assertEquals('Michigan', $v);
- }
- }
-
- function testGetCookies()
- {
- // let server set to us some cookies we tell it
- $cookies = array(
- //'c1' => array(),
- 'c2' => array('value' => 'c2'),
- 'c3' => array('value' => 'c3', 'expires' => time()+60*60*24*30),
- 'c4' => array('value' => 'c4', 'expires' => time()+60*60*24*30, 'path' => '/'),
- 'c5' => array('value' => 'c5', 'expires' => time()+60*60*24*30, 'path' => '/', 'domain' => 'localhost'),
- );
- $cookiesval = php_xmlrpc_encode($cookies);
- $f=new xmlrpcmsg('examples.setcookies',array($cookiesval));
- $r=$this->send($f, 0, true);
- if($r)
- {
- $v = $r->value();
- $this->assertEquals(1, $v->scalarval());
- // now check if we decoded the cookies as we had set them
- $rcookies = $r->cookies();
- foreach($cookies as $c => $v)
- // format for date string in cookies: 'Mon, 31 Oct 2005 13:50:56 GMT'
- // but PHP versions differ on that, some use 'Mon, 31-Oct-2005 13:50:56 GMT'...
- if(isset($v['expires']))
- {
- if (isset($rcookies[$c]['expires']) && strpos($rcookies[$c]['expires'], '-'))
- {
- $cookies[$c]['expires'] = gmdate('D, d\-M\-Y H:i:s \G\M\T' ,$cookies[$c]['expires']);
- }
- else
- {
- $cookies[$c]['expires'] = gmdate('D, d M Y H:i:s \G\M\T' ,$cookies[$c]['expires']);
- }
- }
- $this->assertEquals($cookies, $rcookies);
- }
- }
-
- function testSetCookies()
- {
- // let server set to us some cookies we tell it
- $cookies = array(
- 'c0' => null,
- 'c1' => 1,
- 'c2' => '2 3',
- 'c3' => '!@#$%^&*()_+|}{":?><,./\';[]\\=-'
- );
- $f=new xmlrpcmsg('examples.getcookies',array());
- foreach ($cookies as $cookie => $val)
- {
- $this->client->setCookie($cookie, $val);
- $cookies[$cookie] = (string) $cookies[$cookie];
- }
- $r = $this->client->send($f, $this->timeout, $this->method);
- $this->assertEquals($r->faultCode(), 0, 'Error '.$r->faultCode().' connecting to server: '.$r->faultString());
- if(!$r->faultCode())
- {
- $v = $r->value();
- $v = php_xmlrpc_decode($v);
- // on IIS and Apache getallheaders returns something slightly different...
- $this->assertEquals($v, $cookies);
- }
- }
-
- function testSendTwiceSameMsg()
- {
- $f=new xmlrpcmsg('examples.stringecho', array(
- new xmlrpcval('hello world', 'string')
- ));
- $v1 = $this->send($f);
- $v2 = $this->send($f);
- //$v = $r->faultCode();
- if ($v1 && $v2)
- {
- $this->assertEquals($v2, $v1);
- }
- }
- }
-
- class LocalHostMultiTests extends LocalhostTests
- {
- function _runtests()
- {
- global $failed_tests;
- foreach(get_class_methods('LocalhostTests') as $meth)
- {
- if(strpos($meth, 'test') === 0 && $meth != 'testHttps' && $meth != 'testCatchExceptions')
- {
- if (!isset($failed_tests[$meth]))
- $this->$meth();
- }
- if ($this->_failed)
- {
- break;
- }
- }
- }
-
- function testDeflate()
- {
- if(!function_exists('gzdeflate'))
- {
- $this->fail('Zlib missing: cannot test deflate functionality');
- return;
- }
- $this->client->accepted_compression = array('deflate');
- $this->client->request_compression = 'deflate';
- $this->_runtests();
- }
-
- function testGzip()
- {
- if(!function_exists('gzdeflate'))
- {
- $this->fail('Zlib missing: cannot test gzip functionality');
- return;
- }
- $this->client->accepted_compression = array('gzip');
- $this->client->request_compression = 'gzip';
- $this->_runtests();
- }
-
- function testKeepAlives()
- {
- if(!function_exists('curl_init'))
- {
- $this->fail('CURL missing: cannot test http 1.1');
- return;
- }
- $this->method = 'http11';
- $this->client->keepalive = true;
- $this->_runtests();
- }
-
- function testProxy()
- {
- global $PROXYSERVER, $PROXYPORT;
- if ($PROXYSERVER)
+ $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
+ if(!$r[0]->faultCode())
+ {
+ $val = $r[0]->value();
+ $this->assertTrue(
+ $val->kindOf() == 'scalar' && $val->scalartyp() == 'string',
+ "good1 did not return string");
+ }
+ $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
+ $this->assertTrue($r[2]->faultCode() == 0, "fault from (non recursive) system.multicall");
+ $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
+ if(!$r[3]->faultCode())
+ {
+ $val = $r[3]->value();
+ $this->assertTrue($val->kindOf() == 'array', "good2 did not return array");
+ }
+ }
+
+ function testClientMulticall3()
+ {
+ // NB: This test will NOT pass if server does not support system.multicall.
+
+ $this->client->return_type = 'phpvals';
+ $this->client->no_multicall = false;
+
+ $good1 = new xmlrpcmsg('system.methodHelp',
+ array(php_xmlrpc_encode('system.listMethods')));
+ $bad = new xmlrpcmsg('test.nosuch',
+ array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
+ $recursive = new xmlrpcmsg('system.multicall',
+ array(new xmlrpcval(array(), 'array')));
+ $good2 = new xmlrpcmsg('system.methodSignature',
+ array(php_xmlrpc_encode('system.listMethods'))
+ );
+
+ $r = $this->send(array($good1, $bad, $recursive, $good2));
+ if($r)
+ {
+ $this->assertTrue(count($r) == 4, "wrong number of return values");
+ }
+ $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
+ if(!$r[0]->faultCode())
+ {
+ $val = $r[0]->value();
+ $this->assertTrue(
+ is_string($val) , "good1 did not return string");
+ }
+ $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
+ $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall");
+ $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
+ if(!$r[3]->faultCode())
+ {
+ $val = $r[3]->value();
+ $this->assertTrue(is_array($val), "good2 did not return array");
+ }
+ $this->client->return_type = 'xmlrpcvals';
+ }
+
+ function testCatchWarnings()
+ {
+ $f = new xmlrpcmsg('examples.generatePHPWarning', array(
+ new xmlrpcval('whatever', 'string')
+ ));
+ $v = $this->send($f);
+ if($v)
+ {
+ $this->assertEquals($v->scalarval(), true);
+ }
+ }
+
+ function testCatchExceptions()
+ {
+ global $URI;
+ $f = new xmlrpcmsg('examples.raiseException', array(
+ new xmlrpcval('whatever', 'string')
+ ));
+ $v = $this->send($f, $GLOBALS['xmlrpcerr']['server_error']);
+ $this->client->path = $URI.'?EXCEPTION_HANDLING=1';
+ $v = $this->send($f, 1);
+ $this->client->path = $URI.'?EXCEPTION_HANDLING=2';
+ $v = $this->send($f, $GLOBALS['xmlrpcerr']['invalid_return']);
+ }
+
+ function testZeroParams()
+ {
+ $f = new xmlrpcmsg('system.listMethods');
+ $v = $this->send($f);
+ }
+
+ function testCodeInjectionServerSide()
+ {
+ $f = new xmlrpcmsg('system.MethodHelp');
+ $f->payload = "<?xml version=\"1.0\"?><methodCall><methodName>validator1.echoStructTest</methodName><params><param><value><struct><member><name>','')); echo('gotcha!'); die(); //</name></member></struct></value></param></params></methodCall>";
+ $v = $this->send($f);
+ //$v = $r->faultCode();
+ if ($v)
+ {
+ $this->assertEquals(0, $v->structsize());
+ }
+ }
+
+ function testAutoRegisteredFunction()
+ {
+ $f=new xmlrpcmsg('examples.php.getStateName',array(
+ new xmlrpcval(23, 'int')
+ ));
+ $v=$this->send($f);
+ if($v)
+ {
+ $this->assertEquals('Michigan', $v->scalarval());
+ }
+ else
+ {
+ $this->fail('Note: server can only auto register functions if running with PHP 5.0.3 and up');
+ }
+ }
+
+ function testAutoRegisteredClass()
+ {
+ $f=new xmlrpcmsg('examples.php2.getStateName',array(
+ new xmlrpcval(23, 'int')
+ ));
+ $v=$this->send($f);
+ if($v)
+ {
+ $this->assertEquals('Michigan', $v->scalarval());
+ $f=new xmlrpcmsg('examples.php3.getStateName',array(
+ new xmlrpcval(23, 'int')
+ ));
+ $v=$this->send($f);
+ if($v)