Skip to content

Commit 032db4d

Browse files
authored
Work around failing test case detecting EOF on TLS 1.3 socket streams (#201)
Work around failing test case detecting EOF on TLS 1.3 socket streams
2 parents 2cf8dfa + 1f92698 commit 032db4d

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

tests/FunctionalSecureServerTest.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -718,21 +718,4 @@ private function createPromiseForEvent(EventEmitterInterface $emitter, $event, $
718718
});
719719
});
720720
}
721-
722-
private function supportsTls13()
723-
{
724-
// TLS 1.3 is supported as of OpenSSL 1.1.1 (https://www.openssl.org/blog/blog/2018/09/11/release111/)
725-
// The OpenSSL library version can only be obtained by parsing output from phpinfo().
726-
// OPENSSL_VERSION_TEXT refers to header version which does not necessarily match actual library version
727-
// see php -i | grep OpenSSL
728-
// OpenSSL Library Version => OpenSSL 1.1.1 11 Sep 2018
729-
ob_start();
730-
phpinfo(INFO_MODULES);
731-
$info = ob_get_clean();
732-
733-
if (preg_match('/OpenSSL Library Version => OpenSSL (\S+)/', $info, $match)) {
734-
return version_compare($match[1], '1.1.1', '>=');
735-
}
736-
return false;
737-
}
738721
}

tests/SecureIntegrationTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,21 @@ public function testSendSmallDataToServerReceivesOneChunk()
9393

9494
public function testSendDataWithEndToServerReceivesAllData()
9595
{
96+
// PHP can report EOF on TLS 1.3 stream before consuming all data, so
97+
// we explicitly use older TLS version instead. Selecting TLS version
98+
// requires PHP 5.6+, so skip legacy versions if TLS 1.3 is supported.
99+
// Continue if TLS 1.3 is not supported anyway.
100+
if ($this->supportsTls13()) {
101+
if (!defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
102+
$this->markTestSkipped('TLS 1.3 supported, but this legacy PHP version does not support explicit choice');
103+
}
104+
105+
$this->connector = new SecureConnector(new TcpConnector($this->loop), $this->loop, array(
106+
'verify_peer' => false,
107+
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
108+
));
109+
}
110+
96111
$disconnected = new Deferred();
97112
$this->server->on('connection', function (ConnectionInterface $peer) use ($disconnected) {
98113
$received = '';
@@ -113,6 +128,7 @@ public function testSendDataWithEndToServerReceivesAllData()
113128
// await server to report connection "close" event
114129
$received = Block\await($disconnected->promise(), $this->loop, self::TIMEOUT);
115130

131+
$this->assertEquals(strlen($data), strlen($received));
116132
$this->assertEquals($data, $received);
117133
}
118134

@@ -136,6 +152,7 @@ public function testSendDataWithoutEndingToServerReceivesAllData()
136152

137153
$client->close();
138154

155+
$this->assertEquals(strlen($data), strlen($received));
139156
$this->assertEquals($data, $received);
140157
}
141158

tests/TestCase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,21 @@ public function setExpectedException($exception, $exceptionMessage = '', $except
9898
parent::setExpectedException($exception, $exceptionMessage, $exceptionCode);
9999
}
100100
}
101+
102+
protected function supportsTls13()
103+
{
104+
// TLS 1.3 is supported as of OpenSSL 1.1.1 (https://www.openssl.org/blog/blog/2018/09/11/release111/)
105+
// The OpenSSL library version can only be obtained by parsing output from phpinfo().
106+
// OPENSSL_VERSION_TEXT refers to header version which does not necessarily match actual library version
107+
// see php -i | grep OpenSSL
108+
// OpenSSL Library Version => OpenSSL 1.1.1 11 Sep 2018
109+
ob_start();
110+
phpinfo(INFO_MODULES);
111+
$info = ob_get_clean();
112+
113+
if (preg_match('/OpenSSL Library Version => OpenSSL ([\d\.]+)/', $info, $match)) {
114+
return version_compare($match[1], '1.1.1', '>=');
115+
}
116+
return false;
117+
}
101118
}

0 commit comments

Comments
 (0)