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; + } }