From c803c82b596647118bc9184d4e311d307e781e0f Mon Sep 17 00:00:00 2001 From: gggeek Date: Mon, 23 Jan 2023 13:50:00 +0000 Subject: [PATCH] tests --- .github/workflows/ci.yaml | 1 + demo/client/python/test.py | 5 ++++- demo/server/server.php | 6 ++++++ src/Helper/XMLParser.php | 6 ++++-- tests/03ParsingTest.php | 2 +- tests/09HTTPTest.php | 18 ++++++++++++++++++ tests/10DemofilesTest.php | 2 ++ tests/ci/Dockerfile | 1 + 8 files changed, 37 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d49b889d..d1920872 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -67,6 +67,7 @@ jobs: # @todo add env setup scripts for windows run: | chmod 755 ./tests/ci/setup/*.sh + sudo --preserve-env=GITHUB_ACTIONS ./tests/ci/setup/install_packages.sh sudo --preserve-env=GITHUB_ACTIONS ./tests/ci/setup/setup_perl.sh sudo --preserve-env=GITHUB_ACTIONS ./tests/ci/setup/setup_apache.sh sudo --preserve-env=GITHUB_ACTIONS ./tests/ci/setup/setup_privoxy.sh diff --git a/demo/client/python/test.py b/demo/client/python/test.py index d7954a95..0f478543 100644 --- a/demo/client/python/test.py +++ b/demo/client/python/test.py @@ -3,7 +3,7 @@ import xmlrpc.client import base64 -#import sys +import sys server = xmlrpc.client.ServerProxy("http://localhost/demo/server/server.php") @@ -29,3 +29,6 @@ except xmlrpc.client.Fault as err: print("A fault occurred") print("Fault code: %d" % err.faultCode) print("Fault string: %s" % err.faultString) + + # let the test suite know that here was a fault + sys.exit(err.faultCode) diff --git a/demo/server/server.php b/demo/server/server.php index 4ca667be..fb3827ba 100644 --- a/demo/server/server.php +++ b/demo/server/server.php @@ -85,6 +85,12 @@ if (defined('TESTMODE')) { } } } + if (isset($_GET['FORCE_REDIRECT'])) { + header('HTTP/1.0 302 Found'); + unset($_GET['FORCE_REDIRECT']); + header('Location: ' . $_SERVER['REQUEST_URI'] . (count($_GET) ? '?' . http_build_query($_GET) : '')); + die(); + } } $s->service(); diff --git a/src/Helper/XMLParser.php b/src/Helper/XMLParser.php index c406f7c7..6375ff2b 100644 --- a/src/Helper/XMLParser.php +++ b/src/Helper/XMLParser.php @@ -570,12 +570,14 @@ class XMLParser // NB: this simple checks helps a lot sanitizing input, i.e. no security problems around here // Note the non-strict type check: it will allow ' 1 ' /// @todo feature-creep: use a flexible regexp, the same as we do with int, double and datetime. - /// Note that using a regexp would also make this test less sensitive to phpunit shenanigans + /// Note that using a regexp would also make this test less sensitive to phpunit shenanigans, and + /// to changes in the way php compares strings (since 8.0, leading and trailing newlines are + /// accepted when deciding if a string numeric...) if ($this->_xh['ac'] == '1' || strcasecmp($this->_xh['ac'], 'true') === 0) { $this->_xh['value'] = true; } else { // log if receiving something strange, even though we set the value to false anyway - /// @todo to be consistent with the other types, we should use a value outside the good-value domain, e.g. NULL + /// @todo to be consistent with the other types, we should return a value outside the good-value domain, e.g. NULL if ($this->_xh['ac'] != '0' && strcasecmp($this->_xh['ac'], 'false') !== 0) { $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid data received in BOOLEAN value: ' . $this->_xh['ac']); if ($this->current_parsing_options['xmlrpc_reject_invalid_values']) diff --git a/tests/03ParsingTest.php b/tests/03ParsingTest.php index 74e38908..2510ab68 100644 --- a/tests/03ParsingTest.php +++ b/tests/03ParsingTest.php @@ -389,7 +389,7 @@ aGk= bool -1 +yes diff --git a/tests/09HTTPTest.php b/tests/09HTTPTest.php index d6dd9328..2af8decb 100644 --- a/tests/09HTTPTest.php +++ b/tests/09HTTPTest.php @@ -98,6 +98,24 @@ class HTTPTest extends ServerTest } } + /** + * @dataProvider getSingleHttpTestMethods + * @param string $method + */ + public function testRedirects($method) + { + if (!function_exists('curl_init')) + { + $this->markTestSkipped('CURL missing: cannot test redirects'); + return; + } + + $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_ALWAYS); + $this->client->setCurlOptions(array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_POSTREDIR => 3)); + + $this->$method(); + } + public function testAcceptCharset() { if (version_compare(PHP_VERSION, '5.6.0', '<')) diff --git a/tests/10DemofilesTest.php b/tests/10DemofilesTest.php index fe8b228c..05868ba9 100644 --- a/tests/10DemofilesTest.php +++ b/tests/10DemofilesTest.php @@ -4,6 +4,8 @@ include_once __DIR__ . '/WebTestCase.php'; /** * Tests for php files in the 'demo' directory. + * + * @todo add execution of perl and python demos via usage of 'exec' */ class DemoFilesTest extends PhpXmlRpc_WebTestCase { diff --git a/tests/ci/Dockerfile b/tests/ci/Dockerfile index e34f1568..43c9df86 100644 --- a/tests/ci/Dockerfile +++ b/tests/ci/Dockerfile @@ -13,6 +13,7 @@ RUN mkdir -p /usr/share/man/man1 && \ cd /root/setup && \ ./install_packages.sh && \ ./create_user.sh && \ + ./setup_perl.sh && \ ./setup_apache.sh && \ ./setup_privoxy.sh && \ ./setup_php.sh "${PHP_VERSION}" && \ -- 2.47.0