Skip to content

Commit 9574106

Browse files
authored
Merge pull request #229 from clue-labs/tls-tests
Skip legacy TLS 1.0 / TLS 1.1 tests if disabled by system
2 parents 97522e2 + dfc4559 commit 9574106

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/FunctionalSecureServerTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,44 @@ public function testClientUsesTls12WhenCryptoMethodIsExplicitlyConfiguredByServe
148148
$this->assertEquals('TLSv1.2', $meta['crypto']['protocol']);
149149
}
150150

151+
public function testClientUsesTls10WhenCryptoMethodIsExplicitlyConfiguredByClient()
152+
{
153+
if (PHP_VERSION_ID < 70000) {
154+
$this->markTestSkipped('Test requires PHP 7+ for crypto meta data');
155+
}
156+
157+
$loop = Factory::create();
158+
159+
$server = new TcpServer(0, $loop);
160+
$server = new SecureServer($server, $loop, array(
161+
'local_cert' => __DIR__ . '/../examples/localhost.pem'
162+
));
163+
164+
$connector = new SecureConnector(new TcpConnector($loop), $loop, array(
165+
'verify_peer' => false,
166+
'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT
167+
));
168+
$promise = $connector->connect($server->getAddress());
169+
170+
/* @var ConnectionInterface $client */
171+
try {
172+
$client = Block\await($promise, $loop, self::TIMEOUT);
173+
} catch (\RuntimeException $e) {
174+
if (strpos($e->getMessage(), 'no protocols available') !== false) {
175+
$this->markTestSkipped('TLS v1.0 not available on this system');
176+
}
177+
178+
throw $e;
179+
}
180+
181+
$this->assertInstanceOf('React\Socket\Connection', $client);
182+
$this->assertTrue(isset($client->stream));
183+
184+
$meta = stream_get_meta_data($client->stream);
185+
$this->assertTrue(isset($meta['crypto']['protocol']));
186+
$this->assertEquals('TLSv1', $meta['crypto']['protocol']);
187+
}
188+
151189
public function testServerEmitsConnectionForClientConnection()
152190
{
153191
$loop = Factory::create();
@@ -393,6 +431,7 @@ public function testPipesDataBackInMultipleChunksFromConnection()
393431

394432
/**
395433
* @requires PHP 5.6
434+
* @depends testClientUsesTls10WhenCryptoMethodIsExplicitlyConfiguredByClient
396435
*/
397436
public function testEmitsConnectionForNewTlsv11Connection()
398437
{
@@ -416,6 +455,7 @@ public function testEmitsConnectionForNewTlsv11Connection()
416455

417456
/**
418457
* @requires PHP 5.6
458+
* @depends testClientUsesTls10WhenCryptoMethodIsExplicitlyConfiguredByClient
419459
*/
420460
public function testEmitsErrorForClientWithTlsVersionMismatch()
421461
{

0 commit comments

Comments
 (0)