From 1f92698b786c088ca92ae8b0752f456eeebe841d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sat, 25 May 2019 12:29:04 +0200 Subject: [PATCH] Work around failing test case detecting EOF on TLS 1.3 socket streams This PR improves the test suite to avoid a possible race condition for our TLS tests. It does not change anything about the actual behavior or the expected output, but it helps making the expected output more explicit and no longer subject to a possible race condition. This helps avoiding possible false negatives if TLS 1.3 is supported and PHP reports the EOF indicator before consuming all application data. This builds on top of https://github.com/reactphp/socket/pull/185 and https://github.com/reactphp/socket/pull/186 --- tests/FunctionalSecureServerTest.php | 17 ----------------- tests/SecureIntegrationTest.php | 17 +++++++++++++++++ tests/TestCase.php | 17 +++++++++++++++++ 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/tests/FunctionalSecureServerTest.php b/tests/FunctionalSecureServerTest.php index 4caee701..c4963c67 100644 --- a/tests/FunctionalSecureServerTest.php +++ b/tests/FunctionalSecureServerTest.php @@ -718,21 +718,4 @@ private function createPromiseForEvent(EventEmitterInterface $emitter, $event, $ }); }); } - - private function supportsTls13() - { - // TLS 1.3 is supported as of OpenSSL 1.1.1 (https://www.openssl.org/blog/blog/2018/09/11/release111/) - // The OpenSSL library version can only be obtained by parsing output from phpinfo(). - // OPENSSL_VERSION_TEXT refers to header version which does not necessarily match actual library version - // see php -i | grep OpenSSL - // OpenSSL Library Version => OpenSSL 1.1.1 11 Sep 2018 - ob_start(); - phpinfo(INFO_MODULES); - $info = ob_get_clean(); - - if (preg_match('/OpenSSL Library Version => OpenSSL (\S+)/', $info, $match)) { - return version_compare($match[1], '1.1.1', '>='); - } - return false; - } } diff --git a/tests/SecureIntegrationTest.php b/tests/SecureIntegrationTest.php index 8c9ba14d..371bca72 100644 --- a/tests/SecureIntegrationTest.php +++ b/tests/SecureIntegrationTest.php @@ -93,6 +93,21 @@ public function testSendSmallDataToServerReceivesOneChunk() public function testSendDataWithEndToServerReceivesAllData() { + // PHP can report EOF on TLS 1.3 stream before consuming all data, so + // we explicitly use older TLS version instead. Selecting TLS version + // requires PHP 5.6+, so skip legacy versions if TLS 1.3 is supported. + // Continue if TLS 1.3 is not supported anyway. + if ($this->supportsTls13()) { + if (!defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) { + $this->markTestSkipped('TLS 1.3 supported, but this legacy PHP version does not support explicit choice'); + } + + $this->connector = new SecureConnector(new TcpConnector($this->loop), $this->loop, array( + 'verify_peer' => false, + 'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT + )); + } + $disconnected = new Deferred(); $this->server->on('connection', function (ConnectionInterface $peer) use ($disconnected) { $received = ''; @@ -113,6 +128,7 @@ public function testSendDataWithEndToServerReceivesAllData() // await server to report connection "close" event $received = Block\await($disconnected->promise(), $this->loop, self::TIMEOUT); + $this->assertEquals(strlen($data), strlen($received)); $this->assertEquals($data, $received); } @@ -136,6 +152,7 @@ public function testSendDataWithoutEndingToServerReceivesAllData() $client->close(); + $this->assertEquals(strlen($data), strlen($received)); $this->assertEquals($data, $received); } diff --git a/tests/TestCase.php b/tests/TestCase.php index e87fc2f1..b9b383af 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -98,4 +98,21 @@ public function setExpectedException($exception, $exceptionMessage = '', $except parent::setExpectedException($exception, $exceptionMessage, $exceptionCode); } } + + protected function supportsTls13() + { + // TLS 1.3 is supported as of OpenSSL 1.1.1 (https://www.openssl.org/blog/blog/2018/09/11/release111/) + // The OpenSSL library version can only be obtained by parsing output from phpinfo(). + // OPENSSL_VERSION_TEXT refers to header version which does not necessarily match actual library version + // see php -i | grep OpenSSL + // OpenSSL Library Version => OpenSSL 1.1.1 11 Sep 2018 + ob_start(); + phpinfo(INFO_MODULES); + $info = ob_get_clean(); + + if (preg_match('/OpenSSL Library Version => OpenSSL ([\d\.]+)/', $info, $match)) { + return version_compare($match[1], '1.1.1', '>='); + } + return false; + } } 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