env:
global:
- - LOCALSERVER=localhost
+ - HTTPSERVER=localhost
- URI=/demo/server/server.php
- HTTPSSERVER=localhost
- HTTPSURI=/demo/server/server.php
* Hackish code used to make the demos both viewable as source, runnable, and viewable as html
*/
-// Make errors visible
-ini_set('display_errors', true);
-error_reporting(E_ALL);
-
if (isset($_GET['showSource']) && $_GET['showSource']) {
$file = debug_backtrace()[0]['file'];
highlight_file($file);
die();
}
+// Make errors visible
+ini_set('display_errors', true);
+error_reporting(E_ALL);
+
// Use the custom class autoloader. These two lines not needed when the phpxmlrpc library is installed using Composer
include_once __DIR__ . '/../../src/Autoloader.php';
PhpXmlRpc\Autoloader::register();
// Let unit tests run against localhost, 'plain' demos against a known public server
-if (isset($_SERVER['LOCALSERVER'])) {
- define('XMLRPCSERVER', 'http://'.$_SERVER['LOCALSERVER'].'/demo/server/server.php');
+if (isset($_SERVER['HTTPSERVER'])) {
+ define('XMLRPCSERVER', 'http://'.$_SERVER['HTTPSERVER'].'/demo/server/server.php');
} else {
define('XMLRPCSERVER', 'http://phpxmlrpc.sourceforge.net/server.php');
}
{
$this->args = argParser::getArgs();
- $this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['LOCALSERVER'], 80);
+ $this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['HTTPSERVER'], 80);
$this->client->setDebug($this->args['DEBUG']);
if ($this->args['DEBUG'] == 1)
$this->assertTrue($r->faultCode() === 8 || $r->faultCode() == 5);
// now test a successful connection
- $server = explode(':', $this->args['LOCALSERVER']);
+ $server = explode(':', $this->args['HTTPSERVER']);
if (count($server) > 1) {
$this->client->port = $server[1];
}
$this->client->server = $server[0];
- $this->client->path = $this->args['URI'];
+ $this->client->path = $this->args['HTTPURI'];
$r = $this->client->send($m, 5, 'http11');
$this->assertEquals(0, $r->faultCode());
{
$this->args = argParser::getArgs();
- $server = explode(':', $this->args['LOCALSERVER']);
+ $server = explode(':', $this->args['HTTPSERVER']);
if (count($server) > 1) {
- $this->client = new xmlrpc_client($this->args['URI'], $server[0], $server[1]);
+ $this->client = new xmlrpc_client($this->args['HTTPURI'], $server[0], $server[1]);
} else {
- $this->client = new xmlrpc_client($this->args['URI'], $this->args['LOCALSERVER']);
+ $this->client = new xmlrpc_client($this->args['HTTPURI'], $this->args['HTTPSERVER']);
}
$this->client->setDebug($this->args['DEBUG']);
$this->client->request_compression = $this->request_compression;
$this->client->accepted_compression = $this->accepted_compression;
- $this->coverageScriptUrl = 'http://' . $this->args['LOCALSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['URI'] );
+ $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['HTTPURI'] );
if ($this->args['DEBUG'] == 1)
ob_start();
{
$this->args = argParser::getArgs();
- $this->baseUrl = $this->args['LOCALSERVER'] . str_replace( '/demo/server/server.php', '/demo/', $this->args['URI'] );
+ $this->baseUrl = $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/demo/', $this->args['HTTPURI'] );
- $this->coverageScriptUrl = 'http://' . $this->args['LOCALSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['URI'] );
+ $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['HTTPURI'] );
}
public function testAgeSort()
{
$this->args = argParser::getArgs();
- $this->baseUrl = $this->args['LOCALSERVER'] . str_replace( '/demo/server/server.php', '/debugger/', $this->args['URI'] );
+ $this->baseUrl = $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/debugger/', $this->args['HTTPURI'] );
- $this->coverageScriptUrl = 'http://' . $this->args['LOCALSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['URI'] );
+ $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['HTTPURI'] );
}
public function testIndex()
{
$this->args = argParser::getArgs();
- $this->baseUrl = $this->args['LOCALSERVER'] . str_replace( '/demo/server/server.php', '/tests/', $this->args['URI'] );
+ $this->baseUrl = $this->args['HTTPSERVER'] . str_replace( '/demo/server/server.php', '/tests/', $this->args['HTTPURI'] );
- $this->coverageScriptUrl = 'http://' . $this->args['LOCALSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['URI'] );
+ $this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['HTTPURI'] );
}
public function testVerifyCompat()
for ($i = 0; $i < 25; $i++) {
$reqs[] = $req;
}
- $server = explode(':', $args['LOCALSERVER']);
+ $server = explode(':', $args['HTTPSERVER']);
if (count($server) > 1) {
- $srv = $server[1] . '://' . $server[0] . $args['URI'];
- $c = new Client($args['URI'], $server[0], $server[1]);
+ $srv = $server[1] . '://' . $server[0] . $args['HTTPURI'];
+ $c = new Client($args['HTTPURI'], $server[0], $server[1]);
} else {
- $srv = $args['LOCALSERVER'] . $args['URI'];
- $c = new Client($args['URI'], $args['LOCALSERVER']);
+ $srv = $args['HTTPSERVER'] . $args['HTTPURI'];
+ $c = new Client($args['HTTPURI'], $args['HTTPSERVER']);
}
// do not interfere with http compression
$c->accepted_compression = array();
ARG PHP_VERSION=default
-RUN mkdir -p /usr/share/man/man1 && \
- apt-get update
-
COPY setup/*.sh /root/setup/
COPY config/* /root/config/
-RUN chmod 755 /root/setup/*.sh && \
+RUN mkdir -p /usr/share/man/man1 && \
+ apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y upgrade && \
+ chmod 755 /root/setup/*.sh && \
cd /root/setup && \
./install_packages.sh && \
./create_user.sh && \
./setup_apache.sh && \
./setup_privoxy.sh && \
./setup_php.sh "${PHP_VERSION}" && \
- apt-get remove -y composer || echo An error on the line above is ok; ./get_composer.sh && mv /usr/local/bin/composer.phar /usr/local/bin/composer && chmod 755 /usr/local/bin/composer
+ ./setup_composer.sh
COPY docker/entrypoint.sh /root/entrypoint.sh
RUN chmod 755 /root/entrypoint.sh
--- /dev/null
+# @todo check: is this limited to php5 only?
+
+# Wire up Apache to use php-fpm via mod_fastcgi.
+<IfModule mod_fastcgi.c>
+ AddHandler php5-fcgi .php
+ Action php5-fcgi /php5-fcgi
+ Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
+ FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -host 127.0.0.1:9000 -pass-header Authorization
+ <Directory /usr/lib/cgi-bin>
+ Require all granted
+ </Directory>
+</IfModule>
--- /dev/null
+# @todo check: templatize this, to make it work with any php version
+
+# Redirect to local php-fpm if mod_php is not available
+<IfModule !mod_php7.c>
+<IfModule proxy_fcgi_module>
+ # Enable http authorization headers
+ <IfModule setenvif_module>
+ SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
+ </IfModule>
+
+ <FilesMatch ".+\.ph(ar|p|tml)$">
+ SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost"
+ </FilesMatch>
+ <FilesMatch ".+\.phps$">
+ # Deny access to raw php sources by default
+ # To re-enable it's recommended to enable access to the files
+ # only in specific virtual host or directory
+ Require all denied
+ </FilesMatch>
+ # Deny access to files without filename (e.g. '.php')
+ <FilesMatch "^\.ph(ar|p|ps|tml)$">
+ Require all denied
+ </FilesMatch>
+</IfModule>
+</IfModule>
-# Uses env var: TESTS_ROOT_DIR
+# Uses env vars:
+# HTTPSERVER
+# TESTS_ROOT_DIR
<VirtualHost *:80>
ErrorLog "${TESTS_ROOT_DIR}/apache_error.log"
CustomLog "${TESTS_ROOT_DIR}/apache_access.log" combined
+ # Env vars used by the test code, which we get from the environment
+ SetEnv HTTPSERVER ${HTTPSERVER}
+
<Directory "${TESTS_ROOT_DIR}">
Options FollowSymLinks MultiViews
AllowOverride All
ErrorLog "${TESTS_ROOT_DIR}/apache_error.log"
CustomLog "${TESTS_ROOT_DIR}/apache_access.log" combined
+ # Env vars used by the test code, which we get from the environment
+ SetEnv HTTPSERVER ${HTTPSERVER}
+
<Directory "${TESTS_ROOT_DIR}">
Options FollowSymLinks MultiViews
AllowOverride All
echo "[$(date)] Fixing apache configuration..."
-# @todo set as well APACHE_RUN_USER and/or APACHE_RUN_GROUP ?
sed -e "s?^export TESTS_ROOT_DIR=.*?export TESTS_ROOT_DIR=${TESTS_ROOT_DIR}?g" --in-place /etc/apache2/envvars
+# @todo set as well php-fpm user/group ?
+
echo "[$(date)] Running Composer..."
sudo test -c "cd /home/test && composer install"
USERNAME="${1:-test}"
-addgroup --gid 1013 ${USERNAME}
-adduser --system --uid=1013 --gid=1013 --home /home/${USERNAME} --shell /bin/bash ${USERNAME}
-adduser ${USERNAME} ${USERNAME}
+addgroup --gid 1013 "${USERNAME}"
+adduser --system --uid=1013 --gid=1013 --home "/home/${USERNAME}" --shell /bin/bash "${USERNAME}"
+adduser "${USERNAME}" "${USERNAME}"
-mkdir -p /home/${USERNAME}/.ssh
-cp /etc/skel/.[!.]* /home/${USERNAME}
+mkdir -p "/home/${USERNAME}/.ssh"
+cp /etc/skel/.[!.]* "/home/${USERNAME}"
-adduser ${USERNAME} sudo
-sed -i "\$ a ${USERNAME} ALL=\(ALL:ALL\) NOPASSWD: ALL" /etc/sudoers
+chown -R "${USERNAME}:${USERNAME}" "/home/${USERNAME}"
-chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}
+if [ -f /etc/sudoers ]; then
+ adduser "${USERNAME}" sudo
+ sed -i "\$ a ${USERNAME} ALL=\(ALL:ALL\) NOPASSWD: ALL" /etc/sudoers
+fi
else
echo "export TESTS_ROOT_DIR=/var/www/html" >> /etc/apache2/envvars
fi
+echo "export HTTPSERVER=localhost" >> /etc/apache2/envvars
service apache2 restart
# Installs Composer (latest version, to avoid relying on old ones bundled with the OS)
# @todo allow users to lock down to Composer v1 if needed
+if dpkg -l composer 2>/dev/null; then
+ apt-get remove -y composer
+fi
+
+### Code below taken from https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
+
EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
exit 1
fi
-php composer-setup.php --install-dir=/usr/local/bin
+php composer-setup.php --quiet --install-dir=/usr/local/bin
RESULT=$?
rm composer-setup.php
+
+###
+
+if [ -f /usr/local/bin/composer.phar -a "$RESULT" = 0 ]; then
+ mv /usr/local/bin/composer.phar /usr/local/bin/composer && chmod 755 /usr/local/bin/composer
+fi
+
exit $RESULT
echo "cgi.fix_pathinfo = 1" >> "${1}"
echo "always_populate_raw_post_data = -1" >> "${1}"
+ # @todo this only disables xdebug for CLI. To do the same for the FPM config as well, should we use instead `phpdismod` ?
XDEBUG_INI=$(php -i | grep xdebug.ini | grep -v '=>' | head -1)
if [ "$XDEBUG_INI" != "" ]; then
- #XDEBUG_INI=${XDEBUG_INI/,/}
+ XDEBUG_INI="$(echo "$XDEBUG_INI" | tr -d ',')"
mv "$XDEBUG_INI" "$XDEBUG_INI.bak";
fi
}
if ! which php >/dev/null; then
# install php
- PHP_VERSION=$1
- DEBIAN_VERSION=$(lsb_release -s -c)
+ PHP_VERSION="$1"
+ DEBIAN_VERSION="$(lsb_release -s -c)"
if [ "${PHP_VERSION}" = default ]; then
if [ "${DEBIAN_VERSION}" = jessie -o "${DEBIAN_VERSION}" = precise -o "${DEBIAN_VERSION}" = trusty ]; then
php${PHPSUFFIX}-mbstring \
php${PHPSUFFIX}-xdebug
else
- #DEBIAN_FRONTEND=noninteractive apt-get install -y \
- # gnupg2 ca-certificates lsb-release apt-transport-https
- #wget https://packages.sury.org/php/apt.gpg
- #apt-key add apt.gpg
- #echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list
-
DEBIAN_FRONTEND=noninteractive apt-get install -y language-pack-en-base software-properties-common
LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
apt-get update
-p 80:80 -p 443:443 -p 8080:8080 \
--name "${CONTAINER_NAME}" \
--env CONTAINER_USER_UID=$(id -u) --env CONTAINER_USER_GID=$(id -g) --env TESTS_ROOT_DIR=/home/test \
- --env LOCALSERVER=localhost \
- --env URI=/demo/server/server.php \
+ --env HTTPSERVER=localhost \
+ --env HTTPURI=/demo/server/server.php \
--env HTTPSSERVER=localhost \
--env HTTPSURI=/demo/server/server.php \
--env PROXYSERVER=localhost:8080 \
* Common parameter parsing for benchmark and tests scripts.
*
* @param integer DEBUG
- * @param string LOCALSERVER
- * @param string URI
+ * @param string HTTPSERVER
+ * @param string HTTPURI
* @param string HTTPSSERVER
* @param string HTTPSURI
* @param bool HTTPSIGNOREPEER
**/
class argParser
{
+ /**
+ * @return array
+ */
public static function getArgs()
{
+ /// @todo should we prefix all test parameters with TESTS_ ?
$args = array(
'DEBUG' => 0,
- 'LOCALSERVER' => 'localhost',
- 'HTTPSSERVER' => 'gggeek.altervista.org',
- 'HTTPSURI' => '/sw/xmlrpc/demo/server/server.php',
+ 'HTTPSERVER' => 'localhost',
+ 'HTTPURI' => null,
+ // now that we run tests in Docker by default, with a webserver set up for https, let's default to it
+ 'HTTPSSERVER' => 'localhost',
+ 'HTTPSURI' => null,
+ // example alternative:
+ //'HTTPSSERVER' => 'gggeek.altervista.org',
+ //'HTTPSURI' => '/sw/xmlrpc/demo/server/server.php',
'HTTPSIGNOREPEER' => false,
'HTTPSVERIFYHOST' => 2,
'SSLVERSION' => 0,
'PROXYSERVER' => null,
- 'LOCALPATH' => __DIR__,
+ //'LOCALPATH' => __DIR__,
);
// check for command line (env vars) vs. web page input params
if (isset($DEBUG)) {
$args['DEBUG'] = intval($DEBUG);
}
- if (isset($LOCALSERVER)) {
- $args['LOCALSERVER'] = $LOCALSERVER;
+
+ if (isset($HTTPSERVER)) {
+ $args['HTTPSERVER'] = $HTTPSERVER;
} else {
if (isset($HTTP_HOST)) {
- $args['LOCALSERVER'] = $HTTP_HOST;
+ $args['HTTPSERVER'] = $HTTP_HOST;
} elseif (isset($_SERVER['HTTP_HOST'])) {
- $args['LOCALSERVER'] = $_SERVER['HTTP_HOST'];
+ $args['HTTPSERVER'] = $_SERVER['HTTP_HOST'];
+ }
+ }
+
+ if (!isset($HTTPURI) || $HTTPURI == '') {
+ // GUESTIMATE the url of local demo server
+ // play nice to php 3 and 4-5 in retrieving URL of server.php
+ /// @todo filter out query string from REQUEST_URI
+ if (isset($REQUEST_URI)) {
+ $HTTPURI = str_replace('/tests/testsuite.php', '/demo/server/server.php', $REQUEST_URI);
+ $HTTPURI = str_replace('/testsuite.php', '/server.php', $HTTPURI);
+ $HTTPURI = str_replace('/tests/benchmark.php', '/demo/server/server.php', $HTTPURI);
+ $HTTPURI = str_replace('/benchmark.php', '/server.php', $HTTPURI);
+ } elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['REQUEST_METHOD'])) {
+ $HTTPURI = str_replace('/tests/testsuite.php', '/demo/server/server.php', $_SERVER['PHP_SELF']);
+ $HTTPURI = str_replace('/testsuite.php', '/server.php', $HTTPURI);
+ $HTTPURI = str_replace('/tests/benchmark.php', '/demo/server/server.php', $HTTPURI);
+ $HTTPURI = str_replace('/benchmark.php', '/server.php', $HTTPURI);
+ } else {
+ $HTTPURI = '/demo/server/server.php';
}
}
+ if ($HTTPURI[0] != '/') {
+ $HTTPURI = '/' . $HTTPURI;
+ }
+ $args['HTTPURI'] = $HTTPURI;
+
if (isset($HTTPSSERVER)) {
$args['HTTPSSERVER'] = $HTTPSSERVER;
}
+
+ /// @todo if $HTTPSURI is unset, and HTTPSSERVER == localhost, use HTTPURI
if (isset($HTTPSURI)) {
$args['HTTPSURI'] = $HTTPSURI;
}
+
if (isset($HTTPSIGNOREPEER)) {
$args['HTTPSIGNOREPEER'] = (bool)$HTTPSIGNOREPEER;
}
+
if (isset($HTTPSVERIFYHOST)) {
$args['HTTPSVERIFYHOST'] = (int)$HTTPSVERIFYHOST;
}
+
if (isset($SSLVERSION)) {
$args['SSLVERSION'] = (int)$SSLVERSION;
}
+
if (isset($PROXYSERVER)) {
$arr = explode(':', $PROXYSERVER);
$args['PROXYSERVER'] = $arr[0];
$args['PROXYPORT'] = 8080;
}
}
- if (!isset($URI)) {
- // GUESTIMATE the url of local demo server
- // play nice to php 3 and 4-5 in retrieving URL of server.php
- /// @todo filter out query string from REQUEST_URI
- if (isset($REQUEST_URI)) {
- $URI = str_replace('/tests/testsuite.php', '/demo/server/server.php', $REQUEST_URI);
- $URI = str_replace('/testsuite.php', '/server.php', $URI);
- $URI = str_replace('/tests/benchmark.php', '/demo/server/server.php', $URI);
- $URI = str_replace('/benchmark.php', '/server.php', $URI);
- } elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['REQUEST_METHOD'])) {
- $URI = str_replace('/tests/testsuite.php', '/demo/server/server.php', $_SERVER['PHP_SELF']);
- $URI = str_replace('/testsuite.php', '/server.php', $URI);
- $URI = str_replace('/tests/benchmark.php', '/demo/server/server.php', $URI);
- $URI = str_replace('/benchmark.php', '/server.php', $URI);
- } else {
- $URI = '/demo/server/server.php';
- }
- }
- if ($URI[0] != '/') {
- $URI = '/' . $URI;
- }
- $args['URI'] = $URI;
- if (isset($LOCALPATH)) {
- $args['LOCALPATH'] = $LOCALPATH;
- }
+
+ //if (isset($LOCALPATH)) {
+ // $args['LOCALPATH'] = $LOCALPATH;
+ //}
return $args;
}