From eaad7f2784a38b68ba9d6977c8957d161247d43e Mon Sep 17 00:00:00 2001 From: Jeffrey Parker Date: Tue, 20 Jan 2026 13:31:16 -0500 Subject: [PATCH 1/2] Fix tests using deprecated/missing stunnel3 dependency --- tests/SSL/SSLTest.php | 14 +++++++++++--- tests/SSL/stunnel-badhost.conf | 5 +++++ tests/SSL/stunnel-good.conf | 5 +++++ tests/SSL/stunnel-self.conf | 5 +++++ 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 tests/SSL/stunnel-badhost.conf create mode 100644 tests/SSL/stunnel-good.conf create mode 100644 tests/SSL/stunnel-self.conf diff --git a/tests/SSL/SSLTest.php b/tests/SSL/SSLTest.php index 727e6f9..dc5ef53 100644 --- a/tests/SSL/SSLTest.php +++ b/tests/SSL/SSLTest.php @@ -24,12 +24,20 @@ public function setUp() : void public static function setUpBeforeClass() : void { $silence = '>/dev/null 2>&1 & echo $!'; + $testDir = dirname(__FILE__); + + // Use stunnel4 (or stunnel) with config files + $stunnelCmd = 'stunnel4'; + exec('which stunnel4 2>/dev/null', $output, $returnCode); + if ($returnCode !== 0) { + $stunnelCmd = 'stunnel'; + } $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"), + sprintf("cd %s && %s stunnel-good.conf", $testDir, $stunnelCmd), + sprintf("cd %s && %s stunnel-self.conf", $testDir, $stunnelCmd), + sprintf("cd %s && %s stunnel-badhost.conf", $testDir, $stunnelCmd), ]; $pids = []; diff --git a/tests/SSL/stunnel-badhost.conf b/tests/SSL/stunnel-badhost.conf new file mode 100644 index 0000000..49d7011 --- /dev/null +++ b/tests/SSL/stunnel-badhost.conf @@ -0,0 +1,5 @@ +[badhost] +accept = 4445 +connect = 4000 +cert = badhost.pem +foreground = yes diff --git a/tests/SSL/stunnel-good.conf b/tests/SSL/stunnel-good.conf new file mode 100644 index 0000000..71377d1 --- /dev/null +++ b/tests/SSL/stunnel-good.conf @@ -0,0 +1,5 @@ +[good] +accept = 4443 +connect = 4000 +cert = good.pem +foreground = yes diff --git a/tests/SSL/stunnel-self.conf b/tests/SSL/stunnel-self.conf new file mode 100644 index 0000000..82a941e --- /dev/null +++ b/tests/SSL/stunnel-self.conf @@ -0,0 +1,5 @@ +[self] +accept = 4444 +connect = 4000 +cert = self.pem +foreground = yes From 8b315642611a8731fcd345e688fd50d019b9a079 Mon Sep 17 00:00:00 2001 From: Jeffrey Parker Date: Tue, 20 Jan 2026 13:41:48 -0500 Subject: [PATCH 2/2] Fix tests using deprecated/missing stunnel3 dependency --- tests/SSL/SSLTest.php | 28 ++++++++++++---------------- tests/SSL/stunnel-badhost.conf | 3 +-- tests/SSL/stunnel-good.conf | 3 +-- tests/SSL/stunnel-self.conf | 3 +-- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/tests/SSL/SSLTest.php b/tests/SSL/SSLTest.php index dc5ef53..efad60f 100644 --- a/tests/SSL/SSLTest.php +++ b/tests/SSL/SSLTest.php @@ -23,7 +23,6 @@ public function setUp() : void public static function setUpBeforeClass() : void { - $silence = '>/dev/null 2>&1 & echo $!'; $testDir = dirname(__FILE__); // Use stunnel4 (or stunnel) with config files @@ -33,27 +32,24 @@ public static function setUpBeforeClass() : void $stunnelCmd = 'stunnel'; } - $commands = [ - sprintf("php -S %s", PHP_SERVER), - sprintf("cd %s && %s stunnel-good.conf", $testDir, $stunnelCmd), - sprintf("cd %s && %s stunnel-self.conf", $testDir, $stunnelCmd), - sprintf("cd %s && %s stunnel-badhost.conf", $testDir, $stunnelCmd), - ]; + // Start PHP server in background + $phpServerPid = trim(shell_exec(sprintf("php -S %s >/dev/null 2>&1 & echo \\$!", PHP_SERVER))); - $pids = []; - - 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); } }); diff --git a/tests/SSL/stunnel-badhost.conf b/tests/SSL/stunnel-badhost.conf index 49d7011..4d8d5d6 100644 --- a/tests/SSL/stunnel-badhost.conf +++ b/tests/SSL/stunnel-badhost.conf @@ -1,5 +1,4 @@ [badhost] accept = 4445 -connect = 4000 +connect = localhost:4000 cert = badhost.pem -foreground = yes diff --git a/tests/SSL/stunnel-good.conf b/tests/SSL/stunnel-good.conf index 71377d1..0ebdb29 100644 --- a/tests/SSL/stunnel-good.conf +++ b/tests/SSL/stunnel-good.conf @@ -1,5 +1,4 @@ [good] accept = 4443 -connect = 4000 +connect = localhost:4000 cert = good.pem -foreground = yes diff --git a/tests/SSL/stunnel-self.conf b/tests/SSL/stunnel-self.conf index 82a941e..f4a5ff9 100644 --- a/tests/SSL/stunnel-self.conf +++ b/tests/SSL/stunnel-self.conf @@ -1,5 +1,4 @@ [self] accept = 4444 -connect = 4000 +connect = localhost:4000 cert = self.pem -foreground = yes