Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions tests/SSL/SSLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,33 @@ public function setUp() : void

public static function setUpBeforeClass() : void
{
$silence = '>/dev/null 2>&1 & echo $!';
$testDir = dirname(__FILE__);

$commands = [
sprintf("php -S %s", PHP_SERVER),
sprintf("stunnel3 -d %s -r %s -p %s -P '' -f", GOOD_STUNNEL_SERVER, PHP_SERVER, dirname(__FILE__) . "/" . "good.pem"),
sprintf("stunnel3 -d %s -r %s -p %s -P '' -f", SELF_SIGNED_STUNNEL_SERVER, PHP_SERVER, dirname(__FILE__) . "/" . "self.pem"),
sprintf("stunnel3 -d %s -r %s -p %s -P '' -f", BAD_HOSTNAME_STUNNEL_SERVER, PHP_SERVER, dirname(__FILE__) . "/" . "badhost.pem"),
];
// Use stunnel4 (or stunnel) with config files
$stunnelCmd = 'stunnel4';
exec('which stunnel4 2>/dev/null', $output, $returnCode);
if ($returnCode !== 0) {
$stunnelCmd = 'stunnel';
}

$pids = [];
// Start PHP server in background
$phpServerPid = trim(shell_exec(sprintf("php -S %s >/dev/null 2>&1 & echo \\$!", PHP_SERVER)));

foreach ($commands as $command) {
$output = [];
exec($command . $silence, $output);
$pid = (int) $output[0];
array_push($pids, $pid);
// Start stunnel servers using config files (must run from test directory for relative cert paths)
$stunnelPids = [];
$configs = ['good', 'self', 'badhost'];
foreach ($configs as $name) {
$pid = trim(shell_exec(sprintf("cd %s && %s stunnel-%s.conf >/dev/null 2>&1 & echo \\$!",
$testDir, $stunnelCmd, $name)));
$stunnelPids[] = $pid;
}

// Allow processes to start
sleep(1);

register_shutdown_function(function () use ($pids) {
foreach ($pids as $pid) {
register_shutdown_function(function () use ($phpServerPid, $stunnelPids) {
exec('kill ' . $phpServerPid);
foreach ($stunnelPids as $pid) {
exec('kill ' . $pid);
}
});
Expand Down
4 changes: 4 additions & 0 deletions tests/SSL/stunnel-badhost.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[badhost]
accept = 4445
connect = localhost:4000
cert = badhost.pem
4 changes: 4 additions & 0 deletions tests/SSL/stunnel-good.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[good]
accept = 4443
connect = localhost:4000
cert = good.pem
4 changes: 4 additions & 0 deletions tests/SSL/stunnel-self.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[self]
accept = 4444
connect = localhost:4000
cert = self.pem
Loading