From 393f882cb3a8a040bd7a0eb8da3c05cfacb8af99 Mon Sep 17 00:00:00 2001 From: gggeek Date: Sat, 30 May 2015 11:04:18 +0200 Subject: [PATCH] two fixes for 'load method synopsis' action in the debugger; add tests for NIL values in the dispatch map --- NEWS | 5 +++++ debugger/action.php | 13 +++++++++---- demo/server/server.php | 26 ++++++++++++++++++++++++++ tests/3LocalhostTest.php | 30 ++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 0a3a9a3..d941bcf 100644 --- a/NEWS +++ b/NEWS @@ -60,6 +60,11 @@ PLEASE READ CAREFULLY THE NOTES BELOW to insure a smooth upgrade. * fixed: the debugger would fail sending a request with ISO-8859-1 payload (it missed the character set declaration). It would have a hard time coping with ISO-8859-1 in other fields, such as e.g. the remote method name +* fixed: the debugger would generate a bad payload via the 'load method synopsis' button for signatures containing NULLs + +* fixed: the debugger would generate a bad payload via the 'load method synopsis' button for methods with multiple + signatures + * improved: the debugger is displayed using UTF-8, making it more useful to debug any kind of service * improved: echo all debug messages even when there are characters in them which php deems to be in a wrong encoding; diff --git a/debugger/action.php b/debugger/action.php index 05cc99a..18d9295 100644 --- a/debugger/action.php +++ b/debugger/action.php @@ -350,12 +350,13 @@ if ($action) { $desc = "-"; } echo "Description$desc\n"; - $payload = ""; - $alt_payload = ""; + if ($r2->kindOf() != "array") { echo "SignatureUnknown \n"; } else { for ($i = 0; $i < $r2->arraysize(); $i++) { + $payload = ""; + $alt_payload = ""; if ($i + 1 % 2) { $class = ' class="oddrow"'; } else { @@ -371,9 +372,13 @@ if ($action) { $y = $x->arraymem($k); echo htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding); if ($wstype != 1) { + $type = $y->scalarval(); + if ($type == 'null') { + $type = 'nil'; + } $payload = $payload . '<' . - htmlspecialchars($y->scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . - '>scalarval(), ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . + htmlspecialchars($type, ENT_COMPAT, \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding) . + '>\n"; } $alt_payload .= $y->scalarval(); diff --git a/demo/server/server.php b/demo/server/server.php index 1fdd49b..180a108 100644 --- a/demo/server/server.php +++ b/demo/server/server.php @@ -186,6 +186,23 @@ $moreSignatures = $wrapper->wrapPhpClass($c, array('prefix' => 'tests.', 'method $returnObj_sig = $wrapper->wrapPhpFunction(array($c, 'returnObject'), '', array('encode_php_objs' => true)); +// used to test signatures with NULL params +$findstate12_sig = array( + array(Value::$xmlrpcString, Value::$xmlrpcInt, Value::$xmlrpcNull), + array(Value::$xmlrpcString, Value::$xmlrpcNull, Value::$xmlrpcInt), +); + +function findStateWithNulls($req) +{ + $a = $req->getParam(0); + $b = $req->getParam(1); + + if ($a->scalartyp() == Value::$xmlrpcNull) + return new PhpXmlRpc\Response(new Value(inner_findstate($b->scalarval()))); + else + return new PhpXmlRpc\Response(new Value(inner_findstate($a->scalarval()))); +} + $addtwo_sig = array(array(Value::$xmlrpcInt, Value::$xmlrpcInt, Value::$xmlrpcInt)); $addtwo_doc = 'Add two integers together and return the result'; function addTwo($req) @@ -909,11 +926,20 @@ $signatures = array( 'tests.getStateName.10' => $findstate10_sig, 'tests.getStateName.11' => $findstate11_sig, + 'tests.getStateName.12' => array( + "function" => "findStateWithNulls", + "signature" => $findstate12_sig, + "docstring" => $findstate_doc, + ), + 'tests.returnPhpObject' => $returnObj_sig, ); $signatures = array_merge($signatures, $moreSignatures); +// enable support for the NULL extension +PhpXmlRpc\PhpXmlRpc::$xmlrpc_null_extension = true; + $s = new PhpXmlRpc\Server($signatures, false); $s->setdebug(3); $s->compress_response = true; diff --git a/tests/3LocalhostTest.php b/tests/3LocalhostTest.php index 4b721d6..a1f7dbf 100644 --- a/tests/3LocalhostTest.php +++ b/tests/3LocalhostTest.php @@ -112,6 +112,12 @@ class LocalhostTest extends PHPUnit_Framework_TestCase } } + /** + * @param PhpXmlRpc\Request|array $msg + * @param int|array $errorCode + * @param bool $returnResponse + * @return mixed|\PhpXmlRpc\Response|\PhpXmlRpc\Response[]|\PhpXmlRpc\Value|string|void + */ protected function send($msg, $errorCode = 0, $returnResponse = false) { if ($this->collectCodeCoverageInformation) { @@ -546,6 +552,30 @@ And turned it into nylon'; $v = $this->send($f); } + public function testNullParams() + { + $f = new xmlrpcmsg('tests.getStateName.12', array( + new xmlrpcval('whatever', 'null'), + new xmlrpcval(23, 'int'), + )); + $v = $this->send($f); + if ($v) { + $this->assertEquals('Michigan', $v->scalarval()); + } + $f = new xmlrpcmsg('tests.getStateName.12', array( + new xmlrpcval(23, 'int'), + new xmlrpcval('whatever', 'null'), + )); + $v = $this->send($f); + if ($v) { + $this->assertEquals('Michigan', $v->scalarval()); + } + $f = new xmlrpcmsg('tests.getStateName.12', array( + new xmlrpcval(23, 'int') + )); + $v = $this->send($f, array($GLOBALS['xmlrpcerr']['incorrect_params'])); + } + public function testCodeInjectionServerSide() { $f = new xmlrpcmsg('system.MethodHelp'); -- 2.43.0