From c814b34b1dc43af47280910d2ebc44f6adc26589 Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Sun, 24 Feb 2019 13:05:43 +0000 Subject: [PATCH 1/2] Use spaces instead of tabs in bug 77390 test --- ext/openssl/tests/bug77390.phpt | 160 ++++++++++++++++---------------- 1 file changed, 80 insertions(+), 80 deletions(-) diff --git a/ext/openssl/tests/bug77390.phpt b/ext/openssl/tests/bug77390.phpt index a71275ef6f3..2aa2b15b41b 100644 --- a/ext/openssl/tests/bug77390.phpt +++ b/ext/openssl/tests/bug77390.phpt @@ -12,97 +12,97 @@ $cacertFile = __DIR__ . DIRECTORY_SEPARATOR . 'bug77390-ca.pem.tmp'; $peerName = 'bug77390'; $clientCode = <<<'CODE' - $context = stream_context_create(['ssl' => ['verify_peer' => false, 'peer_name' => '%s']]); + $context = stream_context_create(['ssl' => ['verify_peer' => false, 'peer_name' => '%s']]); - phpt_wait('server'); - phpt_notify('proxy'); - - phpt_wait('proxy'); - $fp = stream_socket_client("ssl://127.0.0.1:10012", $errornum, $errorstr, 3000, STREAM_CLIENT_CONNECT, $context); - stream_set_blocking($fp, false); + phpt_wait('server'); + phpt_notify('proxy'); - $read = [$fp]; - $buf = ''; - $warmedUp = false; - while (stream_select($read, $write, $except, 1000)) { - $chunk = stream_get_contents($fp, 4096); - $buf .= $chunk; - phpt_notify('proxy'); - if (!$warmedUp) { - if ($buf !== 'warmup') { - continue; - } - $warmedUp = true; - $buf = ''; - phpt_notify('server'); - continue; - } - var_dump($chunk); - if ($buf === 'hello, world') { - break; - } - } - - phpt_notify('server'); - phpt_notify('proxy'); + phpt_wait('proxy'); + $fp = stream_socket_client("ssl://127.0.0.1:10012", $errornum, $errorstr, 3000, STREAM_CLIENT_CONNECT, $context); + stream_set_blocking($fp, false); + + $read = [$fp]; + $buf = ''; + $warmedUp = false; + while (stream_select($read, $write, $except, 1000)) { + $chunk = stream_get_contents($fp, 4096); + $buf .= $chunk; + phpt_notify('proxy'); + if (!$warmedUp) { + if ($buf !== 'warmup') { + continue; + } + $warmedUp = true; + $buf = ''; + phpt_notify('server'); + continue; + } + var_dump($chunk); + if ($buf === 'hello, world') { + break; + } + } + + phpt_notify('server'); + phpt_notify('proxy'); CODE; $clientCode = sprintf($clientCode, $peerName); $serverCode = <<<'CODE' - $context = stream_context_create(['ssl' => ['local_cert' => '%s']]); + $context = stream_context_create(['ssl' => ['local_cert' => '%s']]); - $flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN; - $fp = stream_socket_server("ssl://127.0.0.1:10011", $errornum, $errorstr, $flags, $context); - phpt_notify(); - - $conn = stream_socket_accept($fp); - fwrite($conn, 'warmup'); - phpt_wait(); - fwrite($conn, 'hello, world'); - - phpt_wait(); - fclose($conn); + $flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN; + $fp = stream_socket_server("ssl://127.0.0.1:10011", $errornum, $errorstr, $flags, $context); + phpt_notify(); + + $conn = stream_socket_accept($fp); + fwrite($conn, 'warmup'); + phpt_wait(); + fwrite($conn, 'hello, world'); + + phpt_wait(); + fclose($conn); CODE; $serverCode = sprintf($serverCode, $certFile); $proxyCode = <<<'CODE' - phpt_wait(); + phpt_wait(); - $upstream = stream_socket_client("tcp://127.0.0.1:10011", $errornum, $errorstr, 3000, STREAM_CLIENT_CONNECT); - stream_set_blocking($upstream, false); + $upstream = stream_socket_client("tcp://127.0.0.1:10011", $errornum, $errorstr, 3000, STREAM_CLIENT_CONNECT); + stream_set_blocking($upstream, false); - $flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN; - $server = stream_socket_server("tcp://127.0.0.1:10012", $errornum, $errorstr, $flags); - phpt_notify(); - - $conn = stream_socket_accept($server); - stream_set_blocking($conn, false); - - $read = [$upstream, $conn]; - while (stream_select($read, $write, $except, 1)) { - foreach ($read as $fp) { - $data = stream_get_contents($fp); - if ($fp === $conn) { - fwrite($upstream, $data); - } else { - if ($data !== '' && $data[0] === chr(23)) { - $parts = str_split($data, (int) ceil(strlen($data) / 3)); - foreach ($parts as $part) { - fwrite($conn, $part); - phpt_wait(null, 1); - } - } else { - fwrite($conn, $data); - } - } - } - if (feof($upstream)) { - break; - } - $read = [$upstream, $conn]; - } - - phpt_wait(); + $flags = STREAM_SERVER_BIND|STREAM_SERVER_LISTEN; + $server = stream_socket_server("tcp://127.0.0.1:10012", $errornum, $errorstr, $flags); + phpt_notify(); + + $conn = stream_socket_accept($server); + stream_set_blocking($conn, false); + + $read = [$upstream, $conn]; + while (stream_select($read, $write, $except, 1)) { + foreach ($read as $fp) { + $data = stream_get_contents($fp); + if ($fp === $conn) { + fwrite($upstream, $data); + } else { + if ($data !== '' && $data[0] === chr(23)) { + $parts = str_split($data, (int) ceil(strlen($data) / 3)); + foreach ($parts as $part) { + fwrite($conn, $part); + phpt_wait(null, 1); + } + } else { + fwrite($conn, $data); + } + } + } + if (feof($upstream)) { + break; + } + $read = [$upstream, $conn]; + } + + phpt_wait(); CODE; include 'CertificateGenerator.inc'; @@ -112,8 +112,8 @@ $certificateGenerator->saveNewCertAsFileWithKey($peerName, $certFile); include 'ServerClientTestCase.inc'; ServerClientTestCase::getInstance()->run($clientCode, [ - 'server' => $serverCode, - 'proxy' => $proxyCode, + 'server' => $serverCode, + 'proxy' => $proxyCode, ]); ?> --CLEAN-- From 01c00953ff07b3b9414c446c6872b047b23afe24 Mon Sep 17 00:00:00 2001 From: Jakub Zelenka Date: Sun, 24 Feb 2019 13:11:27 +0000 Subject: [PATCH 2/2] Print empty string in test for but 77390 just once --- ext/openssl/tests/bug77390.phpt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ext/openssl/tests/bug77390.phpt b/ext/openssl/tests/bug77390.phpt index 2aa2b15b41b..99ba43e50b6 100644 --- a/ext/openssl/tests/bug77390.phpt +++ b/ext/openssl/tests/bug77390.phpt @@ -23,6 +23,7 @@ $clientCode = <<<'CODE' $read = [$fp]; $buf = ''; + $emptyChunkPrinted = false; $warmedUp = false; while (stream_select($read, $write, $except, 1000)) { $chunk = stream_get_contents($fp, 4096); @@ -37,7 +38,10 @@ $clientCode = <<<'CODE' phpt_notify('server'); continue; } - var_dump($chunk); + if ($chunk !== '' || !$emptyChunkPrinted) { + $emptyChunkPrinted = true; + var_dump($chunk); + } if ($buf === 'hello, world') { break; } @@ -123,5 +127,4 @@ ServerClientTestCase::getInstance()->run($clientCode, [ ?> --EXPECT-- string(0) "" -string(0) "" string(12) "hello, world"