Skip to content

Commit d9b2902

Browse files
committed
Update and integrate openssl client proxy test
1 parent 0c84c2e commit d9b2902

File tree

3 files changed

+72
-150
lines changed

3 files changed

+72
-150
lines changed

ext/openssl/tests/ServerClientProxyTestCase.inc

Lines changed: 0 additions & 117 deletions
This file was deleted.

ext/openssl/tests/ServerClientTestCase.inc

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
const WORKER_ARGV_VALUE = 'RUN_WORKER';
44

5-
function phpt_notify()
5+
const WORKER_DEFAULT_NAME = 'server';
6+
7+
function phpt_notify($worker = WORKER_DEFAULT_NAME)
68
{
7-
ServerClientTestCase::getInstance()->notify();
9+
ServerClientTestCase::getInstance()->notify($worker);
810
}
911

10-
function phpt_wait()
12+
function phpt_wait($worker = WORKER_DEFAULT_NAME)
1113
{
12-
ServerClientTestCase::getInstance()->wait();
14+
ServerClientTestCase::getInstance()->wait($worker);
1315
}
1416

1517
/**
@@ -20,11 +22,11 @@ class ServerClientTestCase
2022
{
2123
private $isWorker = false;
2224

23-
private $workerHandle;
25+
private $workerHandle = [];
2426

25-
private $workerStdIn;
27+
private $workerStdIn = [];
2628

27-
private $workerStdOut;
29+
private $workerStdOut = [];
2830

2931
private static $instance;
3032

@@ -46,26 +48,41 @@ class ServerClientTestCase
4648
$this->isWorker = $isWorker;
4749
}
4850

49-
private function spawnWorkerProcess($code)
51+
private function spawnWorkerProcess($worker, $code)
5052
{
5153
if (defined("PHP_WINDOWS_VERSION_MAJOR")) {
52-
$ini = php_ini_loaded_file();
53-
$cmd = sprintf('%s %s "%s" %s', PHP_BINARY, $ini ? "-n -c $ini" : "", __FILE__, WORKER_ARGV_VALUE);
54+
$ini = php_ini_loaded_file();
55+
$cmd = sprintf(
56+
'%s %s "%s" %s',
57+
PHP_BINARY, $ini ? "-n -c $ini" : "",
58+
__FILE__,
59+
WORKER_ARGV_VALUE
60+
);
5461
} else {
55-
$cmd = sprintf('%s "%s" %s', PHP_BINARY, __FILE__, WORKER_ARGV_VALUE);
62+
$cmd = sprintf(
63+
'%s "%s" %s %s',
64+
PHP_BINARY,
65+
__FILE__,
66+
WORKER_ARGV_VALUE,
67+
$worker
68+
);
5669
}
57-
$this->workerHandle = proc_open($cmd, [['pipe', 'r'], ['pipe', 'w'], STDERR], $pipes);
58-
$this->workerStdIn = $pipes[0];
59-
$this->workerStdOut = $pipes[1];
60-
61-
fwrite($this->workerStdIn, $code . "\n---\n");
70+
$this->workerHandle[$worker] = proc_open(
71+
$cmd,
72+
[['pipe', 'r'], ['pipe', 'w'], STDERR],
73+
$pipes
74+
);
75+
$this->workerStdIn[$worker] = $pipes[0];
76+
$this->workerStdOut[$worker] = $pipes[1];
77+
78+
fwrite($this->workerStdIn[$worker], $code . "\n---\n");
6279
}
6380

64-
private function cleanupWorkerProcess()
81+
private function cleanupWorkerProcess($worker)
6582
{
66-
fclose($this->workerStdIn);
67-
fclose($this->workerStdOut);
68-
proc_close($this->workerHandle);
83+
fclose($this->workerStdIn[$worker]);
84+
fclose($this->workerStdOut[$worker]);
85+
proc_close($this->workerHandle[$worker]);
6986
}
7087

7188
private function stripPhpTagsFromCode($code)
@@ -90,21 +107,28 @@ class ServerClientTestCase
90107
eval($code);
91108
}
92109

93-
public function run($proc1Code, $proc2Code)
110+
public function run($masterCode, $workerCode)
94111
{
95-
$this->spawnWorkerProcess($this->stripPhpTagsFromCode($proc2Code));
96-
eval($this->stripPhpTagsFromCode($proc1Code));
97-
$this->cleanupWorkerProcess();
112+
if (!is_array($workerCode)) {
113+
$workerCode = [WORKER_DEFAULT_NAME => $workerCode];
114+
}
115+
foreach ($workerCode as $worker => $code) {
116+
$this->spawnWorkerProcess($worker, $this->stripPhpTagsFromCode($code));
117+
}
118+
eval($this->stripPhpTagsFromCode($masterCode));
119+
foreach ($workerCode as $worker => $code) {
120+
$this->cleanupWorkerProcess($worker);
121+
}
98122
}
99123

100-
public function wait()
124+
public function wait($worker)
101125
{
102-
fgets($this->isWorker ? STDIN : $this->workerStdOut);
126+
fgets($this->isWorker ? STDIN : $this->workerStdOut[$worker]);
103127
}
104128

105-
public function notify()
129+
public function notify($worker)
106130
{
107-
fwrite($this->isWorker ? STDOUT : $this->workerStdIn, "\n");
131+
fwrite($this->isWorker ? STDOUT : $this->workerStdIn[$worker], "\n");
108132
}
109133
}
110134

ext/openssl/tests/non_blocking_eof.phpt renamed to ext/openssl/tests/bug77390.phpt

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
--TEST--
2-
php_stream_eof() should not block on SSL non-blocking streams when packets are fragmented
2+
Bug #76705: feof might hang on TLS streams in case of fragmented TLS records
33
--SKIPIF--
44
<?php
55
if (!extension_loaded("openssl")) die("skip openssl not loaded");
66
if (!function_exists("proc_open")) die("skip no proc_open");
77
?>
88
--FILE--
99
<?php
10+
$certFile = __DIR__ . DIRECTORY_SEPARATOR . 'bug77390.pem.tmp';
11+
$cacertFile = __DIR__ . DIRECTORY_SEPARATOR . 'bug77390-ca.pem.tmp';
1012

13+
$peerName = 'bug77390';
1114
$clientCode = <<<'CODE'
12-
$context = stream_context_create(['ssl' => ['verify_peer' => false, 'peer_name' => 'bug54992.local']]);
15+
$context = stream_context_create(['ssl' => ['verify_peer' => false, 'peer_name' => '%s']]);
1316
1417
phpt_wait('server');
1518
phpt_notify('proxy');
@@ -32,9 +35,10 @@ $clientCode = <<<'CODE'
3235
phpt_notify('server');
3336
phpt_notify('proxy');
3437
CODE;
38+
$clientCode = sprintf($clientCode, $peerName);
3539

3640
$serverCode = <<<'CODE'
37-
$context = stream_context_create(['ssl' => ['local_cert' => __DIR__ . '/bug54992.pem']]);
41+
$context = stream_context_create(['ssl' => ['local_cert' => '%s']]);
3842
3943
$flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN;
4044
$fp = stream_socket_server("ssl://127.0.0.1:10011", $errornum, $errorstr, $flags, $context);
@@ -46,6 +50,7 @@ $serverCode = <<<'CODE'
4650
phpt_wait();
4751
fclose($conn);
4852
CODE;
53+
$serverCode = sprintf($serverCode, $certFile);
4954

5055
$proxyCode = <<<'CODE'
5156
phpt_wait();
@@ -87,12 +92,22 @@ $proxyCode = <<<'CODE'
8792
phpt_wait();
8893
CODE;
8994

90-
include 'ServerClientProxyTestCase.inc';
91-
ServerClientProxyTestCase::getInstance()->run($clientCode, [
95+
include 'CertificateGenerator.inc';
96+
$certificateGenerator = new CertificateGenerator();
97+
$certificateGenerator->saveCaCert($cacertFile);
98+
$certificateGenerator->saveNewCertAsFileWithKey($peerName, $certFile);
99+
100+
include 'ServerClientTestCase.inc';
101+
ServerClientTestCase::getInstance()->run($clientCode, [
92102
'server' => $serverCode,
93103
'proxy' => $proxyCode,
94104
]);
95105
?>
106+
--CLEAN--
107+
<?php
108+
@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'bug77390.pem.tmp');
109+
@unlink(__DIR__ . DIRECTORY_SEPARATOR . 'bug77390-ca.pem.tmp');
110+
?>
96111
--EXPECT--
97112
string(0) ""
98113
string(0) ""

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy