php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68230 OpenSSL tests spawn PHP processes without preserving the test environment
Submitted: 2014-10-15 07:38 UTC Modified: 2017-10-24 04:33 UTC
Votes:3
Avg. Score:3.7 ± 1.9
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: gm dot outside+php at gmail dot com Assigned:
Status: Open Package: Testing related
PHP Version: 5.6.1 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gm dot outside+php at gmail dot com
New email:
PHP Version: OS:

 

 [2014-10-15 07:38 UTC] gm dot outside+php at gmail dot com
Description:
------------
In the test suite for the OpenSSL extension (ext/openssl) some tests require the server/client architecture.  Therefore they spawn two processes (a server and a client) to perform the tests.

Unfortunately, the way it's currently implemented does not provide reliable testing environment since the spawned instances are not preserving the environment the original test suite was launched in.

In the ext/openssl/tests/ServerClientTestCase.inc file there is a function called "spawnWorkerProcess()" and it simply executes the PHP binary followed by the script file name and script's arguments.  This picks up the system-wide PHP configuration files and can mess the testing up a lot, especially if the system-wide PHP is much older or configured significantly different than the one we are trying to build and test.

For example, this is how the PHP test suite is executed in our package builder:
===
export REPORT_EXIT_STATUS=1 MALLOC_CHECK_=2
export TEST_PHP_SRCDIR=..
unset TZ LANG LC_ALL
sapi/cli/php -n -c ./php-tests.ini -d extension_dir=modules \
        ../run-tests.php -p "$PWD/sapi/cli/php" -q --offline \
                -n -c "$PWD/php-tests.ini" -d "extension_dir=$PWD/modules"
===

As you can see, "-n" ensures that we are not picking up any default configuration files, followed by "-c" that specifies explicitly which configuration file to use for the test purposes.  Then we define the location of modules.  This is done for both the PHP/CLI executing the test suite and as the arguments to the test suite script itself.

The latter ensures that when the test suite generates test scripts it produces something like the following:
===
/php-5.6.1/ext/openssl/tests $ cat bug48182.sh
#!/bin/sh

/php-5.6.1/build-cgi/sapi/cli/php  -n -c '/php-5.6.1/build-cgi/php-tests.ini'  -d "output_handler=" -d "open_basedir=" -d "safe_mode=0" -d "disable_functions=" -d "output_buffering=Off" -d "error_reporting=32767" -d "display_errors=1" -d "display_startup_errors=1" -d "log_errors=0" -d "html_errors=0" -d "track_errors=1" -d "report_memleaks=1" -d "report_zend_debug=0" -d "docref_root=" -d "docref_ext=.html" -d "error_prepend_string=" -d "error_append_string=" -d "auto_prepend_file=" -d "auto_append_file=" -d "magic_quotes_runtime=0" -d "ignore_repeated_errors=0" -d "precision=14" -d "memory_limit=128M" -d "opcache.fast_shutdown=0" -d "opcache.file_update_protection=0" -d "extension_dir=/php-5.6.1/build-cgi/modules" -d "session.auto_start=0" -d "zlib.output_compression=Off" -d "mbstring.func_overload=0" -f "/php-5.6.1/ext/openssl/tests/bug48182.php"  2>&1
===

Now, all these settings are NOT honoured by the client/server OpenSSL tests since they are spawned via the spawnWorkerProcess() routine which does not prepare the test environment correctly.

Test script:
---------------
It's enough to disable the openssl.so extension in /etc/php (i.e. in the system-wide configuration), but enable it in the custom configuration file that is provided to the test suite run.

Expected result:
----------------
All OpenSSL test pass their checks.

Actual result:
--------------
Tests are failing with the following output:
===
/php-5.6.1/ext/openssl/tests $ ./bug48182.sh
Running bug48182

Warning: stream_socket_client(): SSL: Connection refused in /php-5.6.1/ext/openssl/tests/ServerClientTestCase.inc(92) : eval()'d code on line 9

Warning: stream_socket_client(): Failed to enable crypto in /php-5.6.1/ext/openssl/tests/ServerClientTestCase.inc(92) : eval()'d code on line 9

Warning: stream_socket_client(): unable to connect to ssl://127.0.0.1:64321 (Unknown error) in /php-5.6.1/ext/openssl/tests/ServerClientTestCase.inc(92) : eval()'d code on line 9

Warning: fwrite() expects parameter 1 to be resource, boolean given in /php-5.6.1/ext/openssl/tests/ServerClientTestCase.inc(92) : eval()'d code on line 13

Warning: fread() expects parameter 1 to be resource, boolean given in /php-5.6.1/ext/openssl/tests/ServerClientTestCase.inc(92) : eval()'d code on line 14
===

But the real error can be seen by strace'ing the script:
===
[...]
28460 write(1, "\nWarning: stream_socket_server(): unable to connect to ssl://127.0.0.1:64321 (Unable to find the socket transport \"ssl\" - did you forget to enable it when you configured PHP?) in /php-5.6.1/ext/openssl/tests/ServerClientTestCase.inc(86) : eval()'d code on line 7\n", 290) = 290
===

Patches

php-5.6.1-owlx-tests-openssl.diff (last revision 2014-10-15 08:09 UTC by gm dot outside+php at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-10-15 08:15 UTC] gm dot outside+php at gmail dot com
I've just added a patch that partially fixes the test suite.  My patch extracts the name of the configuration file and/or additional configuration files provided to testsuite's PHP binary and executes the spawned PHP binary with the same set of files.  It also extracts the extension_dir and supplies it to the spawned process.

NOTE: This patch is just to fix our build environment so we can build PHP.  This patch does NOT address the real issue of picking up the system-wide configuration files and it misses any custom configuration supplied to the test suite.

To properly solve the issue a new mechanism needs to be invented to ensure that the tests which require spawned children get the proper environment inherited from the primary test suite process.
 [2014-10-17 13:37 UTC] tyrael@php.net
-Assigned To: +Assigned To: tyrael
 [2015-12-06 16:26 UTC] rainer dot jung at kippdata dot de
This worked for me (and was needed) for PHP 7. I also had to add 

$custom_ini .= " -d 'extension=openssl.so'";

to load the openssl extension (which I had build as a dynamically loadable one).
 [2017-10-24 04:33 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: tyrael +Assigned To:
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sat Sep 21 15:01:27 2019 UTC